@astryxdesign/cli 0.7.14 → 0.7.15-canary.g061b2fa

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 (164) hide show
  1. package/README.md +63 -63
  2. package/api/build/_adapter.d.mts +4 -0
  3. package/api/build/_adapter.mjs +28 -2
  4. package/api/build/blocks/blocks.d.mts +10 -1
  5. package/api/build/blocks/blocks.mjs +84 -7
  6. package/api/build/build.mjs +6 -1
  7. package/api/build/tree.d.mts +4 -0
  8. package/api/build/tree.mjs +9 -2
  9. package/api/doctor/_adapter.d.mts +3 -1
  10. package/api/doctor/_adapter.mjs +14 -1
  11. package/api/doctor/_authoring-audit.d.mts +42 -0
  12. package/api/doctor/_authoring-audit.mjs +106 -0
  13. package/api/doctor/doctor.d.mts +7 -0
  14. package/api/doctor/doctor.mjs +24 -39
  15. package/api/doctor/theme-checks.mjs +56 -21
  16. package/api/integration/validate-integration.mjs +17 -3
  17. package/api/integration/validateIntegration.doc.mjs +1 -1
  18. package/api/search/_adapter.mjs +124 -3
  19. package/api/search/_candidate-score.mjs +63 -9
  20. package/api/search/_entries.d.mts +10 -0
  21. package/api/search/_entries.mjs +68 -1
  22. package/api/search/_gather-templates.d.mts +11 -0
  23. package/api/search/_gather-templates.mjs +22 -2
  24. package/api/search/_words.mjs +26 -6
  25. package/api/swizzle/copy/copy.mjs +1 -1
  26. package/api/theme/_adapter.d.mts +17 -1
  27. package/api/theme/_adapter.mjs +185 -40
  28. package/api/theme/build/build.d.mts +29 -1
  29. package/api/theme/build/build.mjs +426 -65
  30. package/api/theme/eject/eject.mjs +10 -6
  31. package/api/theme/targets/targets.d.mts +8 -0
  32. package/api/theme/targets/targets.mjs +24 -4
  33. package/api/theme/template/template.mjs +48 -2
  34. package/api/theme/theme.type.d.mts +8 -0
  35. package/api/theme/theme.type.mjs +5 -1
  36. package/api/theme/themeBuild.doc.mjs +7 -4
  37. package/api/theme/themeEject.doc.mjs +3 -3
  38. package/api/theme/themeRemove.doc.mjs +5 -2
  39. package/api/theme/themeTargets.doc.mjs +1 -1
  40. package/api/theme/themeTemplate.doc.mjs +2 -2
  41. package/api/theme/themeUse.doc.mjs +8 -2
  42. package/api/theme-edit/_adapter.d.mts +46 -3
  43. package/api/theme-edit/_adapter.mjs +372 -109
  44. package/api/theme-edit/_check.d.mts +6 -3
  45. package/api/theme-edit/_check.mjs +665 -87
  46. package/api/theme-edit/_color.mjs +4 -2
  47. package/api/theme-edit/_compiler.d.mts +2 -1
  48. package/api/theme-edit/_compiler.mjs +27 -13
  49. package/api/theme-edit/_context.d.mts +2 -1
  50. package/api/theme-edit/_context.mjs +47 -8
  51. package/api/theme-edit/_edit.d.mts +9 -3
  52. package/api/theme-edit/_edit.mjs +484 -66
  53. package/api/theme-edit/_how-commands.d.mts +33 -7
  54. package/api/theme-edit/_how-commands.mjs +57 -45
  55. package/api/theme-edit/_how-question.d.mts +4 -0
  56. package/api/theme-edit/_how-question.mjs +1004 -223
  57. package/api/theme-edit/_how.mjs +96 -9
  58. package/api/theme-edit/_palette.d.mts +38 -13
  59. package/api/theme-edit/_palette.mjs +620 -223
  60. package/api/theme-edit/_parts.mjs +63 -7
  61. package/api/theme-edit/_png.d.mts +4 -4
  62. package/api/theme-edit/_png.mjs +4 -2
  63. package/api/theme-edit/_preview-app.d.mts +6 -0
  64. package/api/theme-edit/_preview-app.mjs +1194 -207
  65. package/api/theme-edit/_preview.mjs +2 -2
  66. package/api/theme-edit/_project.d.mts +12 -1
  67. package/api/theme-edit/_project.mjs +37 -6
  68. package/api/theme-edit/_settings.d.mts +104 -33
  69. package/api/theme-edit/_settings.mjs +818 -118
  70. package/api/theme-edit/_tables.d.mts +7 -0
  71. package/api/theme-edit/_tables.mjs +61 -0
  72. package/api/theme-edit/theme-edit.type.d.mts +11 -1
  73. package/api/theme-edit/theme-edit.type.mjs +4 -3
  74. package/api/theme-edit/themeEditHow.doc.mjs +6 -0
  75. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  76. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  77. package/api/theme-edit/themeEditPreviewList.doc.mjs +1 -1
  78. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
  79. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  80. package/api/upgrade/_adapter.d.mts +1 -0
  81. package/assets/codemods/run-codemod.mjs +61 -0
  82. package/assets/codemods/runner.mjs +5 -4
  83. package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
  84. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
  85. package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
  86. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
  87. package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
  88. package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
  89. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
  90. package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
  91. package/assets/docs/tree/calendars.doc.mjs +1 -3
  92. package/assets/docs/tree/checks.doc.mjs +22 -1
  93. package/assets/docs.generated.json +2 -1
  94. package/assets/self-audit.generated.json +1 -0
  95. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
  96. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
  97. package/assets/templates/components.generated.json +1 -1
  98. package/authoring/integration/integration.doc.mjs +8 -0
  99. package/authoring/integration/schema.d.mts +8 -0
  100. package/authoring/integration/schema.mjs +1 -0
  101. package/authoring/integration/type.ts +9 -0
  102. package/clients/cli/bin/astryx.mjs +19 -15
  103. package/clients/cli/build-id.generated.json +1 -0
  104. package/clients/cli/commands/ensure-core-built.mjs +12 -5
  105. package/clients/cli/commands/experimental/theme.mjs +178 -78
  106. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  107. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
  108. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
  109. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  110. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  111. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  112. package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
  113. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  114. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  115. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
  116. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
  117. package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
  118. package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
  119. package/clients/cli/commands/manifest.mjs +5 -2
  120. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  121. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  122. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  123. package/clients/cli/commands/theme.mjs +374 -42
  124. package/clients/cli/index.mjs +9 -3
  125. package/clients/cli/lib/manifest.mjs +37 -0
  126. package/clients/cli/lib/resolve-theme.mjs +2 -1
  127. package/clients/cli/manifest.generated.json +1 -0
  128. package/foundation/config/theme-state.d.mts +16 -0
  129. package/foundation/config/theme-state.mjs +84 -13
  130. package/foundation/discovery/module-exports.mjs +16 -2
  131. package/foundation/discovery/stored-self-audit.d.mts +31 -0
  132. package/foundation/discovery/stored-self-audit.mjs +119 -0
  133. package/foundation/discovery/template-adapter.d.mts +48 -2
  134. package/foundation/discovery/template-adapter.mjs +51 -19
  135. package/foundation/discovery/template-needs.d.mts +19 -0
  136. package/foundation/discovery/template-needs.mjs +50 -16
  137. package/foundation/discovery/template-source-tree.d.mts +7 -0
  138. package/foundation/discovery/template-source-tree.mjs +15 -0
  139. package/foundation/discovery/theme-discovery.d.mts +2 -1
  140. package/foundation/discovery/theme-discovery.mjs +2 -8
  141. package/foundation/discovery/theme-module-extensions.d.mts +18 -0
  142. package/foundation/discovery/theme-module-extensions.mjs +30 -0
  143. package/foundation/doc-compiler/import.mjs +22 -15
  144. package/foundation/doc-compiler/stored-docs.d.mts +18 -12
  145. package/foundation/doc-compiler/stored-docs.mjs +52 -19
  146. package/foundation/env/private-dir.d.mts +17 -0
  147. package/foundation/env/private-dir.mjs +42 -0
  148. package/foundation/fs/gather-cache.d.mts +108 -0
  149. package/foundation/fs/gather-cache.mjs +741 -0
  150. package/foundation/fs/jiti-cache.d.mts +21 -0
  151. package/foundation/fs/jiti-cache.mjs +66 -0
  152. package/foundation/fs/module-loader.mjs +14 -3
  153. package/foundation/fs/read-record.d.mts +31 -1
  154. package/foundation/fs/read-record.mjs +100 -7
  155. package/foundation/integrations/integrations.d.mts +8 -0
  156. package/foundation/integrations/integrations.mjs +4 -0
  157. package/foundation/integrations/validate-contributions.d.mts +62 -1
  158. package/foundation/integrations/validate-contributions.mjs +476 -40
  159. package/foundation/release/cache.d.mts +11 -2
  160. package/foundation/release/cache.mjs +59 -10
  161. package/foundation/release/folder-lock.d.mts +21 -0
  162. package/foundation/release/folder-lock.mjs +171 -0
  163. package/foundation/response/response-types.doc.mjs +1 -1
  164. package/package.json +8 -6
@@ -33,7 +33,10 @@ import * as fs from 'node:fs';
33
33
  import * as path from 'node:path';
34
34
  import {fileURLToPath} from 'node:url';
35
35
  import {spawn} from 'node:child_process';
36
- import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
36
+ import {
37
+ getCliInvocation,
38
+ quoteCommandArgument,
39
+ } from '../../../foundation/env/package-manager.mjs';
37
40
  import {isOutsideProject} from '../../../foundation/env/project-scope.mjs';
38
41
  import {jsonOut} from '../../../foundation/response/json.mjs';
39
42
  import {
@@ -59,7 +62,10 @@ import {
59
62
  themeListAvailable,
60
63
  themeListCopySources,
61
64
  } from '../../../api/theme/list/list.mjs';
62
- import {themeTargets} from '../../../api/theme/targets/targets.mjs';
65
+ import {
66
+ normalizeTargetFilter,
67
+ themeTargets,
68
+ } from '../../../api/theme/targets/targets.mjs';
63
69
  import {
64
70
  serializePaletteCandidate,
65
71
  themePaletteGenerate,
@@ -70,6 +76,8 @@ import {
70
76
  themeBuild,
71
77
  themeBuildFamily,
72
78
  themeBuildForReport,
79
+ themeSourceGuesses,
80
+ writeDeferredBuildOutputs,
73
81
  } from '../../../api/theme/build/build.mjs';
74
82
  import {defineCommand} from '../lib/define-command.mjs';
75
83
  import {NO_RESULT_SET, resultSet} from '../../../foundation/debug/index.mjs';
@@ -101,29 +109,89 @@ import {doc as themePaletteGenerateFn} from '../../../api/theme/themePaletteGene
101
109
  * @typedef {object} ThemeCommandWords
102
110
  * @property {string} group - The group's command path: `theme` or `experimental theme`.
103
111
  * @property {string} build - The build subcommand's name: `build` or `compile`.
112
+ * @property {(err: import('../../../api/error.mjs').AstryxError, cwd: string) => import('../../../api/error.mjs').AstryxError | null} [explain] - A clearer refusal for this group, or null.
113
+ * @property {(files: string[], options: {cwd: string, check?: boolean, family?: boolean}) => Promise<import('../../../api/error.mjs').AstryxError | null>} [preflight] - A refusal before a build starts, or null.
114
+ * @property {(files: string[], options: {cwd: string}) => Promise<() => Promise<void>>} [hold] - Locks held while a build or check runs; resolves to their release.
104
115
  */
105
116
 
106
117
  /** @type {ThemeCommandWords} */
107
118
  const THEME_WORDS = {group: 'theme', build: 'build'};
108
119
 
120
+ /**
121
+ * Text as the group that ran the command words it: under `experimental
122
+ * theme`, the commands it names are that group's own (`build` is `compile`
123
+ * there). Only a command the CLI wrote is reworded: one after the CLI's
124
+ * name, or in backticks; text a person typed (a path, a name) stays as
125
+ * typed. Under `theme`, the text is unchanged.
126
+ * @param {string} text
127
+ * @param {ThemeCommandWords} words
128
+ */
129
+ function inGroupWords(text, words) {
130
+ if (words.group === THEME_WORDS.group) return text;
131
+ // An argument the person typed can hold the same words (a filter of
132
+ // `astryx theme list`); it is echoed as typed. Only an argument with a
133
+ // space or a backtick can match, and it is set aside only where the CLI
134
+ // echoes it: in double quotes, or as the argument after a subcommand.
135
+ const typed = [...new Set(process.argv.slice(2))]
136
+ .filter(arg => /[\s`]/.test(arg))
137
+ .sort((a, b) => b.length - a.length);
138
+ /** @type {string[]} */
139
+ const kept = [];
140
+ let masked = String(text);
141
+ for (const arg of typed) {
142
+ const escaped = arg.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
143
+ masked = masked.replace(
144
+ new RegExp(
145
+ `(?<="|\\b(?:add|use|remove|eject|targets|template|build|compile) )${escaped}(?="|\`|\\s|$)`,
146
+ 'g',
147
+ ),
148
+ () => `\uE000${kept.push(arg) - 1}\uE001`,
149
+ );
150
+ }
151
+ return masked
152
+ .replace(
153
+ /((?:\bastryx|@astryxdesign\/cli@[\w.-]+) |`)theme (add|use|remove|list|build|eject|template|targets)\b/g,
154
+ (_, lead, sub) =>
155
+ `${lead}${words.group} ${sub === 'build' ? words.build : sub}`,
156
+ )
157
+ .replace(/\uE000(\d+)\uE001/g, (_, i) => kept[Number(i)]);
158
+ }
159
+
160
+ /**
161
+ * A theme app result with its notes in the words of the group that ran it.
162
+ * @template {{data: {notes?: string[]}}} R
163
+ * @param {R} result
164
+ * @param {ThemeCommandWords} words
165
+ * @returns {R}
166
+ */
167
+ function inGroupNotes(result, words) {
168
+ if (!result?.data?.notes || words.group === THEME_WORDS.group) return result;
169
+ return {
170
+ ...result,
171
+ data: {
172
+ ...result.data,
173
+ notes: result.data.notes.map(n => inGroupWords(n, words)),
174
+ },
175
+ };
176
+ }
177
+
109
178
  /**
110
179
  * A theme API refusal as the group that ran it words it: under
111
180
  * `experimental theme`, the commands it names are that group's own (`build`
112
181
  * is `compile` there). Under `theme`, the text is unchanged.
182
+ * A refusal that names no command gets `fallback`: a command of the same
183
+ * group that works whatever went wrong.
113
184
  * @param {import('../../../api/error.mjs').AstryxError} err
114
185
  * @param {ThemeCommandWords} [words]
186
+ * @param {Array<{name: string, reason: string}>} [fallback]
115
187
  */
116
- function themeError(err, words = THEME_WORDS) {
188
+ function themeError(err, words = THEME_WORDS, fallback = []) {
189
+ err = words.explain?.(err, process.cwd()) ?? err;
117
190
  /** @param {string} text */
118
- const local = text =>
119
- words.group === THEME_WORDS.group
120
- ? text
121
- : text.replace(
122
- /(?<!experimental )\btheme (add|use|remove|list|build|eject|template|targets)\b/g,
123
- (_, sub) => `${words.group} ${sub === 'build' ? words.build : sub}`,
124
- );
191
+ const local = text => inGroupWords(text, words);
192
+ const given = err.suggestions || [];
125
193
  return cliError(local(err.message), {
126
- suggestions: (err.suggestions || []).map(x => ({
194
+ suggestions: (given.length > 0 ? given : fallback).map(x => ({
127
195
  ...x,
128
196
  name: local(x.name),
129
197
  ...(x.reason ? {reason: local(x.reason)} : {}),
@@ -132,6 +200,27 @@ function themeError(err, words = THEME_WORDS) {
132
200
  });
133
201
  }
134
202
 
203
+ /**
204
+ * A command of this CLI as this project runs it, each argument quoted for the
205
+ * shell.
206
+ * @param {ThemeCommandWords} words
207
+ * @param {string} sub the subcommand, such as `list` or the build word
208
+ * @param {string[]} [args]
209
+ * @param {string} reason
210
+ * @returns {{name: string, reason: string}}
211
+ */
212
+ function themeCommand(words, sub, args = [], reason = '') {
213
+ return {
214
+ name: [
215
+ getCliInvocation(process.cwd()),
216
+ words.group,
217
+ sub,
218
+ ...args.map(arg => quoteCommandArgument(arg)),
219
+ ].join(' '),
220
+ reason,
221
+ };
222
+ }
223
+
135
224
  /**
136
225
  * Path to this CLI's real entry (clients/cli/bin/astryx.mjs), resolved from
137
226
  * this module's location (clients/cli/commands/theme.mjs → ../bin/
@@ -518,7 +607,7 @@ function printThemeEject(result, words = THEME_WORDS) {
518
607
  ]
519
608
  : []),
520
609
  text(
521
- `This is a local fork. Build it with ${getCliInvocation()} ${words.group} ${words.build} ${path.join(data.outputDir, data.entry)}.`,
610
+ `This is a local fork. Build it with ${getCliInvocation()} ${words.group} ${words.build} ${quoteCommandArgument(path.join(data.outputDir, data.entry).split(path.sep).join('/'))}.`,
522
611
  ),
523
612
  );
524
613
  }
@@ -730,7 +819,7 @@ function registerPaletteCommands(
730
819
  * @param {ThemeCommandWords} words
731
820
  */
732
821
  function registerThemeCommands(theme, program, docs, words) {
733
- defineCommand(theme, docs.build, {
822
+ const buildCli = defineCommand(theme, docs.build, {
734
823
  fn: themeBuildFn,
735
824
  action: async (
736
825
  /** @type {string[]} */ files,
@@ -754,28 +843,98 @@ function registerThemeCommands(theme, program, docs, words) {
754
843
  // A quoted glob reaches us unexpanded: say so rather than reporting a
755
844
  // literal `themes/*.ts` as a missing file.
756
845
  const looksGlobby = /[*?[\]{}]/.test(entry.file);
846
+ const guesses = looksGlobby
847
+ ? []
848
+ : themeSourceGuesses(entry.file, process.cwd());
757
849
  return cliError(`File not found: ${entry.filePath}`, {
758
850
  code: ERROR_CODES.ERR_FILE_NOT_FOUND,
759
851
  suggestions: looksGlobby
760
852
  ? [
761
853
  {
762
- name: `astryx ${words.group} ${words.build} ${entry.file.replace(/['"]/g, '')}`,
854
+ // The pattern stays unquoted: the shell expands it.
855
+ name: `${getCliInvocation(process.cwd())} ${words.group} ${words.build} ${entry.file.replace(/['"]/g, '')}`,
763
856
  reason:
764
857
  'globs are expanded by your shell; pass the pattern unquoted, or list the files',
765
858
  },
766
859
  ]
767
- : undefined,
860
+ : guesses.length > 0
861
+ ? guesses.map(guess => ({
862
+ name: `${getCliInvocation(process.cwd())} ${words.group} ${words.build} ${quoteCommandArgument(guess)}`,
863
+ reason: 'a theme source that exists',
864
+ }))
865
+ : [
866
+ themeCommand(
867
+ words,
868
+ 'template',
869
+ ['theme.template.ts'],
870
+ 'start a theme source from the annotated template',
871
+ ),
872
+ ],
768
873
  });
769
874
  }
770
875
 
876
+ /**
877
+ * This build again without some of its options, as the way out of a
878
+ * refusal about how they combine.
879
+ * @param {Array<'out' | 'watch' | 'check' | 'family'>} drop
880
+ * @param {string} reason
881
+ * @param {string[]} [only] the files to build, when not all of them
882
+ */
883
+ const buildWithout = (drop, reason, only = files) =>
884
+ themeCommand(
885
+ words,
886
+ words.build,
887
+ [
888
+ ...(options.family && !drop.includes('family')
889
+ ? ['--family', ...only, '--family-key', String(options.familyKey)]
890
+ : only),
891
+ ...(options.out && !drop.includes('out')
892
+ ? ['--out', options.out]
893
+ : []),
894
+ ...(options.check && !drop.includes('check') ? ['--check'] : []),
895
+ ...(options.watch && !drop.includes('watch') ? ['--watch'] : []),
896
+ ...(options.iconsSpecifier
897
+ ? ['--icons-specifier', options.iconsSpecifier]
898
+ : []),
899
+ ],
900
+ reason,
901
+ );
902
+
903
+ // A refusal from the build that names no command: without --out the
904
+ // outputs go beside the source; otherwise the annotated template shows
905
+ // a theme source that builds.
906
+ const buildFallback = options.out
907
+ ? [buildWithout(['out'], 'write the outputs beside the source')]
908
+ : [
909
+ themeCommand(
910
+ words,
911
+ 'template',
912
+ ['theme.template.ts'],
913
+ 'an annotated theme source that builds, to compare with',
914
+ ),
915
+ ];
916
+
771
917
  // One file passed twice would build twice and report two themes.
772
918
  const seenFiles = new Set();
773
919
  for (const entry of entries) {
774
920
  const key = fs.realpathSync(entry.filePath);
775
921
  if (seenFiles.has(key)) {
922
+ const once = entries
923
+ .filter(
924
+ (other, index) =>
925
+ entries.findIndex(
926
+ first =>
927
+ fs.realpathSync(first.filePath) ===
928
+ fs.realpathSync(other.filePath),
929
+ ) === index,
930
+ )
931
+ .map(other => other.file);
776
932
  return cliError(
777
933
  `${entry.file} is given more than once. Select each theme file once.`,
778
- {code: ERROR_CODES.ERR_THEME_INVALID},
934
+ {
935
+ code: ERROR_CODES.ERR_THEME_INVALID,
936
+ suggestions: [buildWithout([], 'each file once', once)],
937
+ },
779
938
  );
780
939
  }
781
940
  seenFiles.add(key);
@@ -789,17 +948,40 @@ function registerThemeCommands(theme, program, docs, words) {
789
948
  options.family
790
949
  ? '--family requires --family-key <key>'
791
950
  : '--family-key requires --family',
792
- {code: ERROR_CODES.ERR_THEME_INVALID},
951
+ {
952
+ code: ERROR_CODES.ERR_THEME_INVALID,
953
+ suggestions: [
954
+ {
955
+ ...themeCommand(
956
+ words,
957
+ words.build,
958
+ [
959
+ ...files,
960
+ // --out names one output, so it goes with one file only.
961
+ ...(options.out && files.length === 1
962
+ ? ['--out', options.out]
963
+ : []),
964
+ ...(options.check ? ['--check'] : []),
965
+ ],
966
+ 'build each theme on its own',
967
+ ),
968
+ },
969
+ ],
970
+ },
793
971
  );
794
972
  }
795
973
  if (options.family && options.out) {
796
974
  return cliError('--family cannot be combined with --out', {
797
975
  code: ERROR_CODES.ERR_THEME_INVALID,
976
+ suggestions: [
977
+ buildWithout(['out'], 'family outputs go beside the family root'),
978
+ ],
798
979
  });
799
980
  }
800
981
  if (options.family && options.watch) {
801
982
  return cliError('--family cannot be combined with --watch', {
802
983
  code: ERROR_CODES.ERR_THEME_INVALID,
984
+ suggestions: [buildWithout(['watch'], 'build the family once')],
803
985
  });
804
986
  }
805
987
 
@@ -808,6 +990,7 @@ function registerThemeCommands(theme, program, docs, words) {
808
990
  if (options.check && options.watch) {
809
991
  return cliError('--check cannot be combined with --watch', {
810
992
  code: ERROR_CODES.ERR_THEME_INVALID,
993
+ suggestions: [buildWithout(['watch'], 'check once')],
811
994
  });
812
995
  }
813
996
 
@@ -819,7 +1002,15 @@ function registerThemeCommands(theme, program, docs, words) {
819
1002
  `--out takes a single output path and ${entries.length} theme files were given. ` +
820
1003
  'Build them without --out (each theme writes <name>.css next to its source), ' +
821
1004
  'or run one invocation per theme.',
822
- {code: ERROR_CODES.ERR_THEME_INVALID},
1005
+ {
1006
+ code: ERROR_CODES.ERR_THEME_INVALID,
1007
+ suggestions: [
1008
+ buildWithout(
1009
+ ['out'],
1010
+ 'each theme writes <name>.css next to its source',
1011
+ ),
1012
+ ],
1013
+ },
823
1014
  );
824
1015
  }
825
1016
 
@@ -830,6 +1021,9 @@ function registerThemeCommands(theme, program, docs, words) {
830
1021
  if (json) {
831
1022
  return cliError('--watch is not supported with --json', {
832
1023
  code: ERROR_CODES.ERR_THEME_INVALID,
1024
+ suggestions: [
1025
+ buildWithout(['watch'], 'build once, with a JSON result'),
1026
+ ],
833
1027
  });
834
1028
  }
835
1029
  await runThemeBuildWatch(entries, {...options, detail}, words);
@@ -847,6 +1041,13 @@ function registerThemeCommands(theme, program, docs, words) {
847
1041
  privateVarError = true;
848
1042
  };
849
1043
 
1044
+ const refused = await words.preflight?.(files, {
1045
+ cwd: process.cwd(),
1046
+ check: options.check,
1047
+ family: Boolean(options.family),
1048
+ });
1049
+ if (refused) return themeError(refused, words, buildFallback);
1050
+
850
1051
  if (options.family) {
851
1052
  try {
852
1053
  const result = await themeBuildFamily(
@@ -856,6 +1057,7 @@ function registerThemeCommands(theme, program, docs, words) {
856
1057
  check: options.check,
857
1058
  iconsSpecifier: options.iconsSpecifier,
858
1059
  __onPrivateVarError: onPrivateVarError,
1060
+ __commandWords: words,
859
1061
  },
860
1062
  {cwd: process.cwd()},
861
1063
  );
@@ -870,10 +1072,9 @@ function registerThemeCommands(theme, program, docs, words) {
870
1072
  } catch (e) {
871
1073
  const err =
872
1074
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
873
- return cliError(err.message, {
874
- suggestions: err.suggestions,
875
- code: err.code,
876
- });
1075
+ return themeError(err, words, [
1076
+ buildWithout(['family'], 'build each theme on its own'),
1077
+ ]);
877
1078
  }
878
1079
  }
879
1080
 
@@ -885,9 +1086,50 @@ function registerThemeCommands(theme, program, docs, words) {
885
1086
  /** @type {Array<{file: string, receipt: import('../../../api/theme/theme.type.mjs').ThemeBuildResponse | import('../../../api/theme/theme.type.mjs').ThemeBuildCheckResponse | null}>} */
886
1087
  const results = [];
887
1088
  let stale = false;
1089
+ // A batch builds every theme first and then writes them in order, so
1090
+ // two themes that build the same files are refused before either
1091
+ // writes. Any other failure writes the themes built before it, as a
1092
+ // shell loop under `set -e` would have, and stops.
1093
+ const deferred = !options.check && entries.length > 1;
1094
+ // Each built theme keeps its writes and what it prints together; what
1095
+ // it prints waits until its outputs are written, so no `[ok]` line
1096
+ // names a file that is never written.
1097
+ /** @type {Array<{writes: Array<Array<{dest: string, content: string}>>, lines: Array<() => void>}>} */
1098
+ const built = [];
1099
+ const publish = () => {
1100
+ for (const theme of built.splice(0)) {
1101
+ writeDeferredBuildOutputs(theme.writes);
1102
+ for (const show of theme.lines) show();
1103
+ }
1104
+ };
1105
+ const writeFailed = (/** @type {unknown} */ error) =>
1106
+ themeError(
1107
+ /** @type {import('../../../api/error.mjs').AstryxError} */ (error),
1108
+ words,
1109
+ [
1110
+ buildWithout(
1111
+ [],
1112
+ 'run the same build again once the files can be written',
1113
+ ),
1114
+ ],
1115
+ );
888
1116
  /** @type {Map<string, string>} */
889
1117
  const claimedOutputs = new Map();
890
1118
  for (const entry of entries) {
1119
+ /** @type {Array<() => void>} */
1120
+ const lines = [];
1121
+ /** @type {Array<Array<{dest: string, content: string}>>} */
1122
+ const writes = [];
1123
+ const log = logger.log;
1124
+ const warn = logger.warn;
1125
+ if (deferred) {
1126
+ logger.log = (/** @type {string | undefined} */ message) => {
1127
+ lines.push(() => log.call(logger, message));
1128
+ };
1129
+ logger.warn = (/** @type {string | undefined} */ message) => {
1130
+ lines.push(() => warn.call(logger, message));
1131
+ };
1132
+ }
891
1133
  try {
892
1134
  const buildOptions = {
893
1135
  out: options.out,
@@ -895,6 +1137,8 @@ function registerThemeCommands(theme, program, docs, words) {
895
1137
  iconsSpecifier: options.iconsSpecifier,
896
1138
  __onPrivateVarError: onPrivateVarError,
897
1139
  __claimedOutputs: claimedOutputs,
1140
+ __deferredWrites: deferred ? writes : undefined,
1141
+ __commandWords: words,
898
1142
  };
899
1143
  let result;
900
1144
  if (report) {
@@ -908,18 +1152,24 @@ function registerThemeCommands(theme, program, docs, words) {
908
1152
  if (built.trailer) trailers.push(built.trailer);
909
1153
  if (compact && result?.type === 'theme.build') {
910
1154
  const {outputs, sizeKB, tokenCount, componentCount} = result.data;
911
- emit(
912
- text(
913
- `[ok] ${outputs.css} (${sizeKB} KB, ${tokenCount} token overrides, ${componentCount} component overrides)`,
914
- ),
915
- );
1155
+ const show = () =>
1156
+ emit(
1157
+ text(
1158
+ `[ok] ${outputs.css} (${sizeKB} KB, ${tokenCount} token overrides, ${componentCount} component overrides)`,
1159
+ ),
1160
+ );
1161
+ if (deferred) lines.push(show);
1162
+ else show();
916
1163
  }
917
1164
  } else {
918
1165
  result = await themeBuild(entry.file, buildOptions, {
919
1166
  cwd: process.cwd(),
920
1167
  });
921
1168
  }
1169
+ logger.log = log;
1170
+ logger.warn = warn;
922
1171
  results.push({file: entry.file, receipt: result ?? null});
1172
+ if (deferred) built.push({writes, lines});
923
1173
  if (
924
1174
  options.check &&
925
1175
  result &&
@@ -929,18 +1179,44 @@ function registerThemeCommands(theme, program, docs, words) {
929
1179
  stale = true;
930
1180
  }
931
1181
  } catch (e) {
1182
+ logger.log = log;
1183
+ logger.warn = warn;
932
1184
  const err =
933
1185
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
934
1186
  // Stop at the first failure, as a shell loop under `set -e` does.
935
1187
  // With several themes in flight the message alone rarely says which
936
1188
  // one broke, so name it. Themes already written keep their install
937
1189
  // and font guidance.
1190
+ if (/** @type {any} */ (err).outputCollision) {
1191
+ // Nothing is written, so only this theme's warnings are shown.
1192
+ for (const show of lines) show();
1193
+ return themeError(err, words, [
1194
+ buildWithout([], 'build the first theme on its own', [
1195
+ entries[0].file,
1196
+ ]),
1197
+ ]);
1198
+ }
1199
+ if (deferred) {
1200
+ try {
1201
+ publish();
1202
+ } catch (writeError) {
1203
+ return writeFailed(writeError);
1204
+ }
1205
+ // The failing theme's warnings, such as a missing package, say
1206
+ // why it failed.
1207
+ for (const show of lines) show();
1208
+ }
938
1209
  if (report && compact) printCompactTrailer(trailers);
939
1210
  else if (report) printBatchTrailer(trailers);
940
- return cliError(
941
- entries.length > 1 ? `${entry.file}: ${err.message}` : err.message,
942
- {suggestions: err.suggestions, code: err.code},
943
- );
1211
+ if (entries.length > 1) err.message = `${entry.file}: ${err.message}`;
1212
+ return themeError(err, words, buildFallback);
1213
+ }
1214
+ }
1215
+ if (deferred) {
1216
+ try {
1217
+ publish();
1218
+ } catch (e) {
1219
+ return writeFailed(e);
944
1220
  }
945
1221
  }
946
1222
 
@@ -986,6 +1262,19 @@ function registerThemeCommands(theme, program, docs, words) {
986
1262
  return NO_RESULT_SET;
987
1263
  },
988
1264
  });
1265
+ // A group may hold locks while a build or check runs (the editor's theme
1266
+ // lock), so it never reads a change half written.
1267
+ if (words.hold) {
1268
+ /** @type {(() => Promise<void>) | undefined} */
1269
+ let release;
1270
+ buildCli.hook('preAction', async (_, cmd) => {
1271
+ release = await words.hold?.(cmd.args, {cwd: process.cwd()});
1272
+ });
1273
+ buildCli.hook('postAction', async () => {
1274
+ await release?.();
1275
+ release = undefined;
1276
+ });
1277
+ }
989
1278
 
990
1279
  const listCli = defineCommand(theme, docs.list, {
991
1280
  fn: themeListFn,
@@ -1001,7 +1290,14 @@ function registerThemeCommands(theme, program, docs, words) {
1001
1290
  } catch (e) {
1002
1291
  const err =
1003
1292
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1004
- return themeError(err, words);
1293
+ return themeError(err, words, [
1294
+ options.package
1295
+ ? themeCommand(words, 'list', [], 'every theme, from every package')
1296
+ : {
1297
+ name: `${getCliInvocation(process.cwd())} doctor`,
1298
+ reason: 'names the integration or theme that is broken',
1299
+ },
1300
+ ]);
1005
1301
  }
1006
1302
 
1007
1303
  await warnOnThemeIntegrationIssues(json);
@@ -1048,7 +1344,9 @@ function registerThemeCommands(theme, program, docs, words) {
1048
1344
  } catch (e) {
1049
1345
  const err =
1050
1346
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1051
- return themeError(err, words);
1347
+ return themeError(err, words, [
1348
+ themeCommand(words, 'list', [], 'the themes you can add'),
1349
+ ]);
1052
1350
  }
1053
1351
 
1054
1352
  await warnOnThemeIntegrationIssues(json);
@@ -1057,6 +1355,10 @@ function registerThemeCommands(theme, program, docs, words) {
1057
1355
  ? resultSet({count: result.data.length, resultKind: 'theme'})
1058
1356
  : NO_RESULT_SET;
1059
1357
 
1358
+ if (result.type !== 'theme.list')
1359
+ result = /** @type {any} */ (
1360
+ inGroupNotes(/** @type {any} */ (result), words)
1361
+ );
1060
1362
  if (json) {
1061
1363
  jsonOut(result);
1062
1364
  return answered;
@@ -1083,9 +1385,12 @@ function registerThemeCommands(theme, program, docs, words) {
1083
1385
  } catch (e) {
1084
1386
  const err =
1085
1387
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1086
- return themeError(err, words);
1388
+ return themeError(err, words, [
1389
+ themeCommand(words, 'list', [], 'the themes this app has added'),
1390
+ ]);
1087
1391
  }
1088
1392
  await warnOnThemeIntegrationIssues(json);
1393
+ result = inGroupNotes(result, words);
1089
1394
  if (json) jsonOut(result);
1090
1395
  else printThemeApp(result);
1091
1396
  return NO_RESULT_SET;
@@ -1103,9 +1408,12 @@ function registerThemeCommands(theme, program, docs, words) {
1103
1408
  } catch (e) {
1104
1409
  const err =
1105
1410
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1106
- return themeError(err, words);
1411
+ return themeError(err, words, [
1412
+ themeCommand(words, 'list', [], 'the themes this app has added'),
1413
+ ]);
1107
1414
  }
1108
1415
  await warnOnThemeIntegrationIssues(json);
1416
+ result = inGroupNotes(result, words);
1109
1417
  if (json) jsonOut(result);
1110
1418
  else printThemeApp(result);
1111
1419
  return NO_RESULT_SET;
@@ -1132,7 +1440,9 @@ function registerThemeCommands(theme, program, docs, words) {
1132
1440
  } catch (e) {
1133
1441
  const err =
1134
1442
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1135
- return themeError(err, words);
1443
+ return themeError(err, words, [
1444
+ themeCommand(words, 'list', [], 'the themes you can fork'),
1445
+ ]);
1136
1446
  }
1137
1447
  await warnOnThemeIntegrationIssues(json);
1138
1448
  if (json) jsonOut(result);
@@ -1160,7 +1470,14 @@ function registerThemeCommands(theme, program, docs, words) {
1160
1470
  } catch (e) {
1161
1471
  const err =
1162
1472
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1163
- return themeError(err, words);
1473
+ return themeError(err, words, [
1474
+ themeCommand(
1475
+ words,
1476
+ 'template',
1477
+ ['theme.template.ts'],
1478
+ 'write the template at the project root',
1479
+ ),
1480
+ ]);
1164
1481
  }
1165
1482
 
1166
1483
  // Writes a starter theme file, or declines to overwrite one.
@@ -1171,9 +1488,19 @@ function registerThemeCommands(theme, program, docs, words) {
1171
1488
 
1172
1489
  const invocation = getCliInvocation(process.cwd());
1173
1490
  if (!result.data.written) {
1491
+ const {overwritable, alternative} = result.data;
1174
1492
  emit(
1175
1493
  text(`[skip] ${result.data.path} already exists — left as is.`),
1176
- text(`Pass --overwrite to replace it with a fresh copy.`),
1494
+ ...(overwritable === false && alternative
1495
+ ? [
1496
+ text(
1497
+ 'It is not a theme template that --overwrite may replace. Write the template to a new file:',
1498
+ ),
1499
+ code(
1500
+ `${invocation} ${words.group} template ${quoteCommandArgument(alternative)}`,
1501
+ ),
1502
+ ]
1503
+ : [text(`Pass --overwrite to replace it with a fresh copy.`)]),
1177
1504
  );
1178
1505
  return NO_RESULT_SET;
1179
1506
  }
@@ -1183,7 +1510,9 @@ function registerThemeCommands(theme, program, docs, words) {
1183
1510
  'It documents every defineTheme field, the token families, and the component override syntax. ' +
1184
1511
  'Copy what you need into your own theme file, then delete it.',
1185
1512
  ),
1186
- code(`${invocation} ${words.group} ${words.build} ${result.data.path}`),
1513
+ code(
1514
+ `${invocation} ${words.group} ${words.build} ${quoteCommandArgument(result.data.path)}`,
1515
+ ),
1187
1516
  );
1188
1517
  return NO_RESULT_SET;
1189
1518
  },
@@ -1201,7 +1530,9 @@ function registerThemeCommands(theme, program, docs, words) {
1201
1530
  } catch (e) {
1202
1531
  const err =
1203
1532
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1204
- return themeError(err, words);
1533
+ return themeError(err, words, [
1534
+ themeCommand(words, 'targets', [], 'every theming target'),
1535
+ ]);
1205
1536
  }
1206
1537
 
1207
1538
  // A filter is a substring search with an exact-name fast path (see
@@ -1212,15 +1543,16 @@ function registerThemeCommands(theme, program, docs, words) {
1212
1543
  const matched = new Set(
1213
1544
  result.data.targets.map(target => target.component.toLowerCase()),
1214
1545
  );
1546
+ const needle = normalizeTargetFilter(filter);
1215
1547
  const answered = resultSet({
1216
1548
  count: result.data.targets.length,
1217
1549
  resultKind: 'theme',
1218
1550
  // Falsy, not just null: the api treats an empty filter as no filter
1219
1551
  // at all, so recording one as a match that missed would invent a
1220
1552
  // failed lookup out of a run that never looked anything up.
1221
- directMatch: !filter
1553
+ directMatch: !needle
1222
1554
  ? undefined
1223
- : matched.size === 1 && matched.has(String(filter).toLowerCase()),
1555
+ : matched.size === 1 && matched.has(needle),
1224
1556
  });
1225
1557
  if (json) {
1226
1558
  jsonOut(result);