@emulsify/cli 2.4.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -16,15 +16,10 @@ function validateComponentName(name) {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
export default async function componentCreate(name, options = {}) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
message: 'Component name:',
|
|
24
|
-
validate: validateComponentName,
|
|
25
|
-
}),
|
|
26
|
-
nonInteractive: { error: MISSING_COMPONENT_NAME_ERROR },
|
|
27
|
-
});
|
|
19
|
+
const providedComponentName = name?.trim() ? name : undefined;
|
|
20
|
+
if (!providedComponentName) {
|
|
21
|
+
requireInteractiveTerminal(MISSING_COMPONENT_NAME_ERROR);
|
|
22
|
+
}
|
|
28
23
|
if (!options.type && !options.format) {
|
|
29
24
|
requireInteractiveTerminal(MISSING_COMPONENT_TYPE_ERROR);
|
|
30
25
|
}
|
|
@@ -34,6 +29,14 @@ export default async function componentCreate(name, options = {}) {
|
|
|
34
29
|
const { emulsifyConfig, variantConf } = await withEmulsifySystem('create components', {
|
|
35
30
|
refresh: options.refresh,
|
|
36
31
|
});
|
|
32
|
+
const componentName = providedComponentName ??
|
|
33
|
+
(await runPrompt({
|
|
34
|
+
prompt: () => input({
|
|
35
|
+
message: 'Component name:',
|
|
36
|
+
validate: validateComponentName,
|
|
37
|
+
}),
|
|
38
|
+
nonInteractive: { error: MISSING_COMPONENT_NAME_ERROR },
|
|
39
|
+
}));
|
|
37
40
|
try {
|
|
38
41
|
await generateComponent(variantConf, emulsifyConfig, componentName, options);
|
|
39
42
|
}
|
package/dist/handlers/init.js
CHANGED
|
@@ -5,6 +5,7 @@ import { input, select } from '@inquirer/prompts';
|
|
|
5
5
|
import { EMULSIFY_PROJECT_CONFIG_FILE, EMULSIFY_PROJECT_HOOK_INIT, EMULSIFY_PROJECT_HOOK_FOLDER, } from '../lib/constants.js';
|
|
6
6
|
import getPlatformInfo from '../util/platform/getPlatformInfo.js';
|
|
7
7
|
import getAvailableStarters from '../util/getAvailableStarters.js';
|
|
8
|
+
import loadJsonFile from '../util/fs/loadJsonFile.js';
|
|
8
9
|
import writeToJsonFile from '../util/fs/writeToJsonFile.js';
|
|
9
10
|
import strToMachineName from '../util/strToMachineName.js';
|
|
10
11
|
import installDependencies from '../util/project/installDependencies.js';
|
|
@@ -23,6 +24,22 @@ const PLATFORM_CHOICES = [
|
|
|
23
24
|
'wordpress',
|
|
24
25
|
'none',
|
|
25
26
|
];
|
|
27
|
+
function isAlreadyExistsError(error) {
|
|
28
|
+
return (error !== null &&
|
|
29
|
+
typeof error === 'object' &&
|
|
30
|
+
'code' in error &&
|
|
31
|
+
error.code === 'EEXIST');
|
|
32
|
+
}
|
|
33
|
+
async function rollbackFailedInitialization(target, phase, error) {
|
|
34
|
+
const failure = `Unable to initialize project while ${phase}: ${String(error)}`;
|
|
35
|
+
try {
|
|
36
|
+
await fs.rm(target, { recursive: true, force: true });
|
|
37
|
+
return new CliError(`${failure}. Removed the incomplete target "${target}".`);
|
|
38
|
+
}
|
|
39
|
+
catch (cleanupError) {
|
|
40
|
+
return new CliError(`${failure}. Automatic cleanup of the incomplete target "${target}" also failed: ${String(cleanupError)}. Remove it manually before retrying.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
26
43
|
export default function init(progress) {
|
|
27
44
|
return async (name, targetDirectory, options) => {
|
|
28
45
|
const { name: autoPlatformName, emulsifyParentDirectory } = (await getPlatformInfo()) || {};
|
|
@@ -99,6 +116,16 @@ export default function init(progress) {
|
|
|
99
116
|
if (existsSync(target)) {
|
|
100
117
|
throw new CliError(`The intended target is already occupied: ${target}`);
|
|
101
118
|
}
|
|
119
|
+
try {
|
|
120
|
+
await fs.mkdir(target);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (isAlreadyExistsError(error)) {
|
|
124
|
+
throw new CliError(`The intended target is already occupied: ${target}`);
|
|
125
|
+
}
|
|
126
|
+
throw new CliError(`Unable to initialize project while creating the target directory "${target}": ${String(error)}`);
|
|
127
|
+
}
|
|
128
|
+
let phase = 'cloning the starter';
|
|
102
129
|
try {
|
|
103
130
|
progress.tick(10, { message: 'validation complete, cloning starter' });
|
|
104
131
|
await git.clone(repository, target, checkout
|
|
@@ -106,36 +133,48 @@ export default function init(progress) {
|
|
|
106
133
|
'--branch': checkout,
|
|
107
134
|
}
|
|
108
135
|
: {});
|
|
109
|
-
|
|
136
|
+
phase = 'reading the starter project configuration';
|
|
137
|
+
const configPath = join(target, EMULSIFY_PROJECT_CONFIG_FILE);
|
|
138
|
+
const starterConfig = await loadJsonFile(configPath);
|
|
139
|
+
phase = 'writing the project configuration';
|
|
140
|
+
await writeToJsonFile(configPath, {
|
|
141
|
+
...starterConfig,
|
|
110
142
|
project: {
|
|
143
|
+
...starterConfig?.project,
|
|
111
144
|
platform: platformName,
|
|
112
145
|
name: projectName,
|
|
113
146
|
machineName,
|
|
114
147
|
},
|
|
115
|
-
starter: {
|
|
148
|
+
starter: {
|
|
149
|
+
...starterConfig?.starter,
|
|
150
|
+
repository,
|
|
151
|
+
},
|
|
116
152
|
});
|
|
117
153
|
progress.tick(30, {
|
|
118
154
|
message: 'starter cloned, installing dependencies (this will take a moment)',
|
|
119
155
|
});
|
|
156
|
+
phase = 'installing dependencies';
|
|
120
157
|
await installDependencies(target);
|
|
121
158
|
progress.tick(40, {
|
|
122
159
|
message: 'dependencies installed, executing init script',
|
|
123
160
|
});
|
|
124
161
|
const initPath = join(target, EMULSIFY_PROJECT_HOOK_FOLDER, EMULSIFY_PROJECT_HOOK_INIT);
|
|
125
162
|
if (existsSync(initPath)) {
|
|
163
|
+
phase = 'executing the starter init hook';
|
|
126
164
|
await executeScript(initPath);
|
|
127
165
|
}
|
|
166
|
+
phase = 'removing the starter Git metadata';
|
|
128
167
|
await fs.rm(join(target, '.git'), { recursive: true });
|
|
129
|
-
progress.tick(10, {
|
|
130
|
-
message: 'init script executed, initialization complete',
|
|
131
|
-
});
|
|
132
|
-
log('success', `Created an Emulsify project in ${target}.`);
|
|
133
|
-
getInitSuccessMessageForPlatform(platformName, target, {
|
|
134
|
-
includeDrupalInstallReminder: isDetectedDrupalProject && platformName === 'drupal',
|
|
135
|
-
}).map(({ method, message }) => log(method, message));
|
|
136
168
|
}
|
|
137
169
|
catch (e) {
|
|
138
|
-
throw
|
|
170
|
+
throw await rollbackFailedInitialization(target, phase, e);
|
|
139
171
|
}
|
|
172
|
+
progress.tick(10, {
|
|
173
|
+
message: 'init script executed, initialization complete',
|
|
174
|
+
});
|
|
175
|
+
log('success', `Created an Emulsify project in ${target}.`);
|
|
176
|
+
getInitSuccessMessageForPlatform(platformName, target, {
|
|
177
|
+
includeDrupalInstallReminder: isDetectedDrupalProject && platformName === 'drupal',
|
|
178
|
+
}).map(({ method, message }) => log(method, message));
|
|
140
179
|
};
|
|
141
180
|
}
|
|
@@ -19,7 +19,7 @@ import executeScript from '../util/fs/executeScript.js';
|
|
|
19
19
|
import validateSystemConfig from '../util/system/validateSystemConfig.js';
|
|
20
20
|
import { getVariantPlatformExpressions, isPlatform, parsePlatformExpression, rankPlatformVariants, selectCompatiblePlatformVariant, selectExactPlatformVariant, } from '../util/platform/platformCompatibility.js';
|
|
21
21
|
import { runPrompt } from '../util/prompt/index.js';
|
|
22
|
-
import buildSystemInstallPlan from '../util/system/buildSystemInstallPlan.js';
|
|
22
|
+
import buildSystemInstallPlan, { selectSystemComponents, } from '../util/system/buildSystemInstallPlan.js';
|
|
23
23
|
const MISSING_SYSTEM_SOURCE_ERROR = 'No component system source was provided. Pass a built-in system name as the positional argument, or pass both --repository <repository> and --checkout <branch, tag, or commit>.';
|
|
24
24
|
const INVALID_SYSTEM_SOURCE_ERROR = 'Unable to resolve the requested component system source. Pass a valid built-in system name as the positional argument, or pass both --repository <repository> and --checkout <branch, tag, or commit>.';
|
|
25
25
|
const WIZARD_TITLE = 'Install a component system';
|
|
@@ -448,9 +448,7 @@ export default async function systemInstall(name, options) {
|
|
|
448
448
|
const installAll = guidedInstall && !options.all
|
|
449
449
|
? await promptForInstallScope(variantConf, ++wizardStep, wizardTotalSteps)
|
|
450
450
|
: options.all === true;
|
|
451
|
-
let componentsToInstall = installAll
|
|
452
|
-
? variantConf.components
|
|
453
|
-
: variantConf.components.filter(({ required }) => required === true);
|
|
451
|
+
let componentsToInstall = selectSystemComponents(variantConf, installAll);
|
|
454
452
|
if (guidedInstall) {
|
|
455
453
|
const projectConfigPath = findFileInCurrentPath(EMULSIFY_PROJECT_CONFIG_FILE);
|
|
456
454
|
if (!projectConfigPath) {
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { dirname, relative, sep } from 'path';
|
|
2
2
|
import safeResolveWithin from '../fs/safeResolveWithin.js';
|
|
3
|
+
import buildComponentDependencyList from '../project/buildComponentDependencyList.js';
|
|
3
4
|
import { getComponentDestination } from '../project/installComponentFromCache.js';
|
|
4
5
|
function toProjectRelativeDisplayPath(projectRoot, destination) {
|
|
5
6
|
const displayPath = relative(projectRoot, destination).split(sep).join('/');
|
|
@@ -8,6 +9,14 @@ function toProjectRelativeDisplayPath(projectRoot, destination) {
|
|
|
8
9
|
function uniqueInOrder(values) {
|
|
9
10
|
return [...new Set(values)];
|
|
10
11
|
}
|
|
12
|
+
export function selectSystemComponents(variantConf, installAll) {
|
|
13
|
+
if (installAll) {
|
|
14
|
+
return [...variantConf.components];
|
|
15
|
+
}
|
|
16
|
+
const requiredComponents = variantConf.components.filter(({ required }) => required === true);
|
|
17
|
+
const selectedNames = uniqueInOrder(requiredComponents.flatMap(({ name }) => buildComponentDependencyList(variantConf.components, name)));
|
|
18
|
+
return selectedNames.map((name) => variantConf.components.find((component) => component.name === name));
|
|
19
|
+
}
|
|
11
20
|
function assertSystemStructure(systemConf, component) {
|
|
12
21
|
if (!systemConf.structure.some(({ name }) => name === component.structure)) {
|
|
13
22
|
throw new Error(`The structure (${component.structure}) specified within the component ${component.name} is invalid.`);
|
|
@@ -16,9 +25,7 @@ function assertSystemStructure(systemConf, component) {
|
|
|
16
25
|
export default function buildSystemInstallPlan(systemConf, variantConf, installAll, projectConfigPath) {
|
|
17
26
|
const projectRoot = dirname(projectConfigPath);
|
|
18
27
|
const requiredComponents = variantConf.components.filter(({ required }) => required === true);
|
|
19
|
-
const components = installAll
|
|
20
|
-
? [...variantConf.components]
|
|
21
|
-
: requiredComponents;
|
|
28
|
+
const components = selectSystemComponents(variantConf, installAll);
|
|
22
29
|
const componentParentDestinations = uniqueInOrder(components.map((component) => {
|
|
23
30
|
assertSystemStructure(systemConf, component);
|
|
24
31
|
return toProjectRelativeDisplayPath(projectRoot, dirname(getComponentDestination(variantConf, component.name, projectConfigPath)));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emulsify/cli",
|
|
3
3
|
"productName": "Emulsify CLI",
|
|
4
|
-
"version": "2.4.
|
|
4
|
+
"version": "2.4.1",
|
|
5
5
|
"description": "Build and use component systems in Drupal, WordPress, or standalone front ends.",
|
|
6
6
|
"repository": "git@github.com:emulsify-ds/emulsify-cli.git",
|
|
7
7
|
"author": "Patrick Coffey <patrickcoffey48@gmail.com>",
|