@astryxdesign/cli 0.7.14-canary.gfb823d9 → 0.7.14

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 (135) hide show
  1. package/CHANGELOG.md +197 -0
  2. package/api/component/_adapter.d.mts +15 -0
  3. package/api/component/_adapter.mjs +76 -0
  4. package/api/component/component.mjs +8 -1
  5. package/api/search/_named-keywords.d.mts +31 -0
  6. package/api/search/_named-keywords.mjs +177 -0
  7. package/api/search/search-index.mjs +8 -1
  8. package/api/search/search.d.mts +6 -1
  9. package/api/search/search.mjs +49 -8
  10. package/api/theme/_adapter.d.mts +33 -0
  11. package/api/theme/_adapter.mjs +352 -16
  12. package/api/theme/build/build.mjs +261 -10
  13. package/api/theme/eject/eject.mjs +13 -1
  14. package/api/theme/list/list.mjs +11 -2
  15. package/api/theme/palette/generate/color.d.mts +2 -0
  16. package/api/theme/palette/generate/color.mjs +1 -1
  17. package/api/theme/template/template.mjs +139 -6
  18. package/api/theme/theme.type.d.mts +15 -1
  19. package/api/theme/theme.type.mjs +9 -3
  20. package/api/theme/themeAdd.doc.mjs +1 -1
  21. package/api/theme/themeBuild.doc.mjs +10 -2
  22. package/api/theme/themeEject.doc.mjs +2 -2
  23. package/api/theme/themeListAvailable.doc.mjs +1 -1
  24. package/api/theme/themeRemove.doc.mjs +1 -1
  25. package/api/theme/themeTemplate.doc.mjs +8 -0
  26. package/api/theme/themeUse.doc.mjs +1 -1
  27. package/api/theme-edit/_adapter.d.mts +36 -2
  28. package/api/theme-edit/_adapter.mjs +340 -12
  29. package/api/theme-edit/_check.d.mts +28 -25
  30. package/api/theme-edit/_check.mjs +876 -308
  31. package/api/theme-edit/_color.d.mts +53 -4
  32. package/api/theme-edit/_color.mjs +406 -79
  33. package/api/theme-edit/_compiler.d.mts +14 -6
  34. package/api/theme-edit/_compiler.mjs +89 -59
  35. package/api/theme-edit/_context.d.mts +28 -8
  36. package/api/theme-edit/_context.mjs +142 -19
  37. package/api/theme-edit/_edit.d.mts +3 -1
  38. package/api/theme-edit/_edit.mjs +746 -76
  39. package/api/theme-edit/_how-commands.d.mts +91 -0
  40. package/api/theme-edit/_how-commands.mjs +269 -0
  41. package/api/theme-edit/_how-question.d.mts +57 -0
  42. package/api/theme-edit/_how-question.mjs +2574 -0
  43. package/api/theme-edit/_how.d.mts +27 -8
  44. package/api/theme-edit/_how.mjs +776 -175
  45. package/api/theme-edit/_overview.d.mts +9 -0
  46. package/api/theme-edit/_overview.mjs +296 -0
  47. package/api/theme-edit/_palette.d.mts +155 -15
  48. package/api/theme-edit/_palette.mjs +1446 -262
  49. package/api/theme-edit/_parts.mjs +61 -5
  50. package/api/theme-edit/_png.d.mts +18 -6
  51. package/api/theme-edit/_png.mjs +135 -25
  52. package/api/theme-edit/_preview-app.d.mts +32 -11
  53. package/api/theme-edit/_preview-app.mjs +1976 -285
  54. package/api/theme-edit/_preview.d.mts +39 -8
  55. package/api/theme-edit/_preview.mjs +367 -41
  56. package/api/theme-edit/_settings.d.mts +147 -11
  57. package/api/theme-edit/_settings.mjs +908 -99
  58. package/api/theme-edit/_tables.d.mts +4 -16
  59. package/api/theme-edit/_tables.mjs +51 -117
  60. package/api/theme-edit/theme-edit.type.d.mts +102 -66
  61. package/api/theme-edit/theme-edit.type.mjs +58 -40
  62. package/api/theme-edit/themeEditHow.doc.mjs +17 -6
  63. package/api/theme-edit/themeEditNew.doc.mjs +21 -5
  64. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +18 -5
  65. package/api/theme-edit/themeEditPreviewApp.doc.mjs +12 -9
  66. package/api/theme-edit/themeEditPreviewList.doc.mjs +11 -2
  67. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +29 -3
  68. package/api/theme-edit/themeEditSet.doc.mjs +14 -8
  69. package/api/theme-edit/themeEditShow.doc.mjs +10 -5
  70. package/api/theme-edit/themeEditUndo.doc.mjs +9 -4
  71. package/assets/discover/official-packages.json +4 -0
  72. package/assets/docs/tree/icon-sets.doc.mjs +3 -3
  73. package/assets/docs.generated.json +1 -0
  74. package/assets/icons/definitions/bookmarkAdd.doc.mjs +9 -0
  75. package/assets/icons/definitions/documentSearch.doc.mjs +9 -0
  76. package/assets/icons/definitions/keyboard.doc.mjs +9 -0
  77. package/assets/icons/definitions/paintBrush.doc.mjs +9 -0
  78. package/assets/icons/definitions/wallet.doc.mjs +9 -0
  79. package/assets/preview-app/gitignore +3 -0
  80. package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.doc.mjs +1 -1
  81. package/assets/templates/blocks/components/Lightbox/LightboxGallery.tsx +1 -1
  82. package/assets/templates/components.generated.json +1 -0
  83. package/assets/templates/pages/gallery-hero/page.tsx +8 -2
  84. package/assets/templates/pages/settings-dialog/template.doc.mjs +3 -3
  85. package/assets/templates/pages/side-gallery/page.tsx +1 -1
  86. package/assets/templates/pages/table-filter/template.doc.mjs +2 -2
  87. package/assets/templates/pages/theme-showcase/template.doc.mjs +1 -1
  88. package/clients/cli/bin/astryx.mjs +37 -5
  89. package/clients/cli/commands/experimental/theme.mjs +422 -57
  90. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +22 -9
  91. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +103 -4
  92. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +13 -8
  93. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +5 -5
  94. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +5 -5
  95. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  96. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +3 -2
  97. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -8
  98. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +2 -2
  99. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  100. package/clients/cli/commands/experimental-theme-targets.doc.mjs +1 -1
  101. package/clients/cli/commands/experimental-theme.doc.mjs +3 -4
  102. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  103. package/clients/cli/commands/theme-eject.doc.mjs +3 -3
  104. package/clients/cli/commands/theme-remove.doc.mjs +2 -2
  105. package/clients/cli/commands/theme-template.doc.mjs +11 -4
  106. package/clients/cli/commands/theme.mjs +145 -46
  107. package/clients/cli/commands.generated.json +1 -0
  108. package/clients/cli/index.mjs +96 -5
  109. package/clients/cli/lib/json-shim.mjs +29 -1
  110. package/foundation/config/project.d.mts +16 -2
  111. package/foundation/config/project.mjs +40 -6
  112. package/foundation/config/theme-state.d.mts +9 -0
  113. package/foundation/config/theme-state.mjs +20 -1
  114. package/foundation/discovery/template-adapter.d.mts +12 -1
  115. package/foundation/discovery/template-adapter.mjs +29 -4
  116. package/foundation/discovery/template-icons.d.mts +13 -0
  117. package/foundation/discovery/template-icons.mjs +76 -0
  118. package/foundation/discovery/template-needs.d.mts +7 -0
  119. package/foundation/discovery/template-needs.mjs +117 -8
  120. package/foundation/discovery/template-source-tree.d.mts +5 -1
  121. package/foundation/discovery/template-source-tree.mjs +6 -4
  122. package/foundation/discovery/theme-discovery.d.mts +14 -3
  123. package/foundation/discovery/theme-discovery.mjs +45 -12
  124. package/foundation/doc-compiler/import.mjs +68 -3
  125. package/foundation/doc-compiler/stored-docs.d.mts +27 -0
  126. package/foundation/doc-compiler/stored-docs.mjs +65 -0
  127. package/foundation/fs/fs-error.d.mts +17 -0
  128. package/foundation/fs/fs-error.mjs +34 -0
  129. package/foundation/response/error-codes.d.mts +3 -1
  130. package/foundation/response/error-codes.doc.mjs +13 -1
  131. package/foundation/response/error-codes.mjs +11 -1
  132. package/foundation/response/response-types.doc.mjs +6 -6
  133. package/package.json +6 -7
  134. package/clients/cli/commands/experimental-theme-palette-generate.doc.mjs +0 -73
  135. package/clients/cli/commands/experimental-theme-palette.doc.mjs +0 -37
@@ -29,6 +29,7 @@ import {
29
29
  text,
30
30
  } from '../../formatters/index.mjs';
31
31
  import {cliError} from '../../lib/cli-error.mjs';
32
+ import {AstryxError} from '../../../../api/error.mjs';
32
33
  import {defineCommand} from '../../lib/define-command.mjs';
33
34
  import {
34
35
  themeEditHow,
@@ -41,6 +42,10 @@ import {
41
42
  themeEditShow,
42
43
  themeEditUndo,
43
44
  } from '../../../../api/theme-edit/theme-edit.mjs';
45
+ import {
46
+ fileExists,
47
+ isHowPicture,
48
+ } from '../../../../api/theme-edit/_adapter.mjs';
44
49
  import {registerThemeSubcommands} from '../theme.mjs';
45
50
  import {doc as groupDoc} from '../experimental-theme.doc.mjs';
46
51
  import {doc as editorDoc} from '../experimental-theme-editor.doc.mjs';
@@ -54,8 +59,6 @@ import {doc as previewAppDoc} from '../experimental-theme-preview-app.doc.mjs';
54
59
  import {doc as previewListDoc} from '../experimental-theme-preview-list.doc.mjs';
55
60
  import {doc as previewRemoveDoc} from '../experimental-theme-preview-remove.doc.mjs';
56
61
  import {doc as howDoc} from '../experimental-theme-editor-how.doc.mjs';
57
- import {doc as paletteDoc} from '../experimental-theme-palette.doc.mjs';
58
- import {doc as paletteGenerateDoc} from '../experimental-theme-palette-generate.doc.mjs';
59
62
  import {doc as compileDoc} from '../experimental-theme-compile.doc.mjs';
60
63
  import {doc as listDoc} from '../experimental-theme-list.doc.mjs';
61
64
  import {doc as addDoc} from '../experimental-theme-add.doc.mjs';
@@ -83,8 +86,15 @@ const HOW = `${EDITOR} ${howDoc.name.split(' ').pop()}`;
83
86
  * Commands in a line, with the run prefix this project uses.
84
87
  * @param {string} line
85
88
  */
86
- const cmd = line =>
87
- line.split(PREFIX).join(`${getCliInvocation()} experimental theme`);
89
+ const cmd = line => {
90
+ const stem = `${getCliInvocation()} experimental theme`;
91
+ // A line that already starts its commands this way (how's answers do,
92
+ // in JSON too) keeps them.
93
+ return line
94
+ .split(stem)
95
+ .map(part => part.split(PREFIX).join(stem))
96
+ .join(stem);
97
+ };
88
98
 
89
99
  /**
90
100
  * Print blocks, a blank line between them, with this project's run prefix
@@ -129,12 +139,20 @@ function flatRecord(o) {
129
139
  const out = {};
130
140
  for (const [k, v] of Object.entries(o)) {
131
141
  if (Array.isArray(v) && !v.length) continue;
132
- if (v && typeof v === 'object' && !Array.isArray(v))
133
- Object.assign(
134
- out,
135
- flatRecord(/** @type {Record<string, unknown>} */ (v)),
136
- );
137
- else out[k] = shownValue(v);
142
+ if (v && typeof v === 'object' && !Array.isArray(v)) {
143
+ const inner = Object.entries(/** @type {Record<string, unknown>} */ (v));
144
+ // A map of objects keeps one field per entry, so no entry overwrites
145
+ // another.
146
+ if (
147
+ inner.some(([, x]) => x && typeof x === 'object' && !Array.isArray(x))
148
+ )
149
+ for (const [name, x] of inner) out[name] = shownValue(x);
150
+ else
151
+ Object.assign(
152
+ out,
153
+ flatRecord(/** @type {Record<string, unknown>} */ (v)),
154
+ );
155
+ } else out[k] = shownValue(v);
138
156
  }
139
157
  return out;
140
158
  }
@@ -186,22 +204,52 @@ function project(data) {
186
204
  section(`${k}:`),
187
205
  record(flatRecord(Object.fromEntries(entries))),
188
206
  );
189
- else
207
+ else {
208
+ // Plain fields of a mixed object print first, as `<key> <field>`.
209
+ /** @type {Record<string, string>} */
210
+ const head = {};
211
+ /** @type {Array<string | import('../../formatters/index.mjs').Block>} */
212
+ const nested = [];
190
213
  for (const [name, x] of entries) {
191
214
  if (Array.isArray(x) && !x.length) continue;
192
- const items = Array.isArray(x) ? x : [x];
193
- parts.push(
194
- section(`${k} ${name}:`),
195
- records(
196
- /** @type {Record<string, unknown>[]} */ (items).map(flatRecord),
197
- ),
198
- );
215
+ if (x === null || typeof x !== 'object')
216
+ head[`${k} ${name}`] = shownValue(x);
217
+ else if (Array.isArray(x) && typeof x[0] !== 'object') {
218
+ const joined = x.join(', ');
219
+ if (x.length <= 3 && joined.length <= 80)
220
+ head[`${k} ${name}`] = joined;
221
+ else nested.push(section(`${k} ${name}:`), list(x.map(String)));
222
+ } else {
223
+ const items = Array.isArray(x) ? x : [x];
224
+ nested.push(
225
+ section(`${k} ${name}:`),
226
+ records(
227
+ /** @type {Record<string, unknown>[]} */ (items).map(
228
+ flatRecord,
229
+ ),
230
+ ),
231
+ );
232
+ }
199
233
  }
234
+ if (Object.keys(head).length) parts.push(record(head));
235
+ parts.push(...nested);
236
+ }
200
237
  }
201
238
  }
202
239
  return [record(plain), ...parts];
203
240
  }
204
241
 
242
+ /**
243
+ * A result whose change was saved but not checked leads with a warning
244
+ * line naming the cause.
245
+ * @param {unknown} result
246
+ * @returns {string[]}
247
+ */
248
+ function notCheckedLine(result) {
249
+ const n = /** @type {any} */ (result)?.data?.notChecked;
250
+ return n ? [`[warn] saved, not checked (${n.code}): ${n.cause}`] : [];
251
+ }
252
+
205
253
  /**
206
254
  * Run one API call: errors become the CLI error envelope, results go to
207
255
  * JSON or to `render`.
@@ -233,7 +281,7 @@ async function run(program, call, render, answer) {
233
281
  jsonOut(/** @type {any} */ (result));
234
282
  return answered;
235
283
  }
236
- print(render(result));
284
+ print([...notCheckedLine(result), ...render(result)]);
237
285
  return answered;
238
286
  }
239
287
 
@@ -259,6 +307,53 @@ const changeOptions = o => ({
259
307
  png: o.png ?? false,
260
308
  });
261
309
 
310
+ /**
311
+ * The dial settings `new` takes as flags, by dial name: every option of its
312
+ * CommandDoc that `set` would take as a dial.
313
+ * @param {any} o
314
+ * @returns {Record<string, string | string[]>}
315
+ */
316
+ function newSettings(o) {
317
+ /** @type {Record<string, string | string[]>} */
318
+ const out = {};
319
+ for (const opt of newDoc.options ?? []) {
320
+ if (opt.param !== 'options.settings') continue;
321
+ const name = opt.flag.split(' ')[0].slice(2);
322
+ const value = o[name.replace(/-([a-z])/g, (_, c) => c.toUpperCase())];
323
+ if (value == null) continue;
324
+ // A flag given twice: headings takes one value per axis (a weight and a
325
+ // tracking); any other flag given two different values is refused.
326
+ const all = flagValues(name);
327
+ if (name === 'headings' && all.length > 1) out[name] = all;
328
+ else if (new Set(all).size > 1)
329
+ throw new AstryxError(
330
+ `--${name} was given twice (${all.join(', ')}); give it once. Nothing was changed.`,
331
+ [],
332
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
333
+ );
334
+ else out[name] = String(value);
335
+ }
336
+ return out;
337
+ }
338
+
339
+ /**
340
+ * Every value one flag was given on the command line, in order.
341
+ * @param {string} name
342
+ * @returns {string[]}
343
+ */
344
+ function flagValues(name) {
345
+ const argv = process.argv;
346
+ /** @type {string[]} */
347
+ const out = [];
348
+ for (let i = 0; i < argv.length; i++) {
349
+ if (argv[i] === '--') break;
350
+ if (argv[i] === `--${name}` && i + 1 < argv.length) out.push(argv[++i]);
351
+ else if (argv[i].startsWith(`--${name}=`))
352
+ out.push(argv[i].slice(name.length + 3));
353
+ }
354
+ return out;
355
+ }
356
+
262
357
  /**
263
358
  * The receipt of a change: a status line, then the change data.
264
359
  * @param {import('../../../../api/theme-edit/theme-edit.type.mjs').ThemeEditChangeResponse} r
@@ -269,22 +364,130 @@ function changeBlocks(r) {
269
364
  const status =
270
365
  d.was != null
271
366
  ? `[ok] ${d.theme}: ${s.thing} ${d.was} -> ${s.value}`
272
- : `[ok] ${d.theme}: ${d.action === 'set' ? describe(s) : `undid ${describe(s)}: back to the base theme's value`}`;
367
+ : `[ok] ${d.theme}: ${d.action === 'set' ? describe(s) : `removed ${describe(s)}; now ${/** @type {any} */ (d).now ?? "the base theme's value"} applies`}`;
368
+ // On undo, `setting` and `removed` both name the setting removed, as in
369
+ // the JSON; the status line says the base theme's value is back.
273
370
  return [status, ...project(/** @type {any} */ (d))];
274
371
  }
275
372
 
373
+ /**
374
+ * The text of `show`: the theme, then each color with its seed and the shade
375
+ * each token uses, the notes on moved shades, and the generated files last.
376
+ * @param {import('../../../../api/theme-edit/theme-edit.type.mjs').ThemeEditShowResponse['data']} d
377
+ */
378
+ function showBlocks(d) {
379
+ const {settings, colors, colorNotes, colorFiles, ...rest} = d;
380
+ const [head, ...others] = project(/** @type {any} */ (rest));
381
+ return [
382
+ head,
383
+ // Each setting as named fields: its whole scope, the parts it reaches,
384
+ // and what a stronger setting hides of it.
385
+ ...(settings.length
386
+ ? [section('settings:'), records(settings.map(s => flatRecord(s)))]
387
+ : []),
388
+ ...others,
389
+ ...(colors.length
390
+ ? [
391
+ section('colors:'),
392
+ ...colors.flatMap(c => [
393
+ record({color: c.color, seed: c.seed}),
394
+ record(c.tokens),
395
+ ]),
396
+ ]
397
+ : []),
398
+ ...(colorNotes.length ? [section('colorNotes:'), list(colorNotes)] : []),
399
+ colorFiles
400
+ ? [section('colorFiles:'), record(colorFiles)]
401
+ : record({colorFiles: 'none'}),
402
+ ].flat();
403
+ }
404
+
276
405
  /**
277
406
  * The text of a lookup answer: the answer data, lists one item per line.
278
407
  * @param {any} d
279
408
  */
280
409
  function lookupBlocks(d) {
281
- if (d.kind === 'question' && !d.results.length)
282
- return [
283
- `No match for "${d.subject}". Name the part (header, nav links, card, button, banner, input...) and what to change (text color, background, gradient, corners, border, shadow, spacing, bold).`,
284
- ...project(d),
285
- `Tip: ${HOW} --list parts`,
286
- ];
287
- return project(d);
410
+ // Echoed user text never drives the terminal: control characters print
411
+ // as escapes.
412
+ const safe = (/** @type {unknown} */ v) =>
413
+ typeof v === 'string'
414
+ ? v.replace(
415
+ /\p{Cc}/gu,
416
+ c => `\\x${(c.charCodeAt(0) + 0x100).toString(16).slice(1)}`,
417
+ )
418
+ : v;
419
+ /** @type {Record<string, unknown>} */
420
+ const shown = {};
421
+ for (const [k, v] of Object.entries(d)) shown[k] = safe(v);
422
+ const {
423
+ hint,
424
+ run: next,
425
+ results,
426
+ examples,
427
+ refused,
428
+ points,
429
+ items,
430
+ ...rest
431
+ } = /** @type {any} */ (shown);
432
+ // Commands print one to a line and are never wrapped, so a line pasted
433
+ // into a shell runs exactly one whole command; a sequence is one line.
434
+ /** @param {string[]} cmds @param {boolean} [sequence] */
435
+ const commandLines = (cmds, sequence) =>
436
+ 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}`]);
442
+ /** @type {Array<string | import('../../formatters/index.mjs').Block>} */
443
+ const blocks = [...(hint ? [String(hint)] : []), ...project(rest)];
444
+ if (Array.isArray(results) && results.length)
445
+ blocks.push(
446
+ 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'),
455
+ ),
456
+ );
457
+ if (Array.isArray(examples) && examples.length)
458
+ blocks.push(section('examples:'), text(commandLines(examples).join('\n')));
459
+ if (Array.isArray(refused) && refused.length)
460
+ blocks.push(section('refused:'), text(refusedLines(refused).join('\n')));
461
+ if (Array.isArray(points) && points.length)
462
+ blocks.push(
463
+ section('points:'),
464
+ text(
465
+ points
466
+ .map(
467
+ (/** @type {any} */ x) => ` ${x.at} ${x.color} alpha ${x.alpha}`,
468
+ )
469
+ .join('\n'),
470
+ ),
471
+ );
472
+ if (Array.isArray(items) && items.length) {
473
+ if (items.some((/** @type {any} */ x) => Array.isArray(x.examples)))
474
+ blocks.push(
475
+ 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'),
484
+ ),
485
+ );
486
+ else blocks.push(...project({items}).slice(1));
487
+ }
488
+ if (Array.isArray(next) && next.length)
489
+ blocks.push(`Tip: ${next.map(String).join(', or ')}`);
490
+ return blocks;
288
491
  }
289
492
 
290
493
  /**
@@ -296,6 +499,23 @@ function lookupBlocks(d) {
296
499
  * @returns {ReturnType<typeof cliError> | null}
297
500
  */
298
501
  function strayOption(command, rest) {
502
+ // A scope flag given twice would keep only the last one without a word.
503
+ for (const flag of ['on', 'when', 'state', 'mode']) {
504
+ const all = flagValues(flag);
505
+ if (new Set(all).size > 1)
506
+ return cliError(
507
+ `--${flag} was given twice (${all.join(', ')}); give it once.`,
508
+ {
509
+ suggestions: [
510
+ {
511
+ name: `${EDITOR} ${command} --help`,
512
+ reason: 'every option it takes',
513
+ },
514
+ ],
515
+ code: ERROR_CODES.ERR_INVALID_ARGUMENT,
516
+ },
517
+ );
518
+ }
299
519
  const word = rest.find(w => typeof w === 'string' && w.startsWith('--'));
300
520
  if (word == null) return null;
301
521
  return cliError(
@@ -309,6 +529,22 @@ function strayOption(command, rest) {
309
529
  );
310
530
  }
311
531
 
532
+ /**
533
+ * A refusal for words after what a command takes, which would otherwise be
534
+ * dropped without a word; null when there are none.
535
+ * @param {string} command
536
+ * @param {string[]} extra
537
+ */
538
+ function extraWords(command, extra) {
539
+ if (!extra.length) return null;
540
+ return cliError(`${command} does not take "${extra.join(' ')}".`, {
541
+ suggestions: [
542
+ {name: `${EDITOR} ${command} --help`, reason: 'what it takes'},
543
+ ],
544
+ code: ERROR_CODES.ERR_INVALID_ARGUMENT,
545
+ });
546
+ }
547
+
312
548
  /**
313
549
  * Help that explains exactly what a subcommand does: its whole description
314
550
  * under the usage line, while the group's list keeps the one-line summary.
@@ -381,15 +617,36 @@ export function registerExperimentalTheme(group, program) {
381
617
  explained(
382
618
  defineCommand(editor, newDoc, {
383
619
  fn: newFn,
384
- action: (/** @type {string} */ name, /** @type {any} */ o) =>
620
+ action: (
621
+ /** @type {string} */ name,
622
+ /** @type {any} */ o,
623
+ /** @type {any} */ cmd,
624
+ ) =>
385
625
  run(
386
626
  program,
387
- () =>
388
- themeEditNew(name, {
627
+ () => {
628
+ // A word after the name is never dropped without a word.
629
+ const extra = (cmd?.args ?? []).slice(1);
630
+ if (extra.length)
631
+ throw new AstryxError(
632
+ `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])
634
+ ? [
635
+ {
636
+ name: `${EDITOR} new ${name} --like ${extra[0]}`,
637
+ reason: 'do this instead',
638
+ },
639
+ ]
640
+ : [],
641
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
642
+ );
643
+ return themeEditNew(name, {
389
644
  cwd: process.cwd(),
390
645
  like: o.like,
391
646
  png: o.png ?? false,
392
- }),
647
+ settings: newSettings(o),
648
+ });
649
+ },
393
650
  r => [
394
651
  `[ok] made theme "${r.data.theme}"${r.data.like ? ` on top of ${r.data.like}` : ''}`,
395
652
  ...project(/** @type {any} */ (r.data)),
@@ -423,16 +680,21 @@ export function registerExperimentalTheme(group, program) {
423
680
  explained(
424
681
  defineCommand(editor, showDoc, {
425
682
  fn: showFn,
426
- action: (/** @type {string} */ name, /** @type {any} */ o) =>
683
+ action: (
684
+ /** @type {string} */ name,
685
+ /** @type {any} */ o,
686
+ /** @type {any} */ c,
687
+ ) =>
688
+ extraWords('show', (c?.args ?? []).slice(1)) ??
427
689
  run(
428
690
  program,
429
691
  () =>
430
692
  themeEditShow(name, {
431
693
  cwd: process.cwd(),
432
694
  png: o.png ?? false,
433
- group: o.group,
695
+ section: o.section,
434
696
  }),
435
- r => project(/** @type {any} */ (r.data)),
697
+ r => showBlocks(r.data),
436
698
  ),
437
699
  }),
438
700
  showDoc,
@@ -449,6 +711,7 @@ export function registerExperimentalTheme(group, program) {
449
711
  /** @type {import('commander').Command} */ c,
450
712
  ) =>
451
713
  strayOption('undo', [which, ...(c?.args ?? []).slice(3)]) ??
714
+ extraWords('undo', (c?.args ?? []).slice(3)) ??
452
715
  run(
453
716
  program,
454
717
  () =>
@@ -490,13 +753,36 @@ export function registerExperimentalTheme(group, program) {
490
753
  cwd: process.cwd(),
491
754
  theme: o.theme,
492
755
  template: o.template,
493
- top: o.top == null ? undefined : Number(o.top),
756
+ top: o.top,
494
757
  path: o.path,
495
758
  }),
496
- r => [
497
- `[ok] theme preview in ${r.data.folder}: ${r.data.added.length ? `added ${r.data.added.join(', ')}` : 'pages refreshed'}`,
498
- ...project(/** @type {any} */ (r.data)),
499
- ],
759
+ r => {
760
+ const {matched, skipped, ...rest} = r.data;
761
+ return [
762
+ `[ok] theme preview in ${r.data.folder}: ${
763
+ [
764
+ ...(r.data.added.length
765
+ ? [`added ${r.data.added.join(', ')}`]
766
+ : []),
767
+ ...(r.data.refreshed.length
768
+ ? [
769
+ `${r.data.refreshed.join(', ')} ${r.data.refreshed.length > 1 ? 'were' : 'was'} there already and ${r.data.refreshed.length > 1 ? 'are' : 'is'} written again`,
770
+ ]
771
+ : []),
772
+ ].join('; ') || 'pages refreshed'
773
+ }`,
774
+ ...project(/** @type {any} */ (rest)),
775
+ ...(matched.length
776
+ ? [section('matched:'), records(matched)]
777
+ : []),
778
+ ...(skipped.length
779
+ ? [
780
+ section('skipped:'),
781
+ records(skipped.map(s => flatRecord(s))),
782
+ ]
783
+ : []),
784
+ ];
785
+ },
500
786
  ),
501
787
  }),
502
788
  previewAddDoc,
@@ -512,14 +798,13 @@ export function registerExperimentalTheme(group, program) {
512
798
  themeEditPreviewApp(dir, {
513
799
  cwd: process.cwd(),
514
800
  theme: o.theme,
515
- overwrite: o.overwrite ?? false,
516
801
  }),
517
802
  r => [
518
803
  `[ok] new app in ${r.data.folder} with the theme preview`,
519
804
  ...project(/** @type {any} */ (r.data)),
520
805
  ],
521
806
  ),
522
- }),
807
+ }).allowExcessArguments(false),
523
808
  previewAppDoc,
524
809
  );
525
810
 
@@ -535,7 +820,7 @@ export function registerExperimentalTheme(group, program) {
535
820
  ? project(/** @type {any} */ (r.data))
536
821
  : [
537
822
  ...project(/** @type {any} */ (r.data)),
538
- `Tip: ${PREFIX} preview add`,
823
+ `Tip: ${PREFIX} preview add${o.path == null ? '' : ` --path '${String(o.path).replace(/'/g, `'\\''`)}'`}`,
539
824
  ],
540
825
  r =>
541
826
  resultSet({
@@ -544,7 +829,7 @@ export function registerExperimentalTheme(group, program) {
544
829
  empty: r.data.pages.length === 0,
545
830
  }),
546
831
  ),
547
- }),
832
+ }).allowExcessArguments(false),
548
833
  previewListDoc,
549
834
  );
550
835
 
@@ -563,7 +848,7 @@ export function registerExperimentalTheme(group, program) {
563
848
  ...project(/** @type {any} */ (r.data)),
564
849
  ],
565
850
  ),
566
- }),
851
+ }).allowExcessArguments(false),
567
852
  previewRemoveDoc,
568
853
  );
569
854
 
@@ -571,7 +856,7 @@ export function registerExperimentalTheme(group, program) {
571
856
  defineCommand(editor, howDoc, {
572
857
  fn: howFn,
573
858
  action: async (/** @type {string[]} */ words, /** @type {any} */ o) => {
574
- if (!words.length && o.list == null && !(o.at ?? []).length) {
859
+ if (!words.length && !o.list && !(o.at ?? []).length) {
575
860
  const c = editor.commands.find(
576
861
  x => x.name() === howDoc.name.split(' ').pop(),
577
862
  );
@@ -579,7 +864,7 @@ export function registerExperimentalTheme(group, program) {
579
864
  if (program.opts().json) c?.outputHelp();
580
865
  else
581
866
  print([
582
- `Usage: ${HOW} [<part|setting|"question"|picture.png>] [--at x,y] [--list dials|tokens|parts|families|properties]`,
867
+ `Usage: ${HOW} [<part|setting|"question"|picture.png>] [--theme <name>] [--at x,y] [--list dials|tokens|parts|groups|properties [filter]]`,
583
868
  '',
584
869
  'Examples:',
585
870
  ...(howDoc.examples ?? []).flatMap(e => [
@@ -589,24 +874,106 @@ export function registerExperimentalTheme(group, program) {
589
874
  ]);
590
875
  return NO_RESULT_SET;
591
876
  }
592
- const stray = strayOption('how', words.slice(1));
877
+ // `--list=tokens` and a second --list are mistakes of form.
878
+ /** @type {string[]} */
879
+ const raw = /** @type {any} */ (program).rawArgs ?? process.argv;
880
+ const listFlags = raw.filter(
881
+ w => w === '--list' || w.startsWith('--list='),
882
+ );
883
+ const themeFlags = raw.filter(
884
+ w => w === '--theme' || w.startsWith('--theme='),
885
+ );
886
+ if (themeFlags.length > 1)
887
+ return cliError('--theme is given twice; give it once.', {
888
+ suggestions: [{name: `${HOW} --help`, reason: 'give --theme once'}],
889
+ code: ERROR_CODES.ERR_INVALID_ARGUMENT,
890
+ });
891
+ if (listFlags.length > 1)
892
+ return cliError('--list is given twice; give it once.', {
893
+ suggestions: [
894
+ {
895
+ name: `${HOW} --list tokens accent`,
896
+ reason: 'one list, then the filter',
897
+ },
898
+ ],
899
+ code: ERROR_CODES.ERR_INVALID_ARGUMENT,
900
+ });
901
+ let list = o.list;
902
+ let rest = [...words];
903
+ const eq = rest.find(w => w.startsWith('--list='));
904
+ if (eq) {
905
+ list = true;
906
+ rest = [eq.slice('--list='.length), ...rest.filter(w => w !== eq)];
907
+ }
908
+ if (list) {
909
+ // The kind is the first word that names one ("accent --list
910
+ // tokens" too); the other words filter, and may start with --.
911
+ const kinds =
912
+ /^(dials?|tokens?|parts?|groups?|propert(y|ies)|kinds?)$/i;
913
+ const at = rest.findIndex(w => kinds.test(w));
914
+ const kind = at >= 0 ? rest[at] : (rest[0] ?? '');
915
+ const filter = (
916
+ at >= 0 ? rest.filter((_, i) => i !== at) : rest.slice(1)
917
+ )
918
+ .filter(w => w !== '--')
919
+ .join(' ');
920
+ return run(
921
+ program,
922
+ () =>
923
+ themeEditHow(filter, {
924
+ cwd: process.cwd(),
925
+ list: kind,
926
+ at: o.at ?? [],
927
+ theme: o.theme,
928
+ }),
929
+ r => lookupBlocks(/** @type {any} */ (r.data)),
930
+ r => {
931
+ const n = /** @type {any} */ (r.data).items.length;
932
+ return resultSet({count: n, resultKind: 'mixed', empty: n === 0});
933
+ },
934
+ );
935
+ }
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
+ );
964
+ const stray = picture ? null : strayOption('how', rest.slice(1));
593
965
  if (stray) return stray;
594
- // A number after a picture is how many colors to list.
595
966
  const count =
596
- words.length === 2 &&
597
- /\.png$/i.test(words[0]) &&
598
- /^\d+$/.test(words[1])
599
- ? Number(words[1])
600
- : undefined;
601
- const subject = count == null ? words.join(' ') : words[0];
967
+ picture && rest.length === 2 ? Number(rest[1]) : undefined;
968
+ const subject = picture ? rest[0] : rest.join(' ');
602
969
  return run(
603
970
  program,
604
971
  () =>
605
972
  themeEditHow(subject, {
606
973
  cwd: process.cwd(),
607
- list: o.list,
608
974
  at: o.at ?? [],
609
975
  count,
976
+ theme: o.theme,
610
977
  }),
611
978
  r => lookupBlocks(/** @type {any} */ (r.data)),
612
979
  r => {
@@ -630,8 +997,6 @@ export function registerExperimentalTheme(group, program) {
630
997
  theme,
631
998
  program,
632
999
  {
633
- palette: paletteDoc,
634
- paletteGenerate: paletteGenerateDoc,
635
1000
  build: compileDoc,
636
1001
  list: listDoc,
637
1002
  add: addDoc,