@emulsify/cli 2.3.1 → 2.4.0
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.
- package/README.md +96 -16
- package/dist/handlers/componentCreate.js +34 -5
- package/dist/handlers/componentEjectTemplates.js +317 -0
- package/dist/handlers/componentInstall.js +54 -14
- package/dist/handlers/hofs/withEmulsifySystem.js +1 -1
- package/dist/handlers/init.js +26 -22
- package/dist/handlers/systemCreate.js +222 -0
- package/dist/handlers/systemDetach.js +50 -0
- package/dist/handlers/systemInstall.js +341 -101
- package/dist/index.js +66 -110
- package/dist/lib/log.js +12 -9
- package/dist/lib/rootHelp.js +321 -0
- package/dist/lib/terminalColors.js +10 -0
- package/dist/util/cache/cloneIntoCache.js +2 -4
- package/dist/util/deriveComponentNames.js +5 -0
- package/dist/util/deriveCustomElementTagName.js +25 -0
- package/dist/util/fs/writeToJsonFile.js +21 -5
- package/dist/util/getGitRepoNameFromUrl.js +47 -3
- package/dist/util/getNonInteractiveGitEnvironment.js +7 -0
- package/dist/util/getRepositoryLatestTag.js +17 -2
- package/dist/util/platform/platformCompatibility.js +18 -7
- package/dist/util/project/componentTemplates/buildComponentArtifacts.js +121 -0
- package/dist/util/project/componentTemplates/index.js +5 -0
- package/dist/util/project/componentTemplates/react.js +20 -0
- package/dist/util/project/componentTemplates/reactStories.js +18 -0
- package/dist/util/project/componentTemplates/scss.js +2 -3
- package/dist/util/project/componentTemplates/sdcStories.js +2 -2
- package/dist/util/project/componentTemplates/stories.js +2 -2
- package/dist/util/project/componentTemplates/twig.js +2 -3
- package/dist/util/project/componentTemplates/webComponent.js +49 -0
- package/dist/util/project/componentTemplates/webComponentStories.js +19 -0
- package/dist/util/project/componentTypes.js +71 -0
- package/dist/util/project/generateComponent.js +139 -101
- package/dist/util/project/renderTemplate.js +24 -4
- package/dist/util/project/resolveComponentTemplate.js +24 -11
- package/dist/util/project/unsetEmulsifyConfig.js +16 -0
- package/dist/util/prompt/index.js +25 -0
- package/dist/util/system/buildSystemInstallPlan.js +46 -0
- package/dist/util/system/buildSystemScaffold.js +99 -0
- package/dist/util/system/getAvailableSystems.js +4 -0
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { dirname, join } from 'path';
|
|
2
2
|
import { existsSync } from 'fs';
|
|
3
|
-
import { select } from '@inquirer/prompts';
|
|
3
|
+
import { confirm, input, select, Separator } from '@inquirer/prompts';
|
|
4
4
|
import { EMULSIFY_PROJECT_CONFIG_FILE, EMULSIFY_SYSTEM_CONFIG_FILE, EMULSIFY_PROJECT_HOOK_FOLDER, EMULSIFY_PROJECT_HOOK_SYSTEM_INSTALL, } from '../lib/constants.js';
|
|
5
5
|
import log from '../lib/log.js';
|
|
6
6
|
import CliError from '../lib/CliError.js';
|
|
@@ -16,12 +16,76 @@ import setEmulsifyConfig from '../util/project/setEmulsifyConfig.js';
|
|
|
16
16
|
import getEmulsifyConfig from '../util/project/getEmulsifyConfig.js';
|
|
17
17
|
import findFileInCurrentPath from '../util/fs/findFileInCurrentPath.js';
|
|
18
18
|
import executeScript from '../util/fs/executeScript.js';
|
|
19
|
-
import writeToJsonFile from '../util/fs/writeToJsonFile.js';
|
|
20
19
|
import validateSystemConfig from '../util/system/validateSystemConfig.js';
|
|
21
|
-
import { getVariantPlatformExpressions, isPlatform, selectCompatiblePlatformVariant, selectExactPlatformVariant, } from '../util/platform/platformCompatibility.js';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
20
|
+
import { getVariantPlatformExpressions, isPlatform, parsePlatformExpression, rankPlatformVariants, selectCompatiblePlatformVariant, selectExactPlatformVariant, } from '../util/platform/platformCompatibility.js';
|
|
21
|
+
import { runPrompt } from '../util/prompt/index.js';
|
|
22
|
+
import buildSystemInstallPlan from '../util/system/buildSystemInstallPlan.js';
|
|
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
|
+
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
|
+
const WIZARD_TITLE = 'Install a component system';
|
|
26
|
+
function formatWizardHeader(step, total) {
|
|
27
|
+
const progress = total ? `Step ${step} of ${total}` : `Step ${step}`;
|
|
28
|
+
return `${WIZARD_TITLE.padEnd(60)}${progress}`;
|
|
29
|
+
}
|
|
30
|
+
function showWizardStep(step, total) {
|
|
31
|
+
log('info', formatWizardHeader(step, total));
|
|
32
|
+
}
|
|
33
|
+
function formatChoice(label, description) {
|
|
34
|
+
return `${label.padEnd(22)}${description}`;
|
|
35
|
+
}
|
|
36
|
+
function pluralize(count, singular, plural = `${singular}s`) {
|
|
37
|
+
return `${count} ${count === 1 ? singular : plural}`;
|
|
38
|
+
}
|
|
39
|
+
function formatSystemLabel(name) {
|
|
40
|
+
return name
|
|
41
|
+
.split(/[-_]/)
|
|
42
|
+
.filter(Boolean)
|
|
43
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
44
|
+
.join(' ');
|
|
45
|
+
}
|
|
46
|
+
function formatPlatformLabel(expression) {
|
|
47
|
+
const platforms = parsePlatformExpression(expression).map((platform) => {
|
|
48
|
+
if (platform === 'none') {
|
|
49
|
+
return 'Platform-neutral';
|
|
50
|
+
}
|
|
51
|
+
if (platform === 'drupal') {
|
|
52
|
+
return 'Drupal';
|
|
53
|
+
}
|
|
54
|
+
return 'WordPress';
|
|
55
|
+
});
|
|
56
|
+
if (platforms.length <= 1) {
|
|
57
|
+
return platforms[0] || expression;
|
|
58
|
+
}
|
|
59
|
+
return `${platforms.slice(0, -1).join(', ')} and ${platforms.at(-1)}`;
|
|
60
|
+
}
|
|
61
|
+
function formatRepositorySource(repository) {
|
|
62
|
+
try {
|
|
63
|
+
const url = new URL(repository);
|
|
64
|
+
if (url.protocol === 'file:') {
|
|
65
|
+
return decodeURIComponent(url.pathname).replace(/\.git\/?$/, '');
|
|
66
|
+
}
|
|
67
|
+
if (url.host) {
|
|
68
|
+
return `${url.host}${url.pathname}`.replace(/\.git\/?$/, '');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
}
|
|
73
|
+
const scpStyle = repository.match(/^(?:[^@\s]+@)?([^:]+):(.+)$/);
|
|
74
|
+
if (scpStyle) {
|
|
75
|
+
return `${scpStyle[1]}/${scpStyle[2]}`.replace(/\.git\/?$/, '');
|
|
76
|
+
}
|
|
77
|
+
return repository.replace(/\.git\/?$/, '');
|
|
78
|
+
}
|
|
79
|
+
function validateRepositoryInput(repository) {
|
|
80
|
+
try {
|
|
81
|
+
return getGitRepoNameFromUrl(repository.trim())
|
|
82
|
+
? true
|
|
83
|
+
: 'Enter a Git repository with a recognizable name.';
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return error instanceof Error ? error.message : String(error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
25
89
|
export async function getSystemRepoInfo(name, { repository, checkout }) {
|
|
26
90
|
if (repository && !checkout) {
|
|
27
91
|
throw new CliError('The --repository option requires --checkout when installing a custom system.');
|
|
@@ -61,34 +125,122 @@ export async function getSystemRepoInfo(name, { repository, checkout }) {
|
|
|
61
125
|
}
|
|
62
126
|
}
|
|
63
127
|
async function promptForSystemInstallChoice() {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
128
|
+
const selectedSource = await runPrompt({
|
|
129
|
+
prompt: async () => {
|
|
130
|
+
const availableSystems = await getAvailableSystems();
|
|
131
|
+
showWizardStep(1);
|
|
132
|
+
return select({
|
|
133
|
+
message: 'Which system?',
|
|
134
|
+
choices: [
|
|
135
|
+
...availableSystems.map((reference) => ({
|
|
136
|
+
name: formatChoice(reference.label, reference.description),
|
|
137
|
+
value: { kind: 'built-in', reference },
|
|
138
|
+
short: reference.label,
|
|
139
|
+
})),
|
|
140
|
+
{
|
|
141
|
+
name: formatChoice('Bring your own', 'Install from a git repository you control.'),
|
|
142
|
+
value: { kind: 'custom' },
|
|
143
|
+
short: 'Bring your own',
|
|
144
|
+
},
|
|
145
|
+
new Separator('────────────'),
|
|
146
|
+
{
|
|
147
|
+
name: 'Cancel',
|
|
148
|
+
value: { kind: 'cancel' },
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
nonInteractive: { error: MISSING_SYSTEM_SOURCE_ERROR },
|
|
72
154
|
});
|
|
73
|
-
if (
|
|
155
|
+
if (selectedSource.kind === 'cancel') {
|
|
74
156
|
log('info', 'System install cancelled.');
|
|
75
157
|
return;
|
|
76
158
|
}
|
|
77
|
-
return
|
|
159
|
+
return selectedSource;
|
|
160
|
+
}
|
|
161
|
+
async function promptForCustomRepository(step, total) {
|
|
162
|
+
return runPrompt({
|
|
163
|
+
prompt: () => {
|
|
164
|
+
showWizardStep(step, total);
|
|
165
|
+
return input({
|
|
166
|
+
message: 'Repository URL or local path:',
|
|
167
|
+
validate: validateRepositoryInput,
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
nonInteractive: {
|
|
171
|
+
error: 'A custom repository is required in non-interactive mode. Pass --repository <repository>.',
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
async function promptForCustomCheckout(step, total) {
|
|
176
|
+
return runPrompt({
|
|
177
|
+
prompt: () => {
|
|
178
|
+
showWizardStep(step, total);
|
|
179
|
+
return input({
|
|
180
|
+
message: 'Checkout (branch, tag, or commit):',
|
|
181
|
+
validate: (value) => value.trim().length > 0 || 'Enter a branch, tag, or commit.',
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
nonInteractive: {
|
|
185
|
+
error: 'A custom checkout is required in non-interactive mode. Pass --checkout <branch, tag, or commit>.',
|
|
186
|
+
},
|
|
187
|
+
});
|
|
78
188
|
}
|
|
79
189
|
function getVariantSelectionErrorMessage(systemConf, projectPlatform, requestedVariant) {
|
|
80
|
-
const availableVariants = getVariantPlatformExpressions(systemConf.variants)
|
|
81
|
-
const
|
|
82
|
-
?
|
|
83
|
-
|
|
84
|
-
|
|
190
|
+
const availableVariants = getVariantPlatformExpressions(systemConf.variants);
|
|
191
|
+
const availableComponentSets = availableVariants.length
|
|
192
|
+
? availableVariants
|
|
193
|
+
.map((expression) => `${formatPlatformLabel(expression)} (${expression})`)
|
|
194
|
+
.join(', ')
|
|
195
|
+
: 'none';
|
|
196
|
+
if (requestedVariant) {
|
|
197
|
+
return `The ${formatSystemLabel(systemConf.name)} system has no component set matching --variant "${requestedVariant}". Available component sets: ${availableComponentSets}.`;
|
|
198
|
+
}
|
|
199
|
+
return `The ${formatSystemLabel(systemConf.name)} system has no component set that works with this ${formatPlatformLabel(projectPlatform)} project. Available component sets: ${availableComponentSets}. Pass --variant <platform-expression> to choose one explicitly.`;
|
|
85
200
|
}
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
201
|
+
function getVariantPromptErrorMessage(systemConf) {
|
|
202
|
+
const availableComponentSets = getVariantPlatformExpressions(systemConf.variants)
|
|
203
|
+
.map((expression) => `${formatPlatformLabel(expression)} (${expression})`)
|
|
204
|
+
.join(', ');
|
|
205
|
+
return `A component set choice is required in non-interactive mode. Pass --variant <platform-expression>. Available component sets: ${availableComponentSets || 'none'}.`;
|
|
206
|
+
}
|
|
207
|
+
async function promptForVariantChoice(variants, projectPlatform, systemName, nonInteractiveError, wizardStep) {
|
|
208
|
+
const rankedVariants = rankPlatformVariants(variants, projectPlatform);
|
|
209
|
+
const recommendation = selectCompatiblePlatformVariant(variants, projectPlatform);
|
|
210
|
+
const recommendedVariants = new Set(recommendation.status === 'selected'
|
|
211
|
+
? [recommendation.variant]
|
|
212
|
+
: recommendation.status === 'ambiguous'
|
|
213
|
+
? recommendation.variants
|
|
214
|
+
: []);
|
|
215
|
+
const defaultChoice = rankedVariants.find(({ variant }) => recommendedVariants.has(variant))?.index;
|
|
216
|
+
const selectedIndex = await runPrompt({
|
|
217
|
+
prompt: () => {
|
|
218
|
+
if (wizardStep) {
|
|
219
|
+
showWizardStep(wizardStep.step, wizardStep.total);
|
|
220
|
+
}
|
|
221
|
+
return select({
|
|
222
|
+
message: wizardStep
|
|
223
|
+
? 'Which component set?'
|
|
224
|
+
: `Which ${formatSystemLabel(systemName)} component set should be used?`,
|
|
225
|
+
choices: rankedVariants.map(({ variant, index }) => {
|
|
226
|
+
const componentCount = variant.components.length;
|
|
227
|
+
const requiredCount = variant.components.filter(({ required }) => required === true).length;
|
|
228
|
+
const counts = ` · ${pluralize(componentCount, 'component')}, ${pluralize(requiredCount, 'required component')}`;
|
|
229
|
+
const recommended = recommendedVariants.has(variant)
|
|
230
|
+
? ' — Recommended'
|
|
231
|
+
: '';
|
|
232
|
+
return {
|
|
233
|
+
name: `${formatPlatformLabel(variant.platform)} (${variant.platform})${recommended}${counts}`,
|
|
234
|
+
value: index,
|
|
235
|
+
short: formatPlatformLabel(variant.platform),
|
|
236
|
+
};
|
|
237
|
+
}),
|
|
238
|
+
default: defaultChoice,
|
|
239
|
+
});
|
|
240
|
+
},
|
|
241
|
+
nonInteractive: { error: nonInteractiveError },
|
|
90
242
|
});
|
|
91
|
-
return variants
|
|
243
|
+
return variants[selectedIndex];
|
|
92
244
|
}
|
|
93
245
|
async function resolveSystemVariant(systemConf, projectPlatform, requestedVariant) {
|
|
94
246
|
if (requestedVariant) {
|
|
@@ -96,8 +248,8 @@ async function resolveSystemVariant(systemConf, projectPlatform, requestedVarian
|
|
|
96
248
|
if (selection.status === 'selected') {
|
|
97
249
|
return selection.variant;
|
|
98
250
|
}
|
|
99
|
-
if (selection.status === 'ambiguous'
|
|
100
|
-
|
|
251
|
+
if (selection.status === 'ambiguous') {
|
|
252
|
+
throw new CliError(`The ${formatSystemLabel(systemConf.name)} system defines more than one component set for --variant "${requestedVariant}". Ask the system maintainer to give each component set a unique platform expression.`);
|
|
101
253
|
}
|
|
102
254
|
throw new CliError(getVariantSelectionErrorMessage(systemConf, projectPlatform, requestedVariant));
|
|
103
255
|
}
|
|
@@ -106,56 +258,84 @@ async function resolveSystemVariant(systemConf, projectPlatform, requestedVarian
|
|
|
106
258
|
return selection.variant;
|
|
107
259
|
}
|
|
108
260
|
if (selection.status === 'ambiguous') {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
const compatibleVariants = selection.variants
|
|
113
|
-
.map(({ platform }) => platform)
|
|
261
|
+
const compatibleComponentSets = selection.variants
|
|
262
|
+
.map(({ platform }) => `${formatPlatformLabel(platform)} (${platform})`)
|
|
114
263
|
.join(', ');
|
|
115
|
-
|
|
264
|
+
return await promptForVariantChoice(selection.variants, projectPlatform, systemConf.name, `More than one ${formatSystemLabel(systemConf.name)} component set works equally well with this ${formatPlatformLabel(projectPlatform)} project: ${compatibleComponentSets}. Run this command in an interactive terminal, or pass --variant <platform-expression>.`);
|
|
116
265
|
}
|
|
117
266
|
throw new CliError(getVariantSelectionErrorMessage(systemConf, projectPlatform, undefined));
|
|
118
267
|
}
|
|
119
|
-
function
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
],
|
|
133
|
-
variants: [
|
|
134
|
-
{
|
|
135
|
-
platform,
|
|
136
|
-
structureImplementations: [
|
|
268
|
+
async function promptForInstallScope(variant, step, total) {
|
|
269
|
+
const requiredComponentCount = variant.components.filter(({ required }) => required === true).length;
|
|
270
|
+
return runPrompt({
|
|
271
|
+
prompt: () => {
|
|
272
|
+
showWizardStep(step, total);
|
|
273
|
+
return select({
|
|
274
|
+
message: 'How much do you want to install?',
|
|
275
|
+
choices: [
|
|
276
|
+
{
|
|
277
|
+
name: formatChoice('Essentials only', pluralize(requiredComponentCount, 'required component')),
|
|
278
|
+
value: false,
|
|
279
|
+
short: 'Essentials only',
|
|
280
|
+
},
|
|
137
281
|
{
|
|
138
|
-
name: 'components',
|
|
139
|
-
|
|
282
|
+
name: formatChoice('Everything', pluralize(variant.components.length, 'component')),
|
|
283
|
+
value: true,
|
|
284
|
+
short: 'Everything',
|
|
140
285
|
},
|
|
141
286
|
],
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
287
|
+
default: false,
|
|
288
|
+
});
|
|
289
|
+
},
|
|
290
|
+
nonInteractive: {
|
|
291
|
+
error: 'Install scope is required in non-interactive mode. Pass --all to install every component, or provide a system name to install required components only.',
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function formatDestinationList(destinations) {
|
|
296
|
+
return destinations.length > 0 ? destinations.join(', ') : 'none';
|
|
297
|
+
}
|
|
298
|
+
function formatDirectoryDestinations(destinations) {
|
|
299
|
+
return formatDestinationList(destinations.map((destination) => destination === '.' || destination.endsWith('/')
|
|
300
|
+
? destination
|
|
301
|
+
: `${destination}/`));
|
|
302
|
+
}
|
|
303
|
+
export function formatSystemInstallReview(systemLabel, repository, checkout, variant, plan, installAll) {
|
|
304
|
+
const continuationIndent = ' ';
|
|
305
|
+
const installRows = [
|
|
306
|
+
`${pluralize(plan.components.length, 'component')} → ${formatDirectoryDestinations(plan.componentParentDestinations)}`,
|
|
307
|
+
];
|
|
308
|
+
if (plan.directoryAssetCount > 0) {
|
|
309
|
+
installRows.push(`${pluralize(plan.directoryAssetCount, 'asset folder')} → ${formatDestinationList(plan.directoryAssetDestinations)}`);
|
|
310
|
+
}
|
|
311
|
+
if (plan.fileAssetCount > 0) {
|
|
312
|
+
installRows.push(`${pluralize(plan.fileAssetCount, 'asset file')} → ${formatDestinationList(plan.fileAssetDestinations)}`);
|
|
313
|
+
}
|
|
314
|
+
return [
|
|
315
|
+
` System ${systemLabel}${checkout ? ` · ${checkout}` : ''}`,
|
|
316
|
+
` Source ${formatRepositorySource(repository)}`,
|
|
317
|
+
` Component set ${formatPlatformLabel(variant.platform)}`,
|
|
318
|
+
` Scope ${installAll ? 'Everything' : 'Essentials only'}`,
|
|
319
|
+
` Will install ${installRows[0]}`,
|
|
320
|
+
...installRows.slice(1).map((row) => `${continuationIndent}${row}`),
|
|
321
|
+
].join('\n');
|
|
146
322
|
}
|
|
147
|
-
async function
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
323
|
+
async function promptForInstallConfirmation(review, step, total, accept) {
|
|
324
|
+
showWizardStep(step, total);
|
|
325
|
+
log('info', `\n${review}\n`);
|
|
326
|
+
return runPrompt({
|
|
327
|
+
prompt: () => confirm({
|
|
328
|
+
message: 'Install now?',
|
|
329
|
+
default: true,
|
|
330
|
+
}),
|
|
331
|
+
nonInteractive: {
|
|
332
|
+
error: 'Installation confirmation is required in non-interactive mode. Pass --yes to accept the reviewed installation.',
|
|
333
|
+
},
|
|
334
|
+
accept: {
|
|
335
|
+
when: accept,
|
|
336
|
+
value: true,
|
|
337
|
+
},
|
|
338
|
+
});
|
|
159
339
|
}
|
|
160
340
|
export default async function systemInstall(name, options) {
|
|
161
341
|
const projectConfig = await getEmulsifyConfig();
|
|
@@ -163,25 +343,47 @@ export default async function systemInstall(name, options) {
|
|
|
163
343
|
throw new CliError('No Emulsify project detected. You must run this command within an existing Emulsify project. For more information about creating Emulsify projects, run "emulsify init --help"');
|
|
164
344
|
}
|
|
165
345
|
if (projectConfig.system) {
|
|
166
|
-
throw new CliError('
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
346
|
+
throw new CliError('This Emulsify project already has a component system configured. Run "emulsify component list" to see what is available. To choose a different system, run "emulsify system detach" first.');
|
|
347
|
+
}
|
|
348
|
+
const guidedInstall = !name && !options.repository && !options.checkout;
|
|
349
|
+
let wizardStep = 1;
|
|
350
|
+
let wizardTotalSteps = 0;
|
|
351
|
+
let systemLabel;
|
|
352
|
+
let repo;
|
|
353
|
+
if (guidedInstall) {
|
|
354
|
+
const source = await promptForSystemInstallChoice();
|
|
355
|
+
if (!source) {
|
|
175
356
|
return;
|
|
176
357
|
}
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
|
|
358
|
+
if (source.kind === 'built-in') {
|
|
359
|
+
const { reference } = source;
|
|
360
|
+
systemLabel = reference.label;
|
|
361
|
+
repo = {
|
|
362
|
+
name: reference.name,
|
|
363
|
+
repository: reference.repository,
|
|
364
|
+
checkout: reference.checkout,
|
|
365
|
+
};
|
|
366
|
+
wizardTotalSteps = 2 + (options.variant ? 0 : 1) + (options.all ? 0 : 1);
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
wizardTotalSteps = 4 + (options.variant ? 0 : 1) + (options.all ? 0 : 1);
|
|
370
|
+
const repository = (await promptForCustomRepository(++wizardStep, wizardTotalSteps)).trim();
|
|
371
|
+
const checkout = (await promptForCustomCheckout(++wizardStep, wizardTotalSteps)).trim();
|
|
372
|
+
repo = await getSystemRepoInfo(undefined, {
|
|
373
|
+
...options,
|
|
374
|
+
repository,
|
|
375
|
+
checkout,
|
|
376
|
+
});
|
|
180
377
|
}
|
|
181
378
|
}
|
|
182
|
-
|
|
379
|
+
else {
|
|
380
|
+
repo = await getSystemRepoInfo(name, options);
|
|
381
|
+
}
|
|
183
382
|
if (!repo) {
|
|
184
|
-
throw new CliError(
|
|
383
|
+
throw new CliError(INVALID_SYSTEM_SOURCE_ERROR);
|
|
384
|
+
}
|
|
385
|
+
if (guidedInstall) {
|
|
386
|
+
log('info', `Loading ${systemLabel || 'the component system'} from ${formatRepositorySource(repo.repository)}. This may take a moment…`);
|
|
185
387
|
}
|
|
186
388
|
if (repo.checkout === undefined) {
|
|
187
389
|
repo.checkout = await getRepositoryLatestTag(repo.repository);
|
|
@@ -208,27 +410,65 @@ export default async function systemInstall(name, options) {
|
|
|
208
410
|
}
|
|
209
411
|
catch (e) {
|
|
210
412
|
console.error('System configuration errors:', e);
|
|
211
|
-
throw new CliError(`The system install failed due to the validation errors reported above. Please fix the
|
|
413
|
+
throw new CliError(`The system install failed due to the validation errors reported above. Please fix the errors in the "${systemConf.name}" configuration and try again.`);
|
|
414
|
+
}
|
|
415
|
+
if (systemConf.name !== repo.name) {
|
|
416
|
+
throw new CliError(`The repository was cached as "${repo.name}", but system.emulsify.json declares the system name "${systemConf.name}". These names must match so files can be installed safely. Rename the repository or update the system name, then retry.`);
|
|
417
|
+
}
|
|
418
|
+
if (!repo.checkout) {
|
|
419
|
+
repo.checkout = await getCachedItemCheckout({
|
|
420
|
+
bucket: 'systems',
|
|
421
|
+
itemPath: [repo.name],
|
|
422
|
+
repository: repo.repository,
|
|
423
|
+
checkout: repo.checkout,
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
if (!repo.checkout) {
|
|
427
|
+
throw new CliError('Unable to determine which system checkout was loaded. Retry with --checkout <branch, tag, or commit>.');
|
|
428
|
+
}
|
|
429
|
+
systemLabel ||= formatSystemLabel(systemConf.name);
|
|
430
|
+
if (guidedInstall) {
|
|
431
|
+
log('info', `Loaded ${systemLabel} · ${repo.checkout}.`);
|
|
212
432
|
}
|
|
213
433
|
const projectPlatform = projectConfig.project.platform;
|
|
214
434
|
if (!isPlatform(projectPlatform)) {
|
|
215
|
-
throw new CliError('
|
|
435
|
+
throw new CliError('This project does not declare a supported platform. Set project.platform in project.emulsify.json to none, drupal, or wordpress before installing a component system.');
|
|
216
436
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (
|
|
221
|
-
|
|
222
|
-
bucket: 'systems',
|
|
223
|
-
itemPath: [repo.name],
|
|
224
|
-
repository: repo.repository,
|
|
225
|
-
checkout: repo.checkout,
|
|
226
|
-
});
|
|
437
|
+
let variantConf;
|
|
438
|
+
if (guidedInstall && !options.variant) {
|
|
439
|
+
const compatibility = selectCompatiblePlatformVariant(systemConf.variants, projectPlatform);
|
|
440
|
+
if (compatibility.status === 'none') {
|
|
441
|
+
throw new CliError(getVariantSelectionErrorMessage(systemConf, projectPlatform, undefined));
|
|
227
442
|
}
|
|
443
|
+
variantConf = await promptForVariantChoice(systemConf.variants || [], projectPlatform, systemConf.name, getVariantPromptErrorMessage(systemConf), { step: ++wizardStep, total: wizardTotalSteps });
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
variantConf = await resolveSystemVariant(systemConf, projectPlatform, options.variant);
|
|
447
|
+
}
|
|
448
|
+
const installAll = guidedInstall && !options.all
|
|
449
|
+
? await promptForInstallScope(variantConf, ++wizardStep, wizardTotalSteps)
|
|
450
|
+
: options.all === true;
|
|
451
|
+
let componentsToInstall = installAll
|
|
452
|
+
? variantConf.components
|
|
453
|
+
: variantConf.components.filter(({ required }) => required === true);
|
|
454
|
+
if (guidedInstall) {
|
|
455
|
+
const projectConfigPath = findFileInCurrentPath(EMULSIFY_PROJECT_CONFIG_FILE);
|
|
456
|
+
if (!projectConfigPath) {
|
|
457
|
+
throw new CliError('Unable to find the Emulsify project configuration for the installation review.');
|
|
458
|
+
}
|
|
459
|
+
const plan = buildSystemInstallPlan(systemConf, variantConf, installAll, projectConfigPath);
|
|
460
|
+
componentsToInstall = plan.components;
|
|
461
|
+
const confirmed = await promptForInstallConfirmation(formatSystemInstallReview(systemLabel, repo.repository, repo.checkout, variantConf, plan, installAll), ++wizardStep, wizardTotalSteps, options.yes === true);
|
|
462
|
+
if (!confirmed) {
|
|
463
|
+
log('info', 'System install cancelled. No project files were changed.');
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
try {
|
|
228
468
|
await setEmulsifyConfig({
|
|
229
469
|
system: {
|
|
230
470
|
repository: repo.repository,
|
|
231
|
-
checkout,
|
|
471
|
+
checkout: repo.checkout,
|
|
232
472
|
},
|
|
233
473
|
variant: {
|
|
234
474
|
platform: variantConf.platform,
|
|
@@ -240,9 +480,7 @@ export default async function systemInstall(name, options) {
|
|
|
240
480
|
throw new CliError('Unable to update your Emulsify project configuration.');
|
|
241
481
|
}
|
|
242
482
|
try {
|
|
243
|
-
const
|
|
244
|
-
const requiredComponents = componentsList.filter(({ required }) => required === true);
|
|
245
|
-
for (const component of options.all ? componentsList : requiredComponents) {
|
|
483
|
+
for (const component of componentsToInstall) {
|
|
246
484
|
await installComponentFromCache(systemConf, variantConf, component.name, true);
|
|
247
485
|
}
|
|
248
486
|
await installGeneralAssetsFromCache(systemConf, variantConf);
|
|
@@ -257,5 +495,7 @@ export default async function systemInstall(name, options) {
|
|
|
257
495
|
catch (e) {
|
|
258
496
|
throw new CliError(`Unable to install system assets and/or required components: ${String(e)}`);
|
|
259
497
|
}
|
|
260
|
-
return log('success',
|
|
498
|
+
return log('success', guidedInstall
|
|
499
|
+
? `Successfully installed the ${systemLabel} system using the ${formatPlatformLabel(variantConf.platform)} component set.`
|
|
500
|
+
: `Successfully installed the ${systemConf.name} system using the ${variantConf.platform} variant.`);
|
|
261
501
|
}
|