@emulsify/cli 2.3.1 → 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.
Files changed (41) hide show
  1. package/README.md +96 -16
  2. package/dist/handlers/componentCreate.js +37 -5
  3. package/dist/handlers/componentEjectTemplates.js +317 -0
  4. package/dist/handlers/componentInstall.js +54 -14
  5. package/dist/handlers/hofs/withEmulsifySystem.js +1 -1
  6. package/dist/handlers/init.js +75 -32
  7. package/dist/handlers/systemCreate.js +222 -0
  8. package/dist/handlers/systemDetach.js +50 -0
  9. package/dist/handlers/systemInstall.js +339 -101
  10. package/dist/index.js +67 -110
  11. package/dist/lib/log.js +12 -9
  12. package/dist/lib/rootHelp.js +321 -0
  13. package/dist/lib/terminalColors.js +10 -0
  14. package/dist/util/cache/cloneIntoCache.js +2 -4
  15. package/dist/util/deriveComponentNames.js +5 -0
  16. package/dist/util/deriveCustomElementTagName.js +25 -0
  17. package/dist/util/fs/writeToJsonFile.js +21 -5
  18. package/dist/util/getGitRepoNameFromUrl.js +47 -3
  19. package/dist/util/getNonInteractiveGitEnvironment.js +7 -0
  20. package/dist/util/getRepositoryLatestTag.js +17 -2
  21. package/dist/util/platform/platformCompatibility.js +18 -7
  22. package/dist/util/project/componentTemplates/buildComponentArtifacts.js +121 -0
  23. package/dist/util/project/componentTemplates/index.js +5 -0
  24. package/dist/util/project/componentTemplates/react.js +20 -0
  25. package/dist/util/project/componentTemplates/reactStories.js +18 -0
  26. package/dist/util/project/componentTemplates/scss.js +2 -3
  27. package/dist/util/project/componentTemplates/sdcStories.js +2 -2
  28. package/dist/util/project/componentTemplates/stories.js +2 -2
  29. package/dist/util/project/componentTemplates/twig.js +2 -3
  30. package/dist/util/project/componentTemplates/webComponent.js +49 -0
  31. package/dist/util/project/componentTemplates/webComponentStories.js +19 -0
  32. package/dist/util/project/componentTypes.js +71 -0
  33. package/dist/util/project/generateComponent.js +139 -101
  34. package/dist/util/project/renderTemplate.js +24 -4
  35. package/dist/util/project/resolveComponentTemplate.js +24 -11
  36. package/dist/util/project/unsetEmulsifyConfig.js +16 -0
  37. package/dist/util/prompt/index.js +25 -0
  38. package/dist/util/system/buildSystemInstallPlan.js +53 -0
  39. package/dist/util/system/buildSystemScaffold.js +99 -0
  40. package/dist/util/system/getAvailableSystems.js +4 -0
  41. 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
- const CREATE_NEW_SYSTEM_CHOICE = 'create a new system';
23
- const CANCEL_SYSTEM_INSTALL_CHOICE = 'cancel';
24
- const SYSTEM_INSTALL_ERROR = 'Unable to download specified system. Specify a valid built-in system name as the positional argument, or provide both --repository and --checkout (branch, tag, or commit) for a custom system.';
20
+ import { getVariantPlatformExpressions, isPlatform, parsePlatformExpression, rankPlatformVariants, selectCompatiblePlatformVariant, selectExactPlatformVariant, } from '../util/platform/platformCompatibility.js';
21
+ import { runPrompt } from '../util/prompt/index.js';
22
+ import buildSystemInstallPlan, { selectSystemComponents, } 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 availableSystems = await getAvailableSystems();
65
- const selectedSystem = await select({
66
- message: 'Choose a component system:',
67
- choices: [
68
- ...availableSystems.map(({ name }) => name),
69
- CREATE_NEW_SYSTEM_CHOICE,
70
- CANCEL_SYSTEM_INSTALL_CHOICE,
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 (selectedSystem === CANCEL_SYSTEM_INSTALL_CHOICE) {
155
+ if (selectedSource.kind === 'cancel') {
74
156
  log('info', 'System install cancelled.');
75
157
  return;
76
158
  }
77
- return selectedSystem;
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).join(', ') || 'none';
81
- const requestedVariantMessage = requestedVariant
82
- ? ` matching "${requestedVariant}"`
83
- : '';
84
- return `Unable to find a compatible variant${requestedVariantMessage} for project platform "${projectPlatform}" within the system (${systemConf.name}). Available variant platform expressions: ${availableVariants}.`;
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
- async function promptForVariantChoice(variants, projectPlatform, systemName) {
87
- const selectedPlatform = await select({
88
- message: `Choose a ${systemName} variant for project platform "${projectPlatform}":`,
89
- choices: variants.map(({ platform }) => platform),
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.find(({ platform }) => platform === selectedPlatform);
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' && process.stdin.isTTY === true) {
100
- return await promptForVariantChoice(selection.variants, projectPlatform, systemConf.name);
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
- if (process.stdin.isTTY === true) {
110
- return await promptForVariantChoice(selection.variants, projectPlatform, systemConf.name);
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
- throw new CliError(`Multiple compatible variants were found for project platform "${projectPlatform}" within the system (${systemConf.name}): ${compatibleVariants}. Run this command in an interactive terminal or specify a variant.`);
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 getCustomSystemPlatform(platform) {
120
- return isPlatform(platform) ? platform : 'none';
121
- }
122
- function buildCustomSystemDefinition(platform) {
123
- return {
124
- name: 'custom-system',
125
- homepage: 'https://example.com/custom-system',
126
- repository: 'https://github.com/example/custom-system.git',
127
- structure: [
128
- {
129
- name: 'components',
130
- description: 'Project component library',
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
- directory: './src/components',
282
+ name: formatChoice('Everything', pluralize(variant.components.length, 'component')),
283
+ value: true,
284
+ short: 'Everything',
140
285
  },
141
286
  ],
142
- components: [],
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 scaffoldCustomSystemDefinition(projectConfig) {
148
- const projectConfigPath = findFileInCurrentPath(EMULSIFY_PROJECT_CONFIG_FILE);
149
- if (!projectConfigPath) {
150
- throw new CliError(`Unable to find ${EMULSIFY_PROJECT_CONFIG_FILE}. Run this command from within an Emulsify project.`);
151
- }
152
- const systemConfigPath = join(dirname(projectConfigPath), EMULSIFY_SYSTEM_CONFIG_FILE);
153
- if (existsSync(systemConfigPath)) {
154
- throw new CliError(`${EMULSIFY_SYSTEM_CONFIG_FILE} already exists. Remove or rename it before creating a new custom system definition.`);
155
- }
156
- await writeToJsonFile(systemConfigPath, buildCustomSystemDefinition(getCustomSystemPlatform(projectConfig.project.platform)));
157
- log('success', `Created ${EMULSIFY_SYSTEM_CONFIG_FILE}.`);
158
- log('info', 'Add your real system name, repository, structures, variants, and components before using this system to install or generate components.');
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('You have already selected a system within this Emulsify project.');
167
- }
168
- let selectedName = name;
169
- if (!selectedName &&
170
- !options.repository &&
171
- !options.checkout &&
172
- process.stdin.isTTY === true) {
173
- selectedName = await promptForSystemInstallChoice();
174
- if (!selectedName) {
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 (selectedName === CREATE_NEW_SYSTEM_CHOICE) {
178
- await scaffoldCustomSystemDefinition(projectConfig);
179
- return;
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
- const repo = await getSystemRepoInfo(selectedName, options);
379
+ else {
380
+ repo = await getSystemRepoInfo(name, options);
381
+ }
183
382
  if (!repo) {
184
- throw new CliError(SYSTEM_INSTALL_ERROR);
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,63 @@ 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 the errors in the "${systemConf.name}" configuration and try again.`);
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('Unable to determine a variant for the specified system. Please either pass in a valid variant using the --variant flag.');
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
- const variantConf = await resolveSystemVariant(systemConf, projectPlatform, options.variant);
218
- try {
219
- let checkout = repo.checkout;
220
- if (!checkout) {
221
- checkout = await getCachedItemCheckout({
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 = selectSystemComponents(variantConf, installAll);
452
+ if (guidedInstall) {
453
+ const projectConfigPath = findFileInCurrentPath(EMULSIFY_PROJECT_CONFIG_FILE);
454
+ if (!projectConfigPath) {
455
+ throw new CliError('Unable to find the Emulsify project configuration for the installation review.');
456
+ }
457
+ const plan = buildSystemInstallPlan(systemConf, variantConf, installAll, projectConfigPath);
458
+ componentsToInstall = plan.components;
459
+ const confirmed = await promptForInstallConfirmation(formatSystemInstallReview(systemLabel, repo.repository, repo.checkout, variantConf, plan, installAll), ++wizardStep, wizardTotalSteps, options.yes === true);
460
+ if (!confirmed) {
461
+ log('info', 'System install cancelled. No project files were changed.');
462
+ return;
463
+ }
464
+ }
465
+ try {
228
466
  await setEmulsifyConfig({
229
467
  system: {
230
468
  repository: repo.repository,
231
- checkout,
469
+ checkout: repo.checkout,
232
470
  },
233
471
  variant: {
234
472
  platform: variantConf.platform,
@@ -240,9 +478,7 @@ export default async function systemInstall(name, options) {
240
478
  throw new CliError('Unable to update your Emulsify project configuration.');
241
479
  }
242
480
  try {
243
- const componentsList = variantConf.components;
244
- const requiredComponents = componentsList.filter(({ required }) => required === true);
245
- for (const component of options.all ? componentsList : requiredComponents) {
481
+ for (const component of componentsToInstall) {
246
482
  await installComponentFromCache(systemConf, variantConf, component.name, true);
247
483
  }
248
484
  await installGeneralAssetsFromCache(systemConf, variantConf);
@@ -257,5 +493,7 @@ export default async function systemInstall(name, options) {
257
493
  catch (e) {
258
494
  throw new CliError(`Unable to install system assets and/or required components: ${String(e)}`);
259
495
  }
260
- return log('success', `Successfully installed the ${systemConf.name} system using the ${variantConf.platform} variant.`);
496
+ return log('success', guidedInstall
497
+ ? `Successfully installed the ${systemLabel} system using the ${formatPlatformLabel(variantConf.platform)} component set.`
498
+ : `Successfully installed the ${systemConf.name} system using the ${variantConf.platform} variant.`);
261
499
  }