@emulsify/cli 2.4.1 → 2.5.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.
Files changed (35) hide show
  1. package/README.md +10 -3
  2. package/dist/handlers/cacheClear.js +5 -6
  3. package/dist/handlers/componentCreate.js +8 -8
  4. package/dist/handlers/componentEjectTemplates.js +22 -20
  5. package/dist/handlers/componentInstall.js +74 -69
  6. package/dist/handlers/componentList.js +51 -4
  7. package/dist/handlers/hofs/withEmulsifySystem.js +3 -1
  8. package/dist/handlers/hofs/withSession.js +8 -0
  9. package/dist/handlers/init.js +144 -132
  10. package/dist/handlers/systemCreate.js +31 -25
  11. package/dist/handlers/systemDetach.js +5 -5
  12. package/dist/handlers/systemInstall.js +59 -53
  13. package/dist/handlers/systemList.js +13 -2
  14. package/dist/index.js +57 -34
  15. package/dist/lib/log.js +21 -24
  16. package/dist/lib/rootHelp.js +30 -5
  17. package/dist/lib/session.js +141 -0
  18. package/dist/schemas/system.json +5 -2
  19. package/dist/schemas/variant.json +8 -5
  20. package/dist/util/cache/cloneIntoCache.js +25 -8
  21. package/dist/util/cache/getCachedItemPath.js +3 -1
  22. package/dist/util/fs/writeToJsonFile.js +4 -1
  23. package/dist/util/getGitRepoNameFromUrl.js +21 -10
  24. package/dist/util/getNonInteractiveGitEnvironment.js +1 -1
  25. package/dist/util/platform/getInitSuccessMessageForPlatform.js +15 -9
  26. package/dist/util/project/componentNpmDependencies.js +169 -0
  27. package/dist/util/project/componentNpmManifest.js +164 -0
  28. package/dist/util/project/generateComponent.js +98 -39
  29. package/dist/util/project/installComponentNpmDependencies.js +197 -0
  30. package/dist/util/project/installDependencies.js +10 -3
  31. package/dist/util/project/resolveComponentTemplate.js +11 -1
  32. package/dist/util/prompt/index.js +21 -6
  33. package/dist/util/system/validateSystemConfig.js +51 -13
  34. package/package.json +16 -18
  35. package/dist/handlers/hofs/withProgressBar.js +0 -10
@@ -1,14 +1,29 @@
1
+ import { isCancel } from '@clack/prompts';
1
2
  import CliError from '../../lib/CliError.js';
2
- export function isInteractiveTerminal() {
3
- return process.stdin.isTTY === true;
3
+ export const PROMPT_CANCELLED_EXIT_CODE = 130;
4
+ export const PROMPT_CANCELLED_MESSAGE = 'Cancelled. Nothing was changed.';
5
+ export class PromptCancelledError extends CliError {
6
+ constructor(message = PROMPT_CANCELLED_MESSAGE) {
7
+ super(message, PROMPT_CANCELLED_EXIT_CODE);
8
+ this.name = 'PromptCancelledError';
9
+ }
10
+ }
11
+ export function isInteractiveTerminal(input = process.stdin, environment = process.env) {
12
+ return input.isTTY === true && !environment.CI;
4
13
  }
5
14
  export function requireInteractiveTerminal(nonInteractiveError) {
6
15
  if (!isInteractiveTerminal()) {
7
16
  throw new CliError(nonInteractiveError);
8
17
  }
9
18
  }
10
- export function isExitPromptError(error) {
11
- return error instanceof Error && error.name === 'ExitPromptError';
19
+ export function isPromptCancelledError(error) {
20
+ return error instanceof PromptCancelledError;
21
+ }
22
+ export function unwrapPromptResult(result) {
23
+ if (isCancel(result)) {
24
+ throw new PromptCancelledError();
25
+ }
26
+ return result;
12
27
  }
13
28
  export async function runPrompt({ prompt, nonInteractive, accept, }) {
14
29
  if (accept?.when === true) {
@@ -16,10 +31,10 @@ export async function runPrompt({ prompt, nonInteractive, accept, }) {
16
31
  }
17
32
  if ('error' in nonInteractive) {
18
33
  requireInteractiveTerminal(nonInteractive.error);
19
- return prompt();
34
+ return unwrapPromptResult(await prompt());
20
35
  }
21
36
  if (!isInteractiveTerminal()) {
22
37
  return nonInteractive.value;
23
38
  }
24
- return prompt();
39
+ return unwrapPromptResult(await prompt());
25
40
  }
@@ -1,27 +1,65 @@
1
1
  import { Ajv } from 'ajv';
2
2
  import addFormats from 'ajv-formats';
3
- async function loadSchemas() {
4
- const [{ default: systemSchema }, { default: variantSchema }] = await Promise.all([
3
+ import { lt, valid } from 'semver';
4
+ import CliError from '../../lib/CliError.js';
5
+ import log from '../../lib/log.js';
6
+ const upgradeCommand = 'npm i -g @emulsify/cli@latest';
7
+ async function createValidator() {
8
+ const [{ default: systemSchema }, { default: variantSchema }, { default: packageInfo },] = await Promise.all([
5
9
  import('../../schemas/system.json', { with: { type: 'json' } }),
6
10
  import('../../schemas/variant.json', { with: { type: 'json' } }),
11
+ import('../../../package.json', { with: { type: 'json' } }),
7
12
  ]);
8
- return { systemSchema, variantSchema };
13
+ const ajv = new Ajv();
14
+ addFormats(ajv, ['uri']);
15
+ ajv.addFormat('semver', (value) => valid(value) !== null);
16
+ ajv.addSchema(variantSchema, 'variant.json');
17
+ return {
18
+ validate: ajv.compile(systemSchema),
19
+ schemas: { systemSchema, variantSchema },
20
+ runningVersion: packageInfo.version,
21
+ };
9
22
  }
10
23
  let validatorPromise;
11
- async function getValidator() {
12
- if (!validatorPromise) {
13
- validatorPromise = loadSchemas().then(({ systemSchema, variantSchema }) => {
14
- const ajv = new Ajv();
15
- addFormats(ajv, ['uri']);
16
- ajv.addSchema(variantSchema, 'variant.json');
17
- return ajv.compile(systemSchema);
18
- });
24
+ function warnUnknownProperties(systemConfig, { systemSchema, variantSchema, }) {
25
+ const unknown = [];
26
+ const collect = (value, properties, location) => {
27
+ const keys = Object.keys(value).filter((key) => !Object.hasOwn(properties, key));
28
+ if (keys.length > 0) {
29
+ unknown.push(`${location}: ${keys.join(', ')}`);
30
+ }
31
+ };
32
+ collect(systemConfig, systemSchema.properties, 'system');
33
+ const variantProperties = systemSchema.properties.variants.items.anyOf[0].properties;
34
+ const items = [
35
+ ['structureImplementations', 'structure implementation'],
36
+ ['components', 'component'],
37
+ ['directories', 'directory'],
38
+ ['files', 'file'],
39
+ ];
40
+ for (const [index, variant] of (systemConfig.variants ?? []).entries()) {
41
+ const location = `variant[${index}] (${JSON.stringify(variant.platform)})`;
42
+ collect(variant, variantProperties, location);
43
+ for (const [key, label] of items) {
44
+ for (const item of variant[key] ?? []) {
45
+ collect(item, variantSchema.definitions[key].items.properties, `${location} ${label} ${JSON.stringify(item.name)}`);
46
+ }
47
+ }
48
+ }
49
+ if (unknown.length > 0) {
50
+ log('warn', `This system uses configuration this version of Emulsify CLI does not understand (${unknown.join('; ')}). Upgrade with \`${upgradeCommand}\` if the system is not behaving as documented.`);
19
51
  }
20
- return validatorPromise;
21
52
  }
22
53
  export default async function validateSystemConfig(systemConfig) {
23
- const validate = await getValidator();
54
+ const { validate, schemas, runningVersion } = await (validatorPromise ??=
55
+ createValidator());
24
56
  if (validate(systemConfig)) {
57
+ const { name, minimumCliVersion } = systemConfig;
58
+ if (minimumCliVersion !== undefined &&
59
+ lt(runningVersion.split(/[+-]/, 1)[0], minimumCliVersion.split(/[+-]/, 1)[0])) {
60
+ throw new CliError(`The ${JSON.stringify(name)} system requires Emulsify CLI ${minimumCliVersion} or newer. You are running ${runningVersion}. Upgrade with: ${upgradeCommand}`);
61
+ }
62
+ warnUnknownProperties(systemConfig, schemas);
25
63
  return { valid: true, systemConfig };
26
64
  }
27
65
  return { valid: false, errors: validate.errors };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@emulsify/cli",
3
3
  "productName": "Emulsify CLI",
4
- "version": "2.4.1",
4
+ "version": "2.5.0",
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>",
@@ -49,37 +49,35 @@
49
49
  "prepare": "husky"
50
50
  },
51
51
  "devDependencies": {
52
- "@commitlint/cli": "^21.2.2",
53
- "@commitlint/config-conventional": "^21.2.2",
52
+ "@commitlint/cli": "^21.2.4",
53
+ "@commitlint/config-conventional": "^21.2.4",
54
54
  "@semantic-release/commit-analyzer": "^13.0.1",
55
- "@semantic-release/github": "^12.0.9",
56
- "@semantic-release/npm": "^13.1.5",
55
+ "@semantic-release/github": "^12.0.11",
56
+ "@semantic-release/npm": "^13.2.0",
57
57
  "@semantic-release/release-notes-generator": "^14.1.1",
58
58
  "@types/fs-extra": "^11.0.4",
59
59
  "@types/jest": "^30.0.0",
60
- "@types/node": "^26.4.0",
61
- "@types/progress": "^2.0.7",
60
+ "@types/node": "^26.6.10",
61
+ "@types/semver": "^7.8.0",
62
62
  "husky": "^9.1.7",
63
- "jest": "^30.5.0",
63
+ "jest": "^30.5.2",
64
64
  "json-schema-to-typescript": "^16.0.0",
65
- "lint-staged": "^17.4.1",
65
+ "lint-staged": "^17.6.2",
66
66
  "nodemon": "^3.1.14",
67
- "prettier": "^3.9.6",
67
+ "prettier": "^3.10.1",
68
68
  "semantic-release": "^25.0.9",
69
- "ts-jest": "^29.4.12",
69
+ "ts-jest": "^29.4.15",
70
70
  "ts-node": "^10.9.2",
71
71
  "typescript": "^6.0.3"
72
72
  },
73
73
  "dependencies": {
74
- "@inquirer/prompts": "^8.7.0",
74
+ "@clack/prompts": "^1.9.0",
75
75
  "ajv": "^8.20.0",
76
76
  "ajv-formats": "^3.0.1",
77
- "boxen": "^8.0.1",
78
77
  "colorette": "^2.0.20",
79
- "commander": "^15.0.0",
80
- "consola": "^3.4.2",
81
- "fs-extra": "^11.4.0",
82
- "progress": "^2.0.3",
83
- "simple-git": "^3.36.0"
78
+ "commander": "^15.1.0",
79
+ "fs-extra": "^11.4.1",
80
+ "semver": "^7.8.6",
81
+ "simple-git": "^4.1.0"
84
82
  }
85
83
  }
@@ -1,10 +0,0 @@
1
- import ProgressBar from 'progress';
2
- export default function withProgressBar(handler) {
3
- const progress = new ProgressBar('[:bar] :percent :message', {
4
- total: 100,
5
- complete: '=',
6
- incomplete: ' ',
7
- width: 100,
8
- });
9
- return handler(progress);
10
- }