@astryxdesign/cli 0.7.15 → 0.7.16-canary.g8514aae
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.
- package/README.md +5 -3
- package/api/component/_adapter.d.mts +1 -1
- package/api/component/_adapter.mjs +28 -1
- package/api/doctor/_adapter.d.mts +17 -0
- package/api/doctor/_adapter.mjs +35 -0
- package/api/doctor/doctor.mjs +18 -4
- package/api/integration/validate-integration.mjs +1 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +43 -12
- package/api/theme/build/build.d.mts +1 -21
- package/api/theme/build/build.mjs +149 -37
- package/api/theme/eject/eject.mjs +22 -1
- package/api/theme/template/template.d.mts +19 -0
- package/api/theme/template/template.mjs +91 -19
- package/api/theme/theme.type.d.mts +5 -1
- package/api/theme/theme.type.mjs +2 -1
- package/api/theme/themeBuild.doc.mjs +3 -3
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +9 -3
- package/api/theme-edit/_adapter.d.mts +21 -0
- package/api/theme-edit/_adapter.mjs +176 -22
- package/api/theme-edit/_check.d.mts +7 -0
- package/api/theme-edit/_check.mjs +1050 -173
- package/api/theme-edit/_color.d.mts +2 -8
- package/api/theme-edit/_color.mjs +292 -219
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +20 -1
- package/api/theme-edit/_context.d.mts +21 -0
- package/api/theme-edit/_context.mjs +235 -12
- package/api/theme-edit/_css.d.mts +50 -1
- package/api/theme-edit/_css.mjs +310 -28
- package/api/theme-edit/_edit.d.mts +9 -0
- package/api/theme-edit/_edit.mjs +907 -123
- package/api/theme-edit/_how-commands.d.mts +11 -26
- package/api/theme-edit/_how-commands.mjs +30 -2
- package/api/theme-edit/_how-question.d.mts +7 -0
- package/api/theme-edit/_how-question.mjs +1304 -176
- package/api/theme-edit/_how.mjs +144 -30
- package/api/theme-edit/_palette.d.mts +6 -0
- package/api/theme-edit/_palette.mjs +164 -62
- package/api/theme-edit/_parts.d.mts +16 -0
- package/api/theme-edit/_parts.mjs +49 -1
- package/api/theme-edit/_png.mjs +19 -14
- package/api/theme-edit/_preview-app.mjs +514 -27
- package/api/theme-edit/_preview.d.mts +11 -0
- package/api/theme-edit/_preview.mjs +245 -24
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +35 -9
- package/api/theme-edit/_settings.d.mts +122 -5
- package/api/theme-edit/_settings.mjs +1363 -71
- package/api/theme-edit/_tables.d.mts +19 -0
- package/api/theme-edit/_tables.mjs +205 -149
- package/api/theme-edit/_vet.d.mts +42 -0
- package/api/theme-edit/_vet.mjs +144 -0
- package/api/theme-edit/theme-edit.type.d.mts +2 -1
- package/api/theme-edit/theme-edit.type.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditShow.doc.mjs +11 -3
- package/assets/docs/tree/single-component.doc.mjs +11 -2
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -2
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/preview-app/src/app/globals.css +1 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
- package/assets/templates/components.generated.json +1 -1
- package/authoring/doctypes/_schema.d.mts +52 -5
- package/authoring/doctypes/_schema.mjs +62 -7
- package/authoring/doctypes/base/type.ts +10 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/function/function.doc.mjs +6 -0
- package/authoring/doctypes/function/type.ts +3 -0
- package/authoring/doctypes/legacy.mjs +5 -1
- package/authoring/index.d.ts +1 -0
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.doc.mjs +2 -2
- package/clients/cli/commands/experimental/theme.mjs +188 -37
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +3 -1
- package/clients/cli/commands/theme.mjs +89 -6
- package/clients/cli/formatters/index.mjs +7 -4
- package/clients/cli/lib/cli-error.mjs +9 -3
- package/clients/cli/lib/component-format.mjs +27 -9
- package/clients/cli/lib/json-shim.mjs +40 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/config/project.mjs +50 -14
- package/foundation/discovery/theme-discovery.d.mts +5 -1
- package/foundation/discovery/theme-discovery.mjs +24 -3
- package/foundation/fs/gather-cache.d.mts +9 -2
- package/foundation/fs/gather-cache.mjs +36 -10
- package/foundation/fs/paths.d.mts +16 -0
- package/foundation/fs/paths.mjs +25 -0
- package/foundation/render/host-exit.d.mts +8 -0
- package/foundation/render/host-exit.mjs +11 -0
- package/foundation/render/page-host.mjs +56 -10
- package/foundation/render/page-worker.mjs +14 -0
- package/foundation/render/render-page.mjs +37 -2
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +5 -0
- package/foundation/response/error-codes.mjs +3 -0
- package/foundation/response/json.d.mts +15 -0
- package/foundation/response/json.mjs +52 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +7 -6
|
@@ -57,7 +57,11 @@ import {themeAdd} from '../../../api/theme/add/add.mjs';
|
|
|
57
57
|
import {themeRemove} from '../../../api/theme/remove/remove.mjs';
|
|
58
58
|
import {themeUse} from '../../../api/theme/use/use.mjs';
|
|
59
59
|
import {themeEject} from '../../../api/theme/eject/eject.mjs';
|
|
60
|
-
import {
|
|
60
|
+
import {
|
|
61
|
+
OUTSIDE_PROJECT_WARNING,
|
|
62
|
+
themeTemplate,
|
|
63
|
+
} from '../../../api/theme/template/template.mjs';
|
|
64
|
+
import {findPackageRoot} from '../../../foundation/fs/paths.mjs';
|
|
61
65
|
import {
|
|
62
66
|
themeListAvailable,
|
|
63
67
|
themeListCopySources,
|
|
@@ -113,6 +117,7 @@ import {doc as themePaletteGenerateFn} from '../../../api/theme/themePaletteGene
|
|
|
113
117
|
* @property {(err: import('../../../api/error.mjs').AstryxError, cwd: string) => import('../../../api/error.mjs').AstryxError | null} [explain] - A clearer refusal for this group, or null.
|
|
114
118
|
* @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.
|
|
115
119
|
* @property {(files: string[], options: {cwd: string}) => Promise<() => Promise<void>>} [hold] - Locks held while a build or check runs; resolves to their release.
|
|
120
|
+
* @property {(options: {targetPath?: string, overwrite?: boolean, cwd?: string}) => import('../../../api/theme/theme.type.mjs').ThemeTemplateResponse} [template] - This group's template write, in place of `themeTemplate`.
|
|
116
121
|
*/
|
|
117
122
|
|
|
118
123
|
/** @type {ThemeCommandWords} */
|
|
@@ -222,6 +227,20 @@ function themeCommand(words, sub, args = [], reason = '') {
|
|
|
222
227
|
};
|
|
223
228
|
}
|
|
224
229
|
|
|
230
|
+
/**
|
|
231
|
+
* The message type a `theme build` child sends its watcher in place of a
|
|
232
|
+
* warning a build prints once per invocation (the --out editor-folder
|
|
233
|
+
* warning), so a watch session prints it once, not on every rebuild.
|
|
234
|
+
*/
|
|
235
|
+
const WATCH_WARNING = 'astryx.theme.build.warning';
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* The `argv0` a watcher starts each `theme build` child with. With the IPC
|
|
239
|
+
* channel it marks the child as the watcher's own, so a CLI run another way
|
|
240
|
+
* with an IPC channel (forked by a tool or test runner) still prints.
|
|
241
|
+
*/
|
|
242
|
+
const WATCH_CHILD_ARGV0 = 'astryx-theme-watch';
|
|
243
|
+
|
|
225
244
|
/**
|
|
226
245
|
* Path to this CLI's real entry (clients/cli/bin/astryx.mjs), resolved from
|
|
227
246
|
* this module's location (clients/cli/commands/theme.mjs → ../bin/
|
|
@@ -244,9 +263,17 @@ function resolveCliBin() {
|
|
|
244
263
|
* @param {(child: import('node:child_process').ChildProcess) => void} [onSpawn] -
|
|
245
264
|
* Receives the child, so a watcher that stops can stop it too.
|
|
246
265
|
* @param {ThemeCommandWords} [words]
|
|
266
|
+
* @param {(message: unknown) => void} [onMessage] - Receives what the child
|
|
267
|
+
* hands over the channel (WATCH_WARNING messages).
|
|
247
268
|
* @returns {Promise<number>}
|
|
248
269
|
*/
|
|
249
|
-
function runThemeBuildOnceChild(
|
|
270
|
+
function runThemeBuildOnceChild(
|
|
271
|
+
file,
|
|
272
|
+
options,
|
|
273
|
+
onSpawn,
|
|
274
|
+
words = THEME_WORDS,
|
|
275
|
+
onMessage,
|
|
276
|
+
) {
|
|
250
277
|
const cliBin = resolveCliBin();
|
|
251
278
|
const command = [...words.group.split(' '), words.build];
|
|
252
279
|
// A detail level the user chose applies to every rebuild.
|
|
@@ -257,10 +284,15 @@ function runThemeBuildOnceChild(file, options, onSpawn, words = THEME_WORDS) {
|
|
|
257
284
|
if (options.iconsSpecifier)
|
|
258
285
|
args.push('--icons-specifier', options.iconsSpecifier);
|
|
259
286
|
return new Promise((/** @type {(code: number) => void} */ resolve) => {
|
|
287
|
+
// The IPC channel and argv0 tell the child it builds for this watcher: it
|
|
288
|
+
// hands its once-per-invocation warnings over the channel instead of
|
|
289
|
+
// printing them.
|
|
260
290
|
const child = spawn(process.execPath, args, {
|
|
261
|
-
|
|
291
|
+
argv0: WATCH_CHILD_ARGV0,
|
|
292
|
+
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
|
262
293
|
env: process.env,
|
|
263
294
|
});
|
|
295
|
+
child.on('message', message => onMessage?.(message));
|
|
264
296
|
onSpawn?.(child);
|
|
265
297
|
child.on('close', code => resolve(code ?? 0));
|
|
266
298
|
child.on('error', () => resolve(1));
|
|
@@ -290,9 +322,28 @@ async function runThemeBuildWatch(entries, options, words = THEME_WORDS) {
|
|
|
290
322
|
.map(e => rel(e.filePath))
|
|
291
323
|
.join(', ')} for changes — press Ctrl-C to stop.`;
|
|
292
324
|
|
|
325
|
+
// A warning a build prints once per invocation is printed at most once
|
|
326
|
+
// per watch session (spec:AST-017 FR29a), not on every rebuild.
|
|
327
|
+
let warned = false;
|
|
328
|
+
// Watch never runs under --json, so the logger prints (cli-surface INV12).
|
|
329
|
+
logger.setSilent(false);
|
|
330
|
+
const onMessage = (/** @type {unknown} */ message) => {
|
|
331
|
+
const m = /** @type {{type?: unknown, text?: unknown}} */ (message);
|
|
332
|
+
if (warned || m?.type !== WATCH_WARNING || typeof m.text !== 'string')
|
|
333
|
+
return;
|
|
334
|
+
warned = true;
|
|
335
|
+
logger.warn(m.text);
|
|
336
|
+
};
|
|
337
|
+
|
|
293
338
|
// Initial build.
|
|
294
339
|
for (const entry of entries) {
|
|
295
|
-
await runThemeBuildOnceChild(
|
|
340
|
+
await runThemeBuildOnceChild(
|
|
341
|
+
entry.file,
|
|
342
|
+
options,
|
|
343
|
+
undefined,
|
|
344
|
+
words,
|
|
345
|
+
onMessage,
|
|
346
|
+
);
|
|
296
347
|
}
|
|
297
348
|
|
|
298
349
|
let building = false;
|
|
@@ -323,6 +374,7 @@ async function runThemeBuildWatch(entries, options, words = THEME_WORDS) {
|
|
|
323
374
|
rebuildChild = child;
|
|
324
375
|
},
|
|
325
376
|
words,
|
|
377
|
+
onMessage,
|
|
326
378
|
);
|
|
327
379
|
rebuildDone = done.then(() => {});
|
|
328
380
|
await done;
|
|
@@ -1074,6 +1126,12 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1074
1126
|
// [ok]/[warn] lines, and the install instructions are all emitted from
|
|
1075
1127
|
// inside themeBuild via the shared logger.
|
|
1076
1128
|
logger.setSilent(json);
|
|
1129
|
+
// Started by a watcher (runThemeBuildWatch): hand the editor-folder
|
|
1130
|
+
// warning to it, and let the channel not keep this build alive.
|
|
1131
|
+
const watchChild =
|
|
1132
|
+
typeof process.send === 'function' &&
|
|
1133
|
+
process.argv0 === WATCH_CHILD_ARGV0;
|
|
1134
|
+
if (watchChild) process.channel?.unref();
|
|
1077
1135
|
let privateVarError = false;
|
|
1078
1136
|
const onPrivateVarError = () => {
|
|
1079
1137
|
privateVarError = true;
|
|
@@ -1102,7 +1160,12 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1102
1160
|
if (json) jsonOut(result);
|
|
1103
1161
|
if (
|
|
1104
1162
|
privateVarError ||
|
|
1105
|
-
(result.type === 'theme.build.check' &&
|
|
1163
|
+
(result.type === 'theme.build.check' &&
|
|
1164
|
+
!(
|
|
1165
|
+
/** @type {import('../../../api/theme/theme.type.mjs').ThemeBuildCheckResponse} */ (
|
|
1166
|
+
result
|
|
1167
|
+
).data.upToDate
|
|
1168
|
+
))
|
|
1106
1169
|
) {
|
|
1107
1170
|
process.exitCode = 1;
|
|
1108
1171
|
}
|
|
@@ -1177,6 +1240,15 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1177
1240
|
__claimedOutputs: claimedOutputs,
|
|
1178
1241
|
__deferredWrites: deferred ? writes : undefined,
|
|
1179
1242
|
__commandWords: words,
|
|
1243
|
+
__onEditorFolder: watchChild
|
|
1244
|
+
? (/** @type {string} */ warning) => {
|
|
1245
|
+
// Held open until the message is out, then let go again.
|
|
1246
|
+
process.channel?.ref();
|
|
1247
|
+
process.send?.({type: WATCH_WARNING, text: warning}, () =>
|
|
1248
|
+
process.channel?.unref(),
|
|
1249
|
+
);
|
|
1250
|
+
}
|
|
1251
|
+
: undefined,
|
|
1180
1252
|
};
|
|
1181
1253
|
let result;
|
|
1182
1254
|
if (report) {
|
|
@@ -1471,6 +1543,9 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1471
1543
|
const json = program.opts().json || false;
|
|
1472
1544
|
/** @type {import('../../../api/theme/theme.type.mjs').ThemeEjectResponse} */
|
|
1473
1545
|
let result;
|
|
1546
|
+
// Eject's warnings go to stderr in text mode; the logger is silent
|
|
1547
|
+
// under --json (cli-surface INV12).
|
|
1548
|
+
logger.setSilent(json);
|
|
1474
1549
|
try {
|
|
1475
1550
|
result = await themeEject(slug, {
|
|
1476
1551
|
targetPath,
|
|
@@ -1503,7 +1578,9 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1503
1578
|
/** @type {import('../../../api/theme/theme.type.mjs').ThemeTemplateResponse} */
|
|
1504
1579
|
let result;
|
|
1505
1580
|
try {
|
|
1506
|
-
|
|
1581
|
+
// The experimental command passes its own write, which protects
|
|
1582
|
+
// only the editor's own files.
|
|
1583
|
+
result = (words.template ?? themeTemplate)({
|
|
1507
1584
|
targetPath,
|
|
1508
1585
|
overwrite: options.overwrite,
|
|
1509
1586
|
cwd: process.cwd(),
|
|
@@ -1521,6 +1598,12 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1521
1598
|
]);
|
|
1522
1599
|
}
|
|
1523
1600
|
|
|
1601
|
+
// Outside a project the template is written here, with one warning
|
|
1602
|
+
// on stderr when a file was written; the logger is silent under --json
|
|
1603
|
+
// (cli-surface INV12).
|
|
1604
|
+
logger.setSilent(json);
|
|
1605
|
+
if (result.data.written && !findPackageRoot(process.cwd()))
|
|
1606
|
+
logger.warn(OUTSIDE_PROJECT_WARNING);
|
|
1524
1607
|
// Writes a starter theme file, or declines to overwrite one.
|
|
1525
1608
|
if (json) {
|
|
1526
1609
|
jsonOut(result);
|
|
@@ -236,7 +236,9 @@ function wrapLine(line, width, indent) {
|
|
|
236
236
|
* @returns {Block}
|
|
237
237
|
*/
|
|
238
238
|
export function section(heading, subtitle) {
|
|
239
|
-
return new Block(
|
|
239
|
+
return new Block(
|
|
240
|
+
toAscii(subtitle ? `${heading}\n${subtitle}` : String(heading)),
|
|
241
|
+
);
|
|
240
242
|
}
|
|
241
243
|
|
|
242
244
|
/**
|
|
@@ -311,9 +313,10 @@ export function records(items, options = {}) {
|
|
|
311
313
|
* @returns {Block}
|
|
312
314
|
*/
|
|
313
315
|
function inlineRecords(items, options) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
316
|
+
// Columns from every row: an optional field is on some rows only.
|
|
317
|
+
const [lead, ...rest] = (
|
|
318
|
+
options.fields ?? [...new Set(items.flatMap(o => Object.keys(o ?? {})))]
|
|
319
|
+
).filter(k => !options.omit?.includes(k));
|
|
317
320
|
if (lead == null) return new Block('');
|
|
318
321
|
/** @param {any} o @param {string} k */
|
|
319
322
|
const value = (o, k) => {
|
|
@@ -54,6 +54,8 @@ import {
|
|
|
54
54
|
isJsonMode,
|
|
55
55
|
jsonError as _jsonError,
|
|
56
56
|
humanWarn,
|
|
57
|
+
outputCaptured,
|
|
58
|
+
writeAllSync,
|
|
57
59
|
} from '../../../foundation/response/json.mjs';
|
|
58
60
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
59
61
|
import {setOutcome} from '../../../foundation/debug/index.mjs';
|
|
@@ -129,18 +131,22 @@ export function cliError(message, options = {}) {
|
|
|
129
131
|
// Human mode: prefix "Error:" and print suggestions on subsequent lines.
|
|
130
132
|
// Use console.error directly — we always want stderr for errors regardless
|
|
131
133
|
// of the JSON-mode flag (we already handled JSON above).
|
|
132
|
-
|
|
134
|
+
const lines = [`Error: ${message}`];
|
|
133
135
|
if (suggestions?.length) {
|
|
134
|
-
|
|
136
|
+
lines.push('');
|
|
135
137
|
for (const s of suggestions) {
|
|
136
138
|
// A suggested command stays bare in JSON and is prefixed here.
|
|
137
139
|
const name = /^astryx(\s|$)/.test(s.name)
|
|
138
140
|
? formatCliCommand(s.name)
|
|
139
141
|
: s.name;
|
|
140
142
|
const tag = s.reason ? ` ${name} (${s.reason})` : ` ${name}`;
|
|
141
|
-
|
|
143
|
+
lines.push(tag);
|
|
142
144
|
}
|
|
143
145
|
}
|
|
146
|
+
// Written whole before a hard exit: output still queued for a slow pipe
|
|
147
|
+
// would be cut at 64 KiB. A soft exit lets the stream drain on its own.
|
|
148
|
+
if (hard && !outputCaptured(2)) writeAllSync(2, `${lines.join('\n')}\n`);
|
|
149
|
+
else for (const line of lines) console.error(line);
|
|
144
150
|
|
|
145
151
|
if (hard) {
|
|
146
152
|
process.exit(exitCode);
|
|
@@ -30,6 +30,24 @@ function targetKey(target) {
|
|
|
30
30
|
return target.className.replace(/^astryx-/, '');
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Render one doc example as an optional heading and a code block. A setup
|
|
35
|
+
* example says so in its heading, because it does not run on its own.
|
|
36
|
+
* @param {import('@astryxdesign/cli/authoring').ComponentExampleDoc} ex
|
|
37
|
+
* @param {string} hashes - heading level, e.g. '###'
|
|
38
|
+
* @returns {string[]}
|
|
39
|
+
*/
|
|
40
|
+
function formatExample(ex, hashes) {
|
|
41
|
+
const lines = [];
|
|
42
|
+
if (ex.kind === 'setup') {
|
|
43
|
+
lines.push(`${hashes} ${ex.label ?? 'Setup'} (setup, code only)\n`);
|
|
44
|
+
} else if (ex.label) {
|
|
45
|
+
lines.push(`${hashes} ${ex.label}\n`);
|
|
46
|
+
}
|
|
47
|
+
lines.push('```tsx\n' + ex.code + '\n```\n');
|
|
48
|
+
return lines;
|
|
49
|
+
}
|
|
50
|
+
|
|
33
51
|
/** @param {string} name @returns {string} */
|
|
34
52
|
function dataAttrForName(name) {
|
|
35
53
|
return `data-${name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()}`;
|
|
@@ -306,8 +324,7 @@ export function formatFull(docs, options = {}) {
|
|
|
306
324
|
sections.push(...formatSubComponent(comp));
|
|
307
325
|
if (comp.examples?.length) {
|
|
308
326
|
for (const ex of comp.examples) {
|
|
309
|
-
|
|
310
|
-
sections.push('```tsx\n' + ex.code + '\n```\n');
|
|
327
|
+
sections.push(...formatExample(ex, '####'));
|
|
311
328
|
}
|
|
312
329
|
}
|
|
313
330
|
}
|
|
@@ -316,8 +333,7 @@ export function formatFull(docs, options = {}) {
|
|
|
316
333
|
if (docs.examples?.length) {
|
|
317
334
|
sections.push('## Examples\n');
|
|
318
335
|
for (const ex of docs.examples) {
|
|
319
|
-
|
|
320
|
-
sections.push('```tsx\n' + ex.code + '\n```\n');
|
|
336
|
+
sections.push(...formatExample(ex, '###'));
|
|
321
337
|
}
|
|
322
338
|
}
|
|
323
339
|
|
|
@@ -515,8 +531,7 @@ export function formatCompact(docs, componentName, importHint) {
|
|
|
515
531
|
if (examples.length) {
|
|
516
532
|
sections.push('## Usage\n');
|
|
517
533
|
for (const ex of examples) {
|
|
518
|
-
|
|
519
|
-
sections.push('```tsx\n' + ex.code + '\n```\n');
|
|
534
|
+
sections.push(...formatExample(ex, '###'));
|
|
520
535
|
}
|
|
521
536
|
}
|
|
522
537
|
|
|
@@ -703,9 +718,12 @@ export function formatBrief(docs, componentName, importHint, options = {}) {
|
|
|
703
718
|
output.push(` ${otherProps.join(', ')}`);
|
|
704
719
|
}
|
|
705
720
|
|
|
706
|
-
// First code example
|
|
707
|
-
|
|
708
|
-
|
|
721
|
+
// First code example; a setup example does not show the component in use.
|
|
722
|
+
const usageExample =
|
|
723
|
+
examples.find((/** @type {any} */ ex) => ex.kind !== 'setup') ??
|
|
724
|
+
examples[0];
|
|
725
|
+
if (usageExample) {
|
|
726
|
+
const code = usageExample.code;
|
|
709
727
|
const codeLine =
|
|
710
728
|
code
|
|
711
729
|
.split('\n')
|
|
@@ -45,6 +45,7 @@ import {API_VERSION, isJsonMode, toErrorEnvelope} from '../../../foundation/resp
|
|
|
45
45
|
import {answeredBy} from '../../../foundation/release/run-context.mjs';
|
|
46
46
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
47
47
|
import {setCommand, setOutcome, recordHelp} from '../../../foundation/debug/index.mjs';
|
|
48
|
+
import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
|
|
48
49
|
|
|
49
50
|
/**
|
|
50
51
|
* Fully-qualified name of a command relative to the root program, e.g.
|
|
@@ -290,14 +291,43 @@ const REJECTED_COMMAND = Symbol.for('astryx.jsonShim.rejectedCommand');
|
|
|
290
291
|
* @returns {import('../../../foundation/response/base').Suggestion[] | undefined}
|
|
291
292
|
*/
|
|
292
293
|
function usageSuggestion(err, code) {
|
|
293
|
-
if (code !== 'commander.optionMissingArgument') return undefined;
|
|
294
294
|
const cmd = /** @type {any} */ (err)?.[REJECTED_COMMAND];
|
|
295
295
|
if (!cmd) return undefined;
|
|
296
296
|
const parts = [];
|
|
297
297
|
for (let node = cmd; node; node = node.parent) parts.unshift(node.name());
|
|
298
|
+
// The theme editor names what is missing with its usage and its help, as
|
|
299
|
+
// the project runs the CLI.
|
|
300
|
+
if (
|
|
301
|
+
code === 'commander.missingArgument' &&
|
|
302
|
+
parts.slice(1, 4).join(' ') === 'experimental theme editor'
|
|
303
|
+
) {
|
|
304
|
+
const words = parts.slice(1).join(' ');
|
|
305
|
+
const invocation = getCliInvocation(process.cwd());
|
|
306
|
+
return [
|
|
307
|
+
{name: `${invocation} ${words} ${cmd.usage()}`.trim(), reason: 'usage'},
|
|
308
|
+
{name: `${invocation} ${words} --help`, reason: 'what each argument is'},
|
|
309
|
+
];
|
|
310
|
+
}
|
|
311
|
+
if (code !== 'commander.optionMissingArgument') return undefined;
|
|
298
312
|
return [{name: `${parts.join(' ')} ${cmd.usage()}`.trim(), reason: 'usage'}];
|
|
299
313
|
}
|
|
300
314
|
|
|
315
|
+
/**
|
|
316
|
+
* The theme editor's message for a missing argument: what the command takes
|
|
317
|
+
* and the words it was given, in order.
|
|
318
|
+
* @param {unknown} err
|
|
319
|
+
* @param {string} message Commander's message
|
|
320
|
+
*/
|
|
321
|
+
function editorMissingMessage(err, message) {
|
|
322
|
+
const cmd = /** @type {any} */ (err)?.[REJECTED_COMMAND];
|
|
323
|
+
const given = /** @type {string[]} */ (cmd?.args ?? []);
|
|
324
|
+
const wants = (cmd?.registeredArguments ?? [])
|
|
325
|
+
.filter((/** @type {any} */ a) => a.required)
|
|
326
|
+
.map((/** @type {any} */ a) => `<${a.name()}>`);
|
|
327
|
+
const missing = /'([^']+)'/.exec(message)?.[1];
|
|
328
|
+
return `${cmd.name()} takes ${wants.join(' ')}, and ${given.length ? `was given ${given.length} (${given.join(' ')}), read as ${wants.slice(0, given.length).join(' ')}` : 'was given none'}: ${missing ? `<${missing}>` : 'an argument'} is missing.`;
|
|
329
|
+
}
|
|
330
|
+
|
|
301
331
|
/** Marks a command whose `command`/`addCommand` already self-install the shim. */
|
|
302
332
|
const SELF_INSTALLING = Symbol.for('astryx.jsonShim.selfInstalling');
|
|
303
333
|
|
|
@@ -469,8 +499,14 @@ export function handleCommanderError(err) {
|
|
|
469
499
|
|
|
470
500
|
// Real error paths. Strip Commander's "error: " prefix once: in the envelope
|
|
471
501
|
// the key is already `error`, and in text mode the Astryx prefix replaces it.
|
|
472
|
-
const cleaned = message.replace(/^error:\s*/i, '');
|
|
473
502
|
const suggestions = usageSuggestion(err, code);
|
|
503
|
+
// In the theme editor a missing argument names what was given: in
|
|
504
|
+
// `set corners small` the first word is read as the theme, so "value" alone
|
|
505
|
+
// would name the wrong thing.
|
|
506
|
+
const cleaned =
|
|
507
|
+
suggestions?.length === 2
|
|
508
|
+
? editorMissingMessage(err, message)
|
|
509
|
+
: message.replace(/^error:\s*/i, '');
|
|
474
510
|
if (jsonActive()) {
|
|
475
511
|
emitJsonError(
|
|
476
512
|
cleaned,
|
|
@@ -482,6 +518,8 @@ export function handleCommanderError(err) {
|
|
|
482
518
|
// same as every other CLI error — the `Error: …` line cliError prints.
|
|
483
519
|
process.stderr.write(`Error: ${cleaned}\n`);
|
|
484
520
|
if (suggestions) process.stderr.write(`Usage: ${suggestions[0].name}\n`);
|
|
521
|
+
if (suggestions?.[1])
|
|
522
|
+
process.stderr.write(`Run: ${suggestions[1].name}\n`);
|
|
485
523
|
}
|
|
486
524
|
process.exit(exitCode || 1);
|
|
487
525
|
}
|