@astryxdesign/cli 0.7.15 → 0.7.16-canary.g54dd64e
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/pack-check.mjs +13 -7
- 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 +64 -27
- package/api/theme/build/build.mjs +341 -69
- package/api/theme/eject/eject.mjs +22 -1
- package/api/theme/template/template.d.mts +19 -0
- package/api/theme/template/template.mjs +102 -25
- 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 +33 -0
- package/api/theme-edit/_adapter.mjs +208 -31
- package/api/theme-edit/_check.d.mts +38 -0
- package/api/theme-edit/_check.mjs +1326 -211
- 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 +29 -0
- package/api/theme-edit/_context.mjs +329 -30
- package/api/theme-edit/_css.d.mts +60 -1
- package/api/theme-edit/_css.mjs +404 -28
- package/api/theme-edit/_edit.d.mts +9 -0
- package/api/theme-edit/_edit.mjs +1025 -126
- 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/_overview.mjs +2 -0
- package/api/theme-edit/_palette.d.mts +11 -0
- package/api/theme-edit/_palette.mjs +194 -65
- package/api/theme-edit/_parts.d.mts +16 -0
- package/api/theme-edit/_parts.mjs +59 -7
- package/api/theme-edit/_png.mjs +19 -14
- package/api/theme-edit/_preview-app.d.mts +3 -0
- package/api/theme-edit/_preview-app.mjs +843 -45
- package/api/theme-edit/_preview.d.mts +16 -3
- package/api/theme-edit/_preview.mjs +310 -29
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +46 -12
- package/api/theme-edit/_settings.d.mts +178 -5
- package/api/theme-edit/_settings.mjs +2035 -86
- package/api/theme-edit/_tables.d.mts +24 -0
- package/api/theme-edit/_tables.mjs +211 -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/api/upgrade/registry/registry.mjs +6 -1
- 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/package.json +1 -0
- 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/assets/templates/pages/dashboard/page.tsx +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 +190 -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 +168 -45
- 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/clients/cli/run.mjs +49 -0
- 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 +79 -15
- package/foundation/fs/paths.d.mts +31 -0
- package/foundation/fs/paths.mjs +43 -10
- 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
|
@@ -35,6 +35,7 @@ import {fileURLToPath} from 'node:url';
|
|
|
35
35
|
import {spawn} from 'node:child_process';
|
|
36
36
|
import {
|
|
37
37
|
getCliInvocation,
|
|
38
|
+
commandInFolder,
|
|
38
39
|
quoteCommandArgument,
|
|
39
40
|
} from '../../../foundation/env/package-manager.mjs';
|
|
40
41
|
import {isOutsideProject} from '../../../foundation/env/project-scope.mjs';
|
|
@@ -57,7 +58,11 @@ import {themeAdd} from '../../../api/theme/add/add.mjs';
|
|
|
57
58
|
import {themeRemove} from '../../../api/theme/remove/remove.mjs';
|
|
58
59
|
import {themeUse} from '../../../api/theme/use/use.mjs';
|
|
59
60
|
import {themeEject} from '../../../api/theme/eject/eject.mjs';
|
|
60
|
-
import {
|
|
61
|
+
import {
|
|
62
|
+
OUTSIDE_PROJECT_WARNING,
|
|
63
|
+
themeTemplate,
|
|
64
|
+
} from '../../../api/theme/template/template.mjs';
|
|
65
|
+
import {findPackageRoot} from '../../../foundation/fs/paths.mjs';
|
|
61
66
|
import {
|
|
62
67
|
themeListAvailable,
|
|
63
68
|
themeListCopySources,
|
|
@@ -73,9 +78,11 @@ import {
|
|
|
73
78
|
import {
|
|
74
79
|
printBatchTrailer,
|
|
75
80
|
printCompactTrailer,
|
|
76
|
-
|
|
81
|
+
setEditorFolderListener,
|
|
82
|
+
setPrivateVarErrorListener,
|
|
77
83
|
themeBuildFamily,
|
|
78
84
|
themeBuildForReport,
|
|
85
|
+
themeBuildWithHandOff,
|
|
79
86
|
themeSourceFiles,
|
|
80
87
|
themeSourceGuesses,
|
|
81
88
|
writeDeferredBuildOutputs,
|
|
@@ -113,6 +120,8 @@ import {doc as themePaletteGenerateFn} from '../../../api/theme/themePaletteGene
|
|
|
113
120
|
* @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
121
|
* @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
122
|
* @property {(files: string[], options: {cwd: string}) => Promise<() => Promise<void>>} [hold] - Locks held while a build or check runs; resolves to their release.
|
|
123
|
+
* @property {(file: string, cwd: string) => {name: string, reason: string} | null} [missingSource] - For a source file that is not there, this group's way to write it again, or null.
|
|
124
|
+
* @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
125
|
*/
|
|
117
126
|
|
|
118
127
|
/** @type {ThemeCommandWords} */
|
|
@@ -222,6 +231,20 @@ function themeCommand(words, sub, args = [], reason = '') {
|
|
|
222
231
|
};
|
|
223
232
|
}
|
|
224
233
|
|
|
234
|
+
/**
|
|
235
|
+
* The message type a `theme build` child sends its watcher in place of a
|
|
236
|
+
* warning a build prints once per invocation (the --out editor-folder
|
|
237
|
+
* warning), so a watch session prints it once, not on every rebuild.
|
|
238
|
+
*/
|
|
239
|
+
const WATCH_WARNING = 'astryx.theme.build.warning';
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The `argv0` a watcher starts each `theme build` child with. With the IPC
|
|
243
|
+
* channel it marks the child as the watcher's own, so a CLI run another way
|
|
244
|
+
* with an IPC channel (forked by a tool or test runner) still prints.
|
|
245
|
+
*/
|
|
246
|
+
const WATCH_CHILD_ARGV0 = 'astryx-theme-watch';
|
|
247
|
+
|
|
225
248
|
/**
|
|
226
249
|
* Path to this CLI's real entry (clients/cli/bin/astryx.mjs), resolved from
|
|
227
250
|
* this module's location (clients/cli/commands/theme.mjs → ../bin/
|
|
@@ -244,9 +267,17 @@ function resolveCliBin() {
|
|
|
244
267
|
* @param {(child: import('node:child_process').ChildProcess) => void} [onSpawn] -
|
|
245
268
|
* Receives the child, so a watcher that stops can stop it too.
|
|
246
269
|
* @param {ThemeCommandWords} [words]
|
|
270
|
+
* @param {(message: unknown) => void} [onMessage] - Receives what the child
|
|
271
|
+
* hands over the channel (WATCH_WARNING messages).
|
|
247
272
|
* @returns {Promise<number>}
|
|
248
273
|
*/
|
|
249
|
-
function runThemeBuildOnceChild(
|
|
274
|
+
function runThemeBuildOnceChild(
|
|
275
|
+
file,
|
|
276
|
+
options,
|
|
277
|
+
onSpawn,
|
|
278
|
+
words = THEME_WORDS,
|
|
279
|
+
onMessage,
|
|
280
|
+
) {
|
|
250
281
|
const cliBin = resolveCliBin();
|
|
251
282
|
const command = [...words.group.split(' '), words.build];
|
|
252
283
|
// A detail level the user chose applies to every rebuild.
|
|
@@ -257,10 +288,15 @@ function runThemeBuildOnceChild(file, options, onSpawn, words = THEME_WORDS) {
|
|
|
257
288
|
if (options.iconsSpecifier)
|
|
258
289
|
args.push('--icons-specifier', options.iconsSpecifier);
|
|
259
290
|
return new Promise((/** @type {(code: number) => void} */ resolve) => {
|
|
291
|
+
// The IPC channel and argv0 tell the child it builds for this watcher: it
|
|
292
|
+
// hands its once-per-invocation warnings over the channel instead of
|
|
293
|
+
// printing them.
|
|
260
294
|
const child = spawn(process.execPath, args, {
|
|
261
|
-
|
|
295
|
+
argv0: WATCH_CHILD_ARGV0,
|
|
296
|
+
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
|
262
297
|
env: process.env,
|
|
263
298
|
});
|
|
299
|
+
child.on('message', message => onMessage?.(message));
|
|
264
300
|
onSpawn?.(child);
|
|
265
301
|
child.on('close', code => resolve(code ?? 0));
|
|
266
302
|
child.on('error', () => resolve(1));
|
|
@@ -290,9 +326,29 @@ async function runThemeBuildWatch(entries, options, words = THEME_WORDS) {
|
|
|
290
326
|
.map(e => rel(e.filePath))
|
|
291
327
|
.join(', ')} for changes — press Ctrl-C to stop.`;
|
|
292
328
|
|
|
329
|
+
// A warning a build prints once per invocation is printed at most once
|
|
330
|
+
// per watch session (spec:AST-017 FR29a), not on every rebuild.
|
|
331
|
+
/** @type {Set<string>} each warning once, whichever build printed it */
|
|
332
|
+
const warned = new Set();
|
|
333
|
+
// Watch never runs under --json, so the logger prints (cli-surface INV12).
|
|
334
|
+
logger.setSilent(false);
|
|
335
|
+
const onMessage = (/** @type {unknown} */ message) => {
|
|
336
|
+
const m = /** @type {{type?: unknown, text?: unknown}} */ (message);
|
|
337
|
+
if (m?.type !== WATCH_WARNING || typeof m.text !== 'string') return;
|
|
338
|
+
if (warned.has(m.text)) return;
|
|
339
|
+
warned.add(m.text);
|
|
340
|
+
logger.warn(m.text);
|
|
341
|
+
};
|
|
342
|
+
|
|
293
343
|
// Initial build.
|
|
294
344
|
for (const entry of entries) {
|
|
295
|
-
await runThemeBuildOnceChild(
|
|
345
|
+
await runThemeBuildOnceChild(
|
|
346
|
+
entry.file,
|
|
347
|
+
options,
|
|
348
|
+
undefined,
|
|
349
|
+
words,
|
|
350
|
+
onMessage,
|
|
351
|
+
);
|
|
296
352
|
}
|
|
297
353
|
|
|
298
354
|
let building = false;
|
|
@@ -323,6 +379,7 @@ async function runThemeBuildWatch(entries, options, words = THEME_WORDS) {
|
|
|
323
379
|
rebuildChild = child;
|
|
324
380
|
},
|
|
325
381
|
words,
|
|
382
|
+
onMessage,
|
|
326
383
|
);
|
|
327
384
|
rebuildDone = done.then(() => {});
|
|
328
385
|
await done;
|
|
@@ -645,11 +702,35 @@ function printThemeEject(result, words = THEME_WORDS) {
|
|
|
645
702
|
]
|
|
646
703
|
: []),
|
|
647
704
|
text(
|
|
648
|
-
`This is a local fork. Build it with ${getCliInvocation()
|
|
705
|
+
`This is a local fork. Build it with ${buildStep(getCliInvocation(), words, path.join(data.outputDir, data.entry))}.`,
|
|
649
706
|
),
|
|
650
707
|
);
|
|
651
708
|
}
|
|
652
709
|
|
|
710
|
+
/**
|
|
711
|
+
* The build command for a theme file a command just wrote, as it works from
|
|
712
|
+
* the current folder: a build writes its outputs beside the source and only
|
|
713
|
+
* inside the folder it runs from, so a file above that folder is built from
|
|
714
|
+
* the project root (`cd ../.. && … theme build theme.template.ts`).
|
|
715
|
+
* @param {string} invocation
|
|
716
|
+
* @param {{group: string, build: string}} words
|
|
717
|
+
* @param {string} file relative to the current folder
|
|
718
|
+
*/
|
|
719
|
+
function buildStep(invocation, words, file) {
|
|
720
|
+
const cwd = process.cwd();
|
|
721
|
+
const abs = path.resolve(cwd, file);
|
|
722
|
+
const rel = path.relative(cwd, abs);
|
|
723
|
+
const posix = (/** @type {string} */ p) => p.split(path.sep).join('/');
|
|
724
|
+
if (!rel.startsWith('..'))
|
|
725
|
+
return `${invocation} ${words.group} ${words.build} ${quoteCommandArgument(posix(rel))}`;
|
|
726
|
+
const root = findPackageRoot(path.dirname(abs)) ?? path.dirname(abs);
|
|
727
|
+
// The shell's own form of "in that folder" (PowerShell has no &&).
|
|
728
|
+
return commandInFolder(
|
|
729
|
+
posix(path.relative(cwd, root)),
|
|
730
|
+
`${invocation} ${words.group} ${words.build} ${quoteCommandArgument(posix(path.relative(root, abs)))}`,
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
|
|
653
734
|
/**
|
|
654
735
|
* The CommandDocs one copy of the theme subcommands is built from.
|
|
655
736
|
* @typedef {object} ThemeCommandDocs
|
|
@@ -884,30 +965,37 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
884
965
|
const guesses = looksGlobby
|
|
885
966
|
? []
|
|
886
967
|
: themeSourceGuesses(entry.file, process.cwd());
|
|
968
|
+
// An editor theme's own source, deleted by hand: the editor writes
|
|
969
|
+
// it again.
|
|
970
|
+
const rewrite = looksGlobby
|
|
971
|
+
? null
|
|
972
|
+
: (words.missingSource?.(entry.file, process.cwd()) ?? null);
|
|
887
973
|
return cliError(`File not found: ${entry.filePath}`, {
|
|
888
974
|
code: ERROR_CODES.ERR_FILE_NOT_FOUND,
|
|
889
|
-
suggestions:
|
|
890
|
-
? [
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
975
|
+
suggestions: rewrite
|
|
976
|
+
? [rewrite]
|
|
977
|
+
: looksGlobby
|
|
978
|
+
? [
|
|
979
|
+
{
|
|
980
|
+
// The pattern stays unquoted: the shell expands it.
|
|
981
|
+
name: `${getCliInvocation(process.cwd())} ${words.group} ${words.build} ${entry.file.replace(/['"]/g, '')}`,
|
|
982
|
+
reason:
|
|
983
|
+
'globs are expanded by your shell; pass the pattern unquoted, or list the files',
|
|
984
|
+
},
|
|
985
|
+
]
|
|
986
|
+
: guesses.length > 0
|
|
987
|
+
? guesses.map(guess => ({
|
|
988
|
+
name: `${getCliInvocation(process.cwd())} ${words.group} ${words.build} ${quoteCommandArgument(guess)}`,
|
|
989
|
+
reason: 'a theme source that exists',
|
|
990
|
+
}))
|
|
991
|
+
: [
|
|
992
|
+
themeCommand(
|
|
993
|
+
words,
|
|
994
|
+
'template',
|
|
995
|
+
['theme.template.ts'],
|
|
996
|
+
'start a theme source from the annotated template',
|
|
997
|
+
),
|
|
998
|
+
],
|
|
911
999
|
});
|
|
912
1000
|
}
|
|
913
1001
|
|
|
@@ -1074,10 +1162,25 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1074
1162
|
// [ok]/[warn] lines, and the install instructions are all emitted from
|
|
1075
1163
|
// inside themeBuild via the shared logger.
|
|
1076
1164
|
logger.setSilent(json);
|
|
1165
|
+
// Started by a watcher (runThemeBuildWatch): hand the editor-folder
|
|
1166
|
+
// warning to it, and let the channel not keep this build alive.
|
|
1167
|
+
const watchChild =
|
|
1168
|
+
typeof process.send === 'function' &&
|
|
1169
|
+
process.argv0 === WATCH_CHILD_ARGV0;
|
|
1170
|
+
if (watchChild) {
|
|
1171
|
+
process.channel?.unref();
|
|
1172
|
+
setEditorFolderListener(warning => {
|
|
1173
|
+
// Held open until the message is out, then let go again.
|
|
1174
|
+
process.channel?.ref();
|
|
1175
|
+
process.send?.({type: WATCH_WARNING, text: warning}, () =>
|
|
1176
|
+
process.channel?.unref(),
|
|
1177
|
+
);
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1077
1180
|
let privateVarError = false;
|
|
1078
|
-
|
|
1181
|
+
setPrivateVarErrorListener(() => {
|
|
1079
1182
|
privateVarError = true;
|
|
1080
|
-
};
|
|
1183
|
+
});
|
|
1081
1184
|
|
|
1082
1185
|
const refused = await words.preflight?.(files, {
|
|
1083
1186
|
cwd: process.cwd(),
|
|
@@ -1094,15 +1197,19 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1094
1197
|
familyKey: /** @type {string} */ (options.familyKey),
|
|
1095
1198
|
check: options.check,
|
|
1096
1199
|
iconsSpecifier: options.iconsSpecifier,
|
|
1097
|
-
__onPrivateVarError: onPrivateVarError,
|
|
1098
|
-
__commandWords: words,
|
|
1099
1200
|
},
|
|
1100
1201
|
{cwd: process.cwd()},
|
|
1202
|
+
{commandWords: words},
|
|
1101
1203
|
);
|
|
1102
1204
|
if (json) jsonOut(result);
|
|
1103
1205
|
if (
|
|
1104
1206
|
privateVarError ||
|
|
1105
|
-
(result.type === 'theme.build.check' &&
|
|
1207
|
+
(result.type === 'theme.build.check' &&
|
|
1208
|
+
!(
|
|
1209
|
+
/** @type {import('../../../api/theme/theme.type.mjs').ThemeBuildCheckResponse} */ (
|
|
1210
|
+
result
|
|
1211
|
+
).data.upToDate
|
|
1212
|
+
))
|
|
1106
1213
|
) {
|
|
1107
1214
|
process.exitCode = 1;
|
|
1108
1215
|
}
|
|
@@ -1173,10 +1280,12 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1173
1280
|
out: options.out,
|
|
1174
1281
|
check: options.check,
|
|
1175
1282
|
iconsSpecifier: options.iconsSpecifier,
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1283
|
+
};
|
|
1284
|
+
/** @type {import('../../../api/theme/build/build.mjs').ThemeBuildHandOff} */
|
|
1285
|
+
const handOff = {
|
|
1286
|
+
claimedOutputs,
|
|
1287
|
+
deferredWrites: deferred ? writes : undefined,
|
|
1288
|
+
commandWords: words,
|
|
1180
1289
|
};
|
|
1181
1290
|
let result;
|
|
1182
1291
|
if (report) {
|
|
@@ -1185,6 +1294,7 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1185
1294
|
buildOptions,
|
|
1186
1295
|
{cwd: process.cwd()},
|
|
1187
1296
|
{compact},
|
|
1297
|
+
handOff,
|
|
1188
1298
|
);
|
|
1189
1299
|
result = built.receipt;
|
|
1190
1300
|
if (built.trailer) trailers.push(built.trailer);
|
|
@@ -1200,9 +1310,12 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1200
1310
|
else show();
|
|
1201
1311
|
}
|
|
1202
1312
|
} else {
|
|
1203
|
-
result = await
|
|
1204
|
-
|
|
1205
|
-
|
|
1313
|
+
result = await themeBuildWithHandOff(
|
|
1314
|
+
entry.file,
|
|
1315
|
+
buildOptions,
|
|
1316
|
+
{cwd: process.cwd()},
|
|
1317
|
+
handOff,
|
|
1318
|
+
);
|
|
1206
1319
|
}
|
|
1207
1320
|
logger.log = log;
|
|
1208
1321
|
logger.warn = warn;
|
|
@@ -1471,6 +1584,9 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1471
1584
|
const json = program.opts().json || false;
|
|
1472
1585
|
/** @type {import('../../../api/theme/theme.type.mjs').ThemeEjectResponse} */
|
|
1473
1586
|
let result;
|
|
1587
|
+
// Eject's warnings go to stderr in text mode; the logger is silent
|
|
1588
|
+
// under --json (cli-surface INV12).
|
|
1589
|
+
logger.setSilent(json);
|
|
1474
1590
|
try {
|
|
1475
1591
|
result = await themeEject(slug, {
|
|
1476
1592
|
targetPath,
|
|
@@ -1503,7 +1619,9 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1503
1619
|
/** @type {import('../../../api/theme/theme.type.mjs').ThemeTemplateResponse} */
|
|
1504
1620
|
let result;
|
|
1505
1621
|
try {
|
|
1506
|
-
|
|
1622
|
+
// The experimental command passes its own write, which protects
|
|
1623
|
+
// only the editor's own files.
|
|
1624
|
+
result = (words.template ?? themeTemplate)({
|
|
1507
1625
|
targetPath,
|
|
1508
1626
|
overwrite: options.overwrite,
|
|
1509
1627
|
cwd: process.cwd(),
|
|
@@ -1512,15 +1630,22 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1512
1630
|
const err =
|
|
1513
1631
|
/** @type {import('../../../api/error.mjs').AstryxError} */ (e);
|
|
1514
1632
|
return themeError(err, words, [
|
|
1633
|
+
// No path: the template at the project root, from any folder.
|
|
1515
1634
|
themeCommand(
|
|
1516
1635
|
words,
|
|
1517
1636
|
'template',
|
|
1518
|
-
[
|
|
1637
|
+
[],
|
|
1519
1638
|
'write the template at the project root',
|
|
1520
1639
|
),
|
|
1521
1640
|
]);
|
|
1522
1641
|
}
|
|
1523
1642
|
|
|
1643
|
+
// Outside a project the template is written here, with one warning
|
|
1644
|
+
// on stderr when a file was written; the logger is silent under --json
|
|
1645
|
+
// (cli-surface INV12).
|
|
1646
|
+
logger.setSilent(json);
|
|
1647
|
+
if (result.data.written && !findPackageRoot(process.cwd()))
|
|
1648
|
+
logger.warn(OUTSIDE_PROJECT_WARNING);
|
|
1524
1649
|
// Writes a starter theme file, or declines to overwrite one.
|
|
1525
1650
|
if (json) {
|
|
1526
1651
|
jsonOut(result);
|
|
@@ -1551,9 +1676,7 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1551
1676
|
'It documents every defineTheme field, the token families, and the component override syntax. ' +
|
|
1552
1677
|
'Copy what you need into your own theme file, then delete it.',
|
|
1553
1678
|
),
|
|
1554
|
-
code(
|
|
1555
|
-
`${invocation} ${words.group} ${words.build} ${quoteCommandArgument(result.data.path)}`,
|
|
1556
|
-
),
|
|
1679
|
+
code(buildStep(invocation, words, result.data.path)),
|
|
1557
1680
|
);
|
|
1558
1681
|
return NO_RESULT_SET;
|
|
1559
1682
|
},
|
|
@@ -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
|
}
|