@astryxdesign/cli 0.7.14 → 0.7.15-canary.g06b7e61

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 (203) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/README.md +63 -63
  3. package/api/build/_adapter.d.mts +4 -0
  4. package/api/build/_adapter.mjs +28 -2
  5. package/api/build/blocks/blocks.d.mts +10 -1
  6. package/api/build/blocks/blocks.mjs +84 -7
  7. package/api/build/build.mjs +6 -1
  8. package/api/build/tree.d.mts +4 -0
  9. package/api/build/tree.mjs +9 -2
  10. package/api/doctor/_adapter.d.mts +3 -1
  11. package/api/doctor/_adapter.mjs +14 -1
  12. package/api/doctor/_authoring-audit.d.mts +42 -0
  13. package/api/doctor/_authoring-audit.mjs +106 -0
  14. package/api/doctor/doctor.d.mts +7 -0
  15. package/api/doctor/doctor.mjs +24 -39
  16. package/api/doctor/theme-checks.mjs +56 -21
  17. package/api/integration/add-helpers.mjs +5 -0
  18. package/api/integration/add-theme.mjs +15 -110
  19. package/api/integration/validate-integration.mjs +17 -3
  20. package/api/integration/validateIntegration.doc.mjs +1 -1
  21. package/api/search/_adapter.mjs +124 -3
  22. package/api/search/_candidate-score.mjs +63 -9
  23. package/api/search/_entries.d.mts +10 -0
  24. package/api/search/_entries.mjs +68 -1
  25. package/api/search/_gather-templates.d.mts +11 -0
  26. package/api/search/_gather-templates.mjs +22 -2
  27. package/api/search/_words.mjs +26 -6
  28. package/api/swizzle/copy/copy.mjs +1 -1
  29. package/api/theme/_adapter.d.mts +37 -5
  30. package/api/theme/_adapter.mjs +381 -57
  31. package/api/theme/_fork.d.mts +90 -0
  32. package/api/theme/_fork.mjs +246 -0
  33. package/api/theme/build/build.d.mts +40 -2
  34. package/api/theme/build/build.mjs +477 -66
  35. package/api/theme/eject/eject.mjs +36 -15
  36. package/api/theme/list/list.mjs +3 -6
  37. package/api/theme/palette/generate/generator.d.mts +13 -0
  38. package/api/theme/palette/generate/generator.mjs +32 -2
  39. package/api/theme/targets/targets.d.mts +8 -0
  40. package/api/theme/targets/targets.mjs +24 -4
  41. package/api/theme/template/template.mjs +48 -2
  42. package/api/theme/theme.type.d.mts +8 -0
  43. package/api/theme/theme.type.mjs +5 -1
  44. package/api/theme/themeBuild.doc.mjs +7 -4
  45. package/api/theme/themeEject.doc.mjs +3 -3
  46. package/api/theme/themeRemove.doc.mjs +5 -2
  47. package/api/theme/themeTargets.doc.mjs +1 -1
  48. package/api/theme/themeTemplate.doc.mjs +2 -2
  49. package/api/theme/themeUse.doc.mjs +8 -2
  50. package/api/theme-edit/_adapter.d.mts +46 -3
  51. package/api/theme-edit/_adapter.mjs +496 -112
  52. package/api/theme-edit/_catalog.d.mts +1 -6
  53. package/api/theme-edit/_catalog.mjs +5 -268
  54. package/api/theme-edit/_check.d.mts +9 -4
  55. package/api/theme-edit/_check.mjs +1232 -229
  56. package/api/theme-edit/_color.d.mts +19 -0
  57. package/api/theme-edit/_color.mjs +280 -34
  58. package/api/theme-edit/_compiler.d.mts +3 -1
  59. package/api/theme-edit/_compiler.mjs +52 -13
  60. package/api/theme-edit/_context.d.mts +4 -1
  61. package/api/theme-edit/_context.mjs +126 -13
  62. package/api/theme-edit/_css.d.mts +84 -0
  63. package/api/theme-edit/_css.mjs +700 -0
  64. package/api/theme-edit/_edit.d.mts +9 -3
  65. package/api/theme-edit/_edit.mjs +806 -103
  66. package/api/theme-edit/_how-commands.d.mts +38 -7
  67. package/api/theme-edit/_how-commands.mjs +64 -45
  68. package/api/theme-edit/_how-question.d.mts +33 -0
  69. package/api/theme-edit/_how-question.mjs +2553 -381
  70. package/api/theme-edit/_how.mjs +402 -31
  71. package/api/theme-edit/_overview.mjs +2 -7
  72. package/api/theme-edit/_palette.d.mts +60 -13
  73. package/api/theme-edit/_palette.mjs +826 -295
  74. package/api/theme-edit/_parts.d.mts +42 -10
  75. package/api/theme-edit/_parts.mjs +280 -69
  76. package/api/theme-edit/_png.d.mts +4 -4
  77. package/api/theme-edit/_png.mjs +4 -2
  78. package/api/theme-edit/_preview-app.d.mts +14 -0
  79. package/api/theme-edit/_preview-app.mjs +1675 -235
  80. package/api/theme-edit/_preview.d.mts +7 -16
  81. package/api/theme-edit/_preview.mjs +79 -86
  82. package/api/theme-edit/_project.d.mts +32 -2
  83. package/api/theme-edit/_project.mjs +80 -19
  84. package/api/theme-edit/_settings.d.mts +199 -52
  85. package/api/theme-edit/_settings.mjs +1422 -217
  86. package/api/theme-edit/_tables.d.mts +19 -6
  87. package/api/theme-edit/_tables.mjs +150 -92
  88. package/api/theme-edit/theme-edit.type.d.mts +20 -1
  89. package/api/theme-edit/theme-edit.type.mjs +6 -3
  90. package/api/theme-edit/themeEditHow.doc.mjs +6 -0
  91. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  92. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  93. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  94. package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
  95. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
  96. package/api/theme-edit/themeEditSet.doc.mjs +1 -1
  97. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  98. package/api/upgrade/_adapter.d.mts +1 -0
  99. package/assets/codemods/run-codemod.mjs +61 -0
  100. package/assets/codemods/runner.mjs +5 -4
  101. package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
  102. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
  103. package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
  104. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
  105. package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
  106. package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
  107. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
  108. package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
  109. package/assets/docs/tree/calendars.doc.mjs +1 -3
  110. package/assets/docs/tree/checks.doc.mjs +22 -1
  111. package/assets/docs/tree/publishing.doc.mjs +1 -0
  112. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  113. package/assets/docs.generated.json +2 -1
  114. package/assets/preview-app/next.config.mjs +7 -1
  115. package/assets/self-audit.generated.json +1 -0
  116. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
  117. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
  118. package/assets/templates/components.generated.json +1 -1
  119. package/authoring/integration/integration.doc.mjs +8 -0
  120. package/authoring/integration/schema.d.mts +8 -0
  121. package/authoring/integration/schema.mjs +1 -0
  122. package/authoring/integration/type.ts +9 -0
  123. package/clients/cli/bin/astryx.mjs +19 -15
  124. package/clients/cli/build-id.generated.json +1 -0
  125. package/clients/cli/commands/ensure-core-built.mjs +12 -5
  126. package/clients/cli/commands/experimental/index.mjs +10 -10
  127. package/clients/cli/commands/experimental/theme.mjs +200 -81
  128. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  129. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
  130. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
  131. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
  132. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  133. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  134. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  135. package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
  136. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  137. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  138. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
  139. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
  140. package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
  141. package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
  142. package/clients/cli/commands/integration.mjs +8 -0
  143. package/clients/cli/commands/manifest.mjs +5 -2
  144. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  145. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  146. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  147. package/clients/cli/commands/theme.mjs +439 -66
  148. package/clients/cli/index.mjs +27 -6
  149. package/clients/cli/lib/cli-error.mjs +118 -3
  150. package/clients/cli/lib/manifest.mjs +37 -0
  151. package/clients/cli/lib/resolve-theme.mjs +2 -1
  152. package/clients/cli/manifest.generated.json +1 -0
  153. package/foundation/config/project.mjs +34 -8
  154. package/foundation/config/theme-state.d.mts +16 -0
  155. package/foundation/config/theme-state.mjs +84 -13
  156. package/foundation/discovery/module-exports.mjs +16 -2
  157. package/foundation/discovery/stored-self-audit.d.mts +31 -0
  158. package/foundation/discovery/stored-self-audit.mjs +119 -0
  159. package/foundation/discovery/template-adapter.d.mts +48 -2
  160. package/foundation/discovery/template-adapter.mjs +51 -19
  161. package/foundation/discovery/template-needs.d.mts +19 -0
  162. package/foundation/discovery/template-needs.mjs +50 -16
  163. package/foundation/discovery/template-source-tree.d.mts +7 -0
  164. package/foundation/discovery/template-source-tree.mjs +15 -0
  165. package/foundation/discovery/theme-discovery.d.mts +2 -1
  166. package/foundation/discovery/theme-discovery.mjs +16 -10
  167. package/foundation/discovery/theme-imports.d.mts +16 -0
  168. package/foundation/discovery/theme-imports.mjs +30 -2
  169. package/foundation/discovery/theme-module-extensions.d.mts +18 -0
  170. package/foundation/discovery/theme-module-extensions.mjs +30 -0
  171. package/foundation/doc-compiler/import.mjs +22 -15
  172. package/foundation/doc-compiler/stored-docs.d.mts +18 -12
  173. package/foundation/doc-compiler/stored-docs.mjs +52 -19
  174. package/foundation/env/private-dir.d.mts +17 -0
  175. package/foundation/env/private-dir.mjs +42 -0
  176. package/foundation/fs/gather-cache.d.mts +108 -0
  177. package/foundation/fs/gather-cache.mjs +783 -0
  178. package/foundation/fs/jiti-cache.d.mts +21 -0
  179. package/foundation/fs/jiti-cache.mjs +66 -0
  180. package/foundation/fs/module-loader.mjs +14 -3
  181. package/foundation/fs/read-record.d.mts +31 -1
  182. package/foundation/fs/read-record.mjs +100 -7
  183. package/foundation/integrations/autolink.d.mts +1 -24
  184. package/foundation/integrations/autolink.mjs +7 -60
  185. package/foundation/integrations/declared-dependencies.d.mts +27 -0
  186. package/foundation/integrations/declared-dependencies.mjs +73 -0
  187. package/foundation/integrations/integrations.d.mts +8 -0
  188. package/foundation/integrations/integrations.mjs +4 -0
  189. package/foundation/integrations/may-have-integrations.d.mts +8 -0
  190. package/foundation/integrations/may-have-integrations.mjs +47 -0
  191. package/foundation/integrations/validate-contributions.d.mts +62 -1
  192. package/foundation/integrations/validate-contributions.mjs +476 -40
  193. package/foundation/release/cache.d.mts +32 -4
  194. package/foundation/release/cache.mjs +105 -16
  195. package/foundation/release/folder-lock.d.mts +28 -0
  196. package/foundation/release/folder-lock.mjs +205 -0
  197. package/foundation/release/lock-lease.d.mts +2 -1
  198. package/foundation/release/lock-lease.mjs +7 -2
  199. package/foundation/response/error-codes.doc.mjs +1 -1
  200. package/foundation/response/response-types.doc.mjs +5 -5
  201. package/package.json +8 -6
  202. package/api/theme-edit/_css-properties.d.mts +0 -10
  203. package/api/theme-edit/_css-properties.mjs +0 -556
@@ -99,6 +99,14 @@ export const doc = {
99
99
  "Link to this integration's docs site, such as its home page. Catalogs that list the package may show it.",
100
100
  example: "'https://widgets.acme.dev'",
101
101
  },
102
+ {
103
+ name: 'logo',
104
+ type: '{ light: string; dark?: string }',
105
+ description:
106
+ "The square logo catalogs show beside your package's name: paths, relative to the package root, to images the package ships. Each is a PNG, JPEG or WebP image, or a shapes-only SVG, of at most 512 KB, whose extension (`.png`, `.jpg`, `.jpeg`, `.webp`, `.svg`) names its format. Set `dark` for a version drawn for dark backgrounds; without it, `light` is used everywhere. `{@command integration check}` notes a logo that is missing, not one of those images, or not packed. In an SVG, no attribute value may hold `<`, `>`, `&` or `\\`, so write `and` rather than `&amp;` in a label. A package.json `marketplace.logo` is also read when this field is not set.",
107
+ example:
108
+ "{ light: './marketplace/logo.svg', dark: './marketplace/logo-dark.svg' }",
109
+ },
102
110
  {
103
111
  name: 'cliCommand',
104
112
  type: 'string',
@@ -53,6 +53,10 @@ export const integrationBaseSchema: z.ZodObject<{
53
53
  }, z.core.$strip>>;
54
54
  issuesUrl: z.ZodOptional<z.ZodString>;
55
55
  docsiteUrl: z.ZodOptional<z.ZodString>;
56
+ logo: z.ZodOptional<z.ZodObject<{
57
+ light: z.ZodString;
58
+ dark: z.ZodOptional<z.ZodString>;
59
+ }, z.core.$strip>>;
56
60
  }, z.core.$strip>;
57
61
  export const integrationSchema: z.ZodObject<{
58
62
  providerId: z.ZodOptional<z.ZodString>;
@@ -66,6 +70,10 @@ export const integrationSchema: z.ZodObject<{
66
70
  }, z.core.$strip>>;
67
71
  issuesUrl: z.ZodOptional<z.ZodString>;
68
72
  docsiteUrl: z.ZodOptional<z.ZodString>;
73
+ logo: z.ZodOptional<z.ZodObject<{
74
+ light: z.ZodString;
75
+ dark: z.ZodOptional<z.ZodString>;
76
+ }, z.core.$strip>>;
69
77
  agentDocs: z.ZodOptional<z.ZodObject<{
70
78
  append: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
71
79
  }, z.core.$strip>>;
@@ -99,6 +99,7 @@ export const integrationBaseSchema = z.object({
99
99
  experimental: z.object({iconSets: z.string().optional()}).optional(),
100
100
  issuesUrl: z.string().url().optional(),
101
101
  docsiteUrl: z.string().url().optional(),
102
+ logo: z.object({light: z.string(), dark: z.string().optional()}).optional(),
102
103
  });
103
104
 
104
105
  // Unknown top-level keys are stripped rather than rejected. `.strict()` made a key from a
@@ -56,6 +56,15 @@ export interface AstryxIntegration {
56
56
  * accepts it as a known field; catalogs that list the package may show
57
57
  * it. */
58
58
  docsiteUrl?: string;
59
+ /** The square logo catalogs show beside the package name: paths, relative
60
+ * to the package root, to images the package ships. Each is a PNG, JPEG,
61
+ * WebP, or an SVG drawn only with shapes, at most 512 KB. `dark`, when
62
+ * set, is drawn for dark backgrounds; without it `light` is used
63
+ * everywhere. `astryx integration check` checks both. */
64
+ logo?: {
65
+ light: string;
66
+ dark?: string;
67
+ };
59
68
  /** The command that runs the Astryx CLI for this package's users, such as
60
69
  * `acme astryx`. Every command the CLI prints in a project that loads
61
70
  * this package starts with it, in place of the package-manager prefix
@@ -24,8 +24,12 @@
24
24
  import {fileURLToPath, pathToFileURL} from 'node:url';
25
25
  import {dirname, join} from 'node:path';
26
26
  import * as nodeModule from 'node:module';
27
- import {existsSync, lstatSync, mkdirSync, realpathSync} from 'node:fs';
27
+ import {existsSync, mkdirSync, realpathSync} from 'node:fs';
28
28
  import {tmpdir} from 'node:os';
29
+ import {
30
+ currentUid,
31
+ isPrivateDir,
32
+ } from '../../../foundation/env/private-dir.mjs';
29
33
 
30
34
  // Node's compile cache keeps the compiled form of the CLI's modules between
31
35
  // runs, so a run skips most of their compiling. It lives in a folder of the
@@ -33,24 +37,19 @@ import {tmpdir} from 'node:os';
33
37
  // only once that folder exists, so a machine's first run just makes it and a
34
38
  // one-off run never pays to write the cache; and only while it is a real
35
39
  // folder the user owns that no one else can reach, since a shared folder
36
- // could hold planted cache files. Where the system has no user ids
40
+ // could hold planted cache files (foundation/env/private-dir.mjs, the check
41
+ // the kept search catalogs use too). Where the system has no user ids
37
42
  // (Windows), ownership cannot be checked, so the cache stays off.
38
43
  // NODE_DISABLE_COMPILE_CACHE turns it off. It is best effort: a cache Node
39
44
  // cannot read or write is skipped, and nothing about it is printed.
40
45
  try {
41
- const uid = typeof process.getuid === 'function' ? process.getuid() : null;
46
+ const uid = currentUid();
42
47
  if (!process.env.NODE_DISABLE_COMPILE_CACHE && uid != null) {
43
48
  const cacheDir = join(tmpdir(), `node-compile-cache-${uid}`);
44
49
  if (!existsSync(cacheDir)) {
45
50
  mkdirSync(cacheDir, {mode: 0o700});
46
- } else {
47
- const stat = lstatSync(cacheDir);
48
- const own =
49
- stat.isDirectory() &&
50
- !stat.isSymbolicLink() &&
51
- stat.uid === uid &&
52
- (stat.mode & 0o077) === 0;
53
- if (own) nodeModule.enableCompileCache?.(cacheDir);
51
+ } else if (isPrivateDir(cacheDir)) {
52
+ nodeModule.enableCompileCache?.(cacheDir);
54
53
  }
55
54
  }
56
55
  } catch {
@@ -91,7 +90,12 @@ if (!isNodeVersionSupported(process.versions.node)) {
91
90
  // does it load and dispatch the command. See clients/cli/run.mjs,
92
91
  // foundation/release/handoff.mjs, and spec AST-081 FR2 and FR9.
93
92
  const {runCli} = await importSrc('run.mjs');
94
- await runCli({
95
- cliRoot: join(binDir, '..', '..', '..'),
96
- argv: process.argv.slice(2),
97
- });
93
+ const {recordRunFor} = await importSrc('../../foundation/fs/gather-cache.mjs');
94
+ // A search or build records what it reads, so a later run with the same
95
+ // inputs can reuse its gathered catalog (foundation/fs/gather-cache.mjs).
96
+ await recordRunFor(process.argv.slice(2), () =>
97
+ runCli({
98
+ cliRoot: join(binDir, '..', '..', '..'),
99
+ argv: process.argv.slice(2),
100
+ }),
101
+ );
@@ -0,0 +1 @@
1
+ {"id":"ca8e51f90acbf3ecbb2593f80d5827b1b9f25fef31c37c520275bc5fca3619aa"}
@@ -231,11 +231,18 @@ export function coreBuildIsStale(entry, roots, generated = []) {
231
231
  }
232
232
 
233
233
  function buildCore() {
234
- execFileSync('pnpm', ['-F', '@astryxdesign/core', 'build'], {
235
- cwd: REPO_ROOT,
236
- stdio: 'pipe',
237
- timeout: BUILD_TIMEOUT_MS,
238
- });
234
+ const args = ['-F', '@astryxdesign/core', 'build'];
235
+ /** @type {import('node:child_process').ExecFileSyncOptions} */
236
+ const options = {cwd: REPO_ROOT, stdio: 'pipe', timeout: BUILD_TIMEOUT_MS};
237
+ // On Windows, pnpm is a `pnpm.cmd` batch file. execFileSync cannot start a
238
+ // batch file without a shell: `pnpm` gives ENOENT and `pnpm.cmd` gives
239
+ // EINVAL. The arguments are literals, so cmd.exe gets them directly.
240
+ /** @type {[string, string[]]} */
241
+ const [file, fileArgs] =
242
+ process.platform === 'win32'
243
+ ? ['cmd.exe', ['/d', '/s', '/c', 'pnpm', ...args]]
244
+ : ['pnpm', args];
245
+ execFileSync(file, fileArgs, options);
239
246
  }
240
247
 
241
248
  /**
@@ -9,7 +9,7 @@
9
9
 
10
10
  import {NO_RESULT_SET} from '../../../../foundation/debug/index.mjs';
11
11
  import {ERROR_CODES} from '../../../../foundation/response/error-codes.mjs';
12
- import {cliError} from '../../lib/cli-error.mjs';
12
+ import {cliError, themeGroupUnknownSubcommand} from '../../lib/cli-error.mjs';
13
13
  import {defineCommand} from '../../lib/define-command.mjs';
14
14
  import {doc as experimentalGroup} from '../experimental.doc.mjs';
15
15
  import {registerExperimentalIcon} from './icon.mjs';
@@ -26,16 +26,16 @@ export function registerExperimental(program) {
26
26
  ) => {
27
27
  const extras = cmd?.args ?? [];
28
28
  if (extras.length > 0) {
29
- return cliError(
30
- `unknown subcommand 'experimental ${String(extras[0])}'`,
31
- {
32
- suggestions: (experimental.commands ?? []).map(command => ({
33
- name: command.name(),
34
- reason: 'available subcommand',
35
- })),
36
- code: ERROR_CODES.ERR_UNKNOWN_SUBCOMMAND,
37
- },
29
+ const {message, suggestions} = themeGroupUnknownSubcommand(
30
+ 'experimental',
31
+ String(extras[0]),
32
+ (experimental.commands ?? []).map(command => command.name()),
33
+ experimental,
38
34
  );
35
+ return cliError(message, {
36
+ suggestions,
37
+ code: ERROR_CODES.ERR_UNKNOWN_SUBCOMMAND,
38
+ });
39
39
  }
40
40
  experimental.help();
41
41
  return NO_RESULT_SET;
@@ -18,6 +18,7 @@
18
18
 
19
19
  import {getCliInvocation} from '../../../../foundation/env/package-manager.mjs';
20
20
  import {jsonOut} from '../../../../foundation/response/json.mjs';
21
+ import {levenshteinDistance} from '../../../../foundation/text/levenshtein.mjs';
21
22
  import {NO_RESULT_SET, resultSet} from '../../../../foundation/debug/index.mjs';
22
23
  import {ERROR_CODES} from '../../../../foundation/response/error-codes.mjs';
23
24
  import {
@@ -43,8 +44,10 @@ import {
43
44
  themeEditUndo,
44
45
  } from '../../../../api/theme-edit/theme-edit.mjs';
45
46
  import {
46
- fileExists,
47
- isHowPicture,
47
+ builtInThemes,
48
+ editorCompileProblem,
49
+ editorThemeHold,
50
+ editorThemeRefusal,
48
51
  } from '../../../../api/theme-edit/_adapter.mjs';
49
52
  import {registerThemeSubcommands} from '../theme.mjs';
50
53
  import {doc as groupDoc} from '../experimental-theme.doc.mjs';
@@ -76,6 +79,7 @@ import {doc as previewAppFn} from '../../../../api/theme-edit/themeEditPreviewAp
76
79
  import {doc as previewListFn} from '../../../../api/theme-edit/themeEditPreviewList.doc.mjs';
77
80
  import {doc as previewRemoveFn} from '../../../../api/theme-edit/themeEditPreviewRemove.doc.mjs';
78
81
  import {doc as howFn} from '../../../../api/theme-edit/themeEditHow.doc.mjs';
82
+ import {quoteCommandArgument} from '../../../../foundation/env/package-manager.mjs';
79
83
 
80
84
  const PREFIX = 'astryx experimental theme';
81
85
  const EDITOR = `${PREFIX} editor`;
@@ -250,6 +254,18 @@ function notCheckedLine(result) {
250
254
  return n ? [`[warn] saved, not checked (${n.code}): ${n.cause}`] : [];
251
255
  }
252
256
 
257
+ /**
258
+ * Text with C0 control characters and DEL shown as escapes (\u001b), so
259
+ * text a person typed cannot move the cursor or recolor the terminal.
260
+ * @param {string} text
261
+ */
262
+ const escapeControls = text =>
263
+ String(text).replace(
264
+ // eslint-disable-next-line no-control-regex
265
+ /[\u0000-\u0008\u000b-\u001f\u007f]/g,
266
+ c => `\\u${`000${c.charCodeAt(0).toString(16)}`.slice(-4)}`,
267
+ );
268
+
253
269
  /**
254
270
  * Run one API call: errors become the CLI error envelope, results go to
255
271
  * JSON or to `render`.
@@ -269,8 +285,14 @@ async function run(program, call, render, answer) {
269
285
  const err = /** @type {import('../../../../api/error.mjs').AstryxError} */ (
270
286
  e
271
287
  );
272
- return cliError(err.message, {
273
- suggestions: err.suggestions,
288
+ // Suggested commands start the way this project runs the CLI, in JSON
289
+ // as in text. Echoed user text never drives the terminal: control
290
+ // characters print as escapes.
291
+ return cliError(escapeControls(err.message), {
292
+ suggestions: err.suggestions?.map(x => ({
293
+ ...x,
294
+ name: escapeControls(cmd(x.name)),
295
+ })),
274
296
  code: err.code ?? ERROR_CODES.ERR_UNKNOWN,
275
297
  });
276
298
  }
@@ -281,7 +303,20 @@ async function run(program, call, render, answer) {
281
303
  jsonOut(/** @type {any} */ (result));
282
304
  return answered;
283
305
  }
284
- print([...notCheckedLine(result), ...render(result)]);
306
+ // --detail compact|brief (and --dense) print a change's status line
307
+ // alone; an answer (how, show, list) is the answer, and prints whole.
308
+ const o = program.opts();
309
+ const change = ['themeEdit.set', 'themeEdit.undo', 'themeEdit.new'].includes(
310
+ /** @type {any} */ (result)?.type,
311
+ );
312
+ const short =
313
+ change &&
314
+ (o.detail === 'compact' ||
315
+ o.detail === 'brief' ||
316
+ o.dense ||
317
+ o.lang === 'dense');
318
+ const lines = [...notCheckedLine(result), ...render(result)];
319
+ print(short ? lines.slice(0, notCheckedLine(result).length + 1) : lines);
285
320
  return answered;
286
321
  }
287
322
 
@@ -434,53 +469,52 @@ function lookupBlocks(d) {
434
469
  /** @param {string[]} cmds @param {boolean} [sequence] */
435
470
  const commandLines = (cmds, sequence) =>
436
471
  sequence && cmds.length > 1
437
- ? [` ${cmds.join(' && ')}`, ' sequence: run as one line, in this order']
438
- : cmds.map(c => ` ${c}`);
439
- /** @param {Array<{command: string, why: string}>} list */
440
- const refusedLines = list =>
441
- list.flatMap(r => [` x ${r.command}`, ` not run: ${r.why}`]);
472
+ ? [cmds.join(' && '), 'sequence: run as one line, in this order']
473
+ : cmds;
474
+ /** @param {Array<{command: string, why: string}>} refusedList */
475
+ const refusedLines = refusedList =>
476
+ refusedList.flatMap(r => [`x ${r.command}`, ` not run: ${r.why}`]);
442
477
  /** @type {Array<string | import('../../formatters/index.mjs').Block>} */
443
478
  const blocks = [...(hint ? [String(hint)] : []), ...project(rest)];
444
479
  if (Array.isArray(results) && results.length)
445
480
  blocks.push(
446
481
  section('results:'),
447
- text(
448
- results
449
- .flatMap((/** @type {any} */ r) => [
450
- String(r.text),
451
- ...commandLines(r.commands ?? [], r.sequence),
452
- ...refusedLines(r.refused ?? []),
453
- ])
454
- .join('\n'),
482
+ list(
483
+ results.map((/** @type {any} */ r) => [
484
+ String(r.text),
485
+ ...commandLines(r.commands ?? [], r.sequence),
486
+ ...refusedLines(r.refused ?? []),
487
+ ]),
455
488
  ),
456
489
  );
457
490
  if (Array.isArray(examples) && examples.length)
458
- blocks.push(section('examples:'), text(commandLines(examples).join('\n')));
491
+ blocks.push(section('examples:'), list(commandLines(examples)));
459
492
  if (Array.isArray(refused) && refused.length)
460
- blocks.push(section('refused:'), text(refusedLines(refused).join('\n')));
493
+ blocks.push(
494
+ section('refused:'),
495
+ list(refused.map((/** @type {any} */ r) => refusedLines([r]))),
496
+ );
461
497
  if (Array.isArray(points) && points.length)
462
498
  blocks.push(
463
499
  section('points:'),
464
- text(
465
- points
466
- .map(
467
- (/** @type {any} */ x) => ` ${x.at} ${x.color} alpha ${x.alpha}`,
468
- )
469
- .join('\n'),
500
+ records(
501
+ points.map((/** @type {any} */ x) => ({
502
+ at: x.at,
503
+ color: x.color,
504
+ alpha: x.alpha,
505
+ })),
470
506
  ),
471
507
  );
472
508
  if (Array.isArray(items) && items.length) {
473
509
  if (items.some((/** @type {any} */ x) => Array.isArray(x.examples)))
474
510
  blocks.push(
475
511
  section('items:'),
476
- text(
477
- items
478
- .flatMap((/** @type {any} */ x) => [
479
- `${x.name} ${x.values}`,
480
- ` help: ${x.help}`,
481
- ...commandLines(x.examples),
482
- ])
483
- .join('\n'),
512
+ list(
513
+ items.map((/** @type {any} */ x) => [
514
+ `${x.name} ${x.values}`,
515
+ `help: ${x.help}`,
516
+ ...commandLines(x.examples),
517
+ ]),
484
518
  ),
485
519
  );
486
520
  else blocks.push(...project({items}).slice(1));
@@ -508,7 +542,7 @@ function strayOption(command, rest) {
508
542
  {
509
543
  suggestions: [
510
544
  {
511
- name: `${EDITOR} ${command} --help`,
545
+ name: cmd(`${EDITOR} ${command} --help`),
512
546
  reason: 'every option it takes',
513
547
  },
514
548
  ],
@@ -522,7 +556,10 @@ function strayOption(command, rest) {
522
556
  `unknown option '${word}': only the thing a change names may start with -- (a design token such as --color-accent).`,
523
557
  {
524
558
  suggestions: [
525
- {name: `${EDITOR} ${command} --help`, reason: 'every option it takes'},
559
+ {
560
+ name: cmd(`${EDITOR} ${command} --help`),
561
+ reason: 'every option it takes',
562
+ },
526
563
  ],
527
564
  code: ERROR_CODES.ERR_INVALID_OPTION,
528
565
  },
@@ -539,7 +576,7 @@ function extraWords(command, extra) {
539
576
  if (!extra.length) return null;
540
577
  return cliError(`${command} does not take "${extra.join(' ')}".`, {
541
578
  suggestions: [
542
- {name: `${EDITOR} ${command} --help`, reason: 'what it takes'},
579
+ {name: cmd(`${EDITOR} ${command} --help`), reason: 'what it takes'},
543
580
  ],
544
581
  code: ERROR_CODES.ERR_INVALID_ARGUMENT,
545
582
  });
@@ -561,9 +598,28 @@ function explained(c, doc, {tokens = false} = {}) {
561
598
  return c;
562
599
  }
563
600
 
601
+ /** Old and sibling names, and where each now is. */
602
+ const MOVED = /** @type {Record<string, Record<string, string>>} */ ({
603
+ theme: {
604
+ build: 'compile',
605
+ set: 'editor set',
606
+ undo: 'editor undo',
607
+ show: 'editor show',
608
+ new: 'editor new',
609
+ how: 'editor how',
610
+ explain: 'editor how',
611
+ reset: 'editor undo',
612
+ palette: 'editor set',
613
+ help: '--help',
614
+ },
615
+ editor: {explain: 'how', reset: 'undo', help: '--help', palette: 'set'},
616
+ preview: {help: '--help'},
617
+ });
618
+
564
619
  /**
565
- * A command group: bare, it prints its help; with an unknown word, the
566
- * unknown-subcommand error with every subcommand as a suggestion.
620
+ * A command group: bare, it prints its help (in JSON too, as the root
621
+ * does); with an unknown word, the unknown-subcommand error, leading with
622
+ * where a moved name now is, then the nearest subcommands.
567
623
  * @param {import('commander').Command} parent
568
624
  * @param {import('@astryxdesign/cli/authoring').CommandDoc} doc
569
625
  * @returns {import('commander').Command}
@@ -576,18 +632,55 @@ function defineGroup(parent, doc) {
576
632
  /** @type {import('commander').Command} */ c,
577
633
  ) => {
578
634
  const extras = c?.args ?? [];
635
+ const words = [];
636
+ for (let x = cmd; x && x.parent; x = x.parent) words.unshift(x.name());
637
+ const here = `${getCliInvocation()} ${words.join(' ')}`;
579
638
  if (extras.length > 0) {
639
+ const word = String(extras[0]).toLowerCase();
640
+ const group = doc.name.split(' ').at(-1) ?? '';
641
+ const moved =
642
+ MOVED[group]?.[word] ??
643
+ // `preview <theme>`: the pages for a theme.
644
+ (group === 'preview' && /^[a-z][a-z0-9-]*$/.test(word)
645
+ ? `add --theme ${word}`
646
+ : null);
647
+ const ranked = (cmd.commands ?? [])
648
+ .map(command => command.name())
649
+ .sort(
650
+ (a, b) =>
651
+ levenshteinDistance(word, a) - levenshteinDistance(word, b),
652
+ );
580
653
  return cliError(
581
- `unknown subcommand '${doc.name} ${String(extras[0])}'`,
654
+ `unknown subcommand '${doc.name} ${String(extras[0])}'${moved ? `; it is ${here} ${moved}` : ''}`,
582
655
  {
583
- suggestions: (cmd.commands ?? []).map(command => ({
584
- name: command.name(),
585
- reason: 'available subcommand',
586
- })),
656
+ suggestions: [
657
+ ...(moved
658
+ ? [{name: `${here} ${moved}`, reason: 'do this instead'}]
659
+ : []),
660
+ ...ranked.map(name => ({
661
+ name: `${here} ${name}`,
662
+ reason: 'available subcommand',
663
+ })),
664
+ ],
587
665
  code: ERROR_CODES.ERR_UNKNOWN_SUBCOMMAND,
588
666
  },
589
667
  );
590
668
  }
669
+ if (c?.optsWithGlobals?.().json) {
670
+ jsonOut(
671
+ /** @type {any} */ ({
672
+ type: 'help',
673
+ data: {
674
+ command: words.join(' '),
675
+ commands: (cmd.commands ?? []).map(command => ({
676
+ name: command.name(),
677
+ summary: command.summary() || command.description(),
678
+ })),
679
+ },
680
+ }),
681
+ );
682
+ return NO_RESULT_SET;
683
+ }
591
684
  cmd.help();
592
685
  return NO_RESULT_SET;
593
686
  },
@@ -630,14 +723,26 @@ export function registerExperimentalTheme(group, program) {
630
723
  if (extra.length)
631
724
  throw new AstryxError(
632
725
  `new takes one theme name; "${extra.join(' ')}" is extra. For a base theme, use --like. Nothing was changed.`,
633
- /^[a-z][a-z0-9-]*$/.test(extra[0])
726
+ // A built-in theme after the name is the base; other words
727
+ // were most likely part of the name.
728
+ builtInThemes().includes(extra[0])
634
729
  ? [
635
730
  {
636
731
  name: `${EDITOR} new ${name} --like ${extra[0]}`,
637
732
  reason: 'do this instead',
638
733
  },
639
734
  ]
640
- : [],
735
+ : [
736
+ {
737
+ name: `${EDITOR} new ${quoteCommandArgument(
738
+ [name, ...extra]
739
+ .join('-')
740
+ .toLowerCase()
741
+ .replace(/[^a-z0-9-]+/g, '-'),
742
+ )}`,
743
+ reason: 'do this instead',
744
+ },
745
+ ],
641
746
  ERROR_CODES.ERR_INVALID_ARGUMENT,
642
747
  );
643
748
  return themeEditNew(name, {
@@ -686,6 +791,22 @@ export function registerExperimentalTheme(group, program) {
686
791
  /** @type {any} */ c,
687
792
  ) =>
688
793
  extraWords('show', (c?.args ?? []).slice(1)) ??
794
+ // The sheet is limited to one section (the docs say so): a second
795
+ // --section is refused, never kept over the first in silence.
796
+ (new Set(flagValues('section')).size > 1
797
+ ? cliError(
798
+ `--section limits the sheet to one section, and was given ${flagValues('section').length} (${flagValues('section').join(', ')}); give one, or none for the whole sheet.`,
799
+ {
800
+ suggestions: [
801
+ {
802
+ name: `${EDITOR} show ${name} --section ${flagValues('section')[0]}`,
803
+ reason: 'do this instead',
804
+ },
805
+ ],
806
+ code: ERROR_CODES.ERR_INVALID_ARGUMENT,
807
+ },
808
+ )
809
+ : null) ??
689
810
  run(
690
811
  program,
691
812
  () =>
@@ -807,6 +928,25 @@ export function registerExperimentalTheme(group, program) {
807
928
  }).allowExcessArguments(false),
808
929
  previewAppDoc,
809
930
  );
931
+ {
932
+ // A folder name that starts with "-" reads as an option: say how to
933
+ // pass it.
934
+ const app = /** @type {any} */ (
935
+ preview.commands.find(
936
+ (/** @type {any} */ x) =>
937
+ x.name() === previewAppDoc.name.split(' ').pop(),
938
+ )
939
+ );
940
+ const unknown = app?.unknownOption?.bind(app);
941
+ if (app && unknown)
942
+ app.unknownOption = (/** @type {string} */ flag) =>
943
+ /^-[^-]/.test(flag) && flag.length > 2
944
+ ? app.error(
945
+ `error: unknown option '${flag}'. A folder name that starts with "-" goes after --: ${PREFIX} preview app -- ${flag}`,
946
+ {code: 'commander.unknownOption'},
947
+ )
948
+ : unknown(flag);
949
+ }
810
950
 
811
951
  explained(
812
952
  defineCommand(preview, previewListDoc, {
@@ -820,7 +960,7 @@ export function registerExperimentalTheme(group, program) {
820
960
  ? project(/** @type {any} */ (r.data))
821
961
  : [
822
962
  ...project(/** @type {any} */ (r.data)),
823
- `Tip: ${PREFIX} preview add${o.path == null ? '' : ` --path '${String(o.path).replace(/'/g, `'\\''`)}'`}`,
963
+ `Tip: ${PREFIX} preview add${o.path == null ? '' : ` --path ${quoteCommandArgument(String(o.path))}`}`,
824
964
  ],
825
965
  r =>
826
966
  resultSet({
@@ -933,46 +1073,19 @@ export function registerExperimentalTheme(group, program) {
933
1073
  },
934
1074
  );
935
1075
  }
936
- // A picture first: the only other word is how many colors to list.
937
- const picture = isHowPicture(rest[0] ?? '');
938
- if (picture && rest.length > 2)
939
- return cliError(
940
- `After a picture, give only how many colors to list, not "${rest.slice(1).join(' ')}".`,
941
- {
942
- suggestions: [
943
- {name: `${HOW} ${rest[0]} 5`, reason: 'do this instead'},
944
- ],
945
- code: ERROR_CODES.ERR_INVALID_ARGUMENT,
946
- },
947
- );
948
- // A missing picture is the first thing to say, before a bad count.
949
- if (
950
- picture &&
951
- rest.length === 2 &&
952
- !/^[1-9]\d*$/.test(rest[1]) &&
953
- fileExists(rest[0])
954
- )
955
- return cliError(
956
- `The count after a picture must be a positive whole number, not "${rest[1]}".`,
957
- {
958
- suggestions: [
959
- {name: `${HOW} ${rest[0]} 5`, reason: 'do this instead'},
960
- ],
961
- code: ERROR_CODES.ERR_INVALID_ARGUMENT,
962
- },
963
- );
1076
+ // The API decides what the words are (a picture and a count, or a
1077
+ // question); a picture is told by its extension here only to keep
1078
+ // option words after it for the count.
1079
+ const picture = /\.png$/i.test(rest[0] ?? '');
964
1080
  const stray = picture ? null : strayOption('how', rest.slice(1));
965
1081
  if (stray) return stray;
966
- const count =
967
- picture && rest.length === 2 ? Number(rest[1]) : undefined;
968
- const subject = picture ? rest[0] : rest.join(' ');
969
1082
  return run(
970
1083
  program,
971
1084
  () =>
972
- themeEditHow(subject, {
1085
+ themeEditHow(rest.join(' '), {
973
1086
  cwd: process.cwd(),
974
1087
  at: o.at ?? [],
975
- count,
1088
+ words: rest,
976
1089
  theme: o.theme,
977
1090
  }),
978
1091
  r => lookupBlocks(/** @type {any} */ (r.data)),
@@ -1006,6 +1119,12 @@ export function registerExperimentalTheme(group, program) {
1006
1119
  template: templateDoc,
1007
1120
  targets: targetsDoc,
1008
1121
  },
1009
- {group: 'experimental theme', build: 'compile'},
1122
+ {
1123
+ group: 'experimental theme',
1124
+ build: 'compile',
1125
+ explain: editorThemeRefusal,
1126
+ preflight: editorCompileProblem,
1127
+ hold: editorThemeHold,
1128
+ },
1010
1129
  );
1011
1130
  }
@@ -39,7 +39,7 @@ export const doc = {
39
39
  flag: '-o, --out <path>',
40
40
  param: 'options.out',
41
41
  description:
42
- 'Output CSS file path, relative or absolute; the .js and .d.ts are written beside it (default: <theme name>.css next to the source). A build writes only inside the working directory, the defaults beside the source too (ERR_PATH_TRAVERSAL); --check writes nothing, so it compares outputs anywhere and refuses only a relative path that escapes the working directory. Single theme only: refused with more than one file or with --family (ERR_THEME_INVALID)',
42
+ 'Output CSS file path, relative or absolute; the .js and .d.ts are written beside it (default: <theme name>.css next to the source). A folder, or a path ending in /, writes <theme name>.css into it. A build never replaces the theme source (ERR_THEME_INVALID). At a path --out names, it replaces only its own earlier outputs: any other existing file fails with ERR_FILE_EXISTS and nothing is written. A build writes only inside the working directory, the defaults beside the source too (ERR_PATH_TRAVERSAL); --check writes nothing, so it compares outputs anywhere and refuses only a relative path that escapes the working directory. Single theme only: refused with more than one file or with --family (ERR_THEME_INVALID)',
43
43
  },
44
44
  {
45
45
  flag: '--icons-specifier <specifier>',
@@ -50,7 +50,7 @@ export const doc = {
50
50
  {
51
51
  flag: '-w, --watch',
52
52
  description:
53
- 'Rebuild automatically when a theme file changes (Ctrl-C to stop). Refused with --check, --family, or --json (ERR_THEME_INVALID)',
53
+ 'Rebuild automatically when the theme source, or a local file it imports, changes (Ctrl-C to stop). Refused with --check, --family, or --json (ERR_THEME_INVALID)',
54
54
  },
55
55
  {
56
56
  flag: '-c, --check',
@@ -89,7 +89,7 @@ export const doc = {
89
89
  },
90
90
  {
91
91
  code: 1,
92
- when: 'a build or validation error, or --check finds stale or missing outputs',
92
+ when: 'a build or validation error (an error envelope), or --check finds stale or missing outputs (the check result, with upToDate false and the stale files, is still printed: it is a result, not an error). One exception: an editor theme whose settings changed after its build is refused (ERR_THEME_INVALID, an error envelope) before any file is checked, with `editor show <theme>` to build it again',
93
93
  },
94
94
  ],
95
95
  related: ['experimental theme add', 'experimental theme list'],