@astryxdesign/cli 0.7.15 → 0.7.16-canary.g07c77c0
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/build/_adapter.d.mts +1 -0
- package/api/build/blocks/blocks.d.mts +1 -0
- package/api/build/blocks/blocks.mjs +18 -1
- 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 +43 -0
- package/api/doctor/built-checks.mjs +1 -1
- package/api/doctor/doctor.mjs +18 -4
- package/api/doctor/theme-checks.mjs +1 -1
- package/api/integration/add-contribution.mjs +3 -3
- package/api/integration/pack-check.mjs +14 -8
- package/api/integration/validate-integration.mjs +1 -1
- package/api/search/_adapter.mjs +15 -16
- package/api/search/_entries.d.mts +2 -1
- package/api/search/_entries.mjs +28 -1
- package/api/swizzle/_moduleGraph.mjs +1 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +43 -12
- package/api/theme/_fork.mjs +1 -1
- package/api/theme/build/build.d.mts +116 -32
- package/api/theme/build/build.mjs +449 -102
- 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 +32 -2
- package/api/theme-edit/_adapter.mjs +213 -36
- package/api/theme-edit/_check.d.mts +69 -3
- package/api/theme-edit/_check.mjs +1517 -218
- 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 +426 -40
- 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 +1300 -135
- 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 +33 -0
- package/api/theme-edit/_parts.mjs +138 -9
- package/api/theme-edit/_png.d.mts +18 -0
- package/api/theme-edit/_png.mjs +95 -14
- package/api/theme-edit/_preview-app.d.mts +9 -0
- package/api/theme-edit/_preview-app.mjs +1191 -71
- package/api/theme-edit/_preview.d.mts +16 -3
- package/api/theme-edit/_preview.mjs +335 -30
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +46 -12
- package/api/theme-edit/_settings.d.mts +240 -5
- package/api/theme-edit/_settings.mjs +2561 -115
- 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/codemods/parse.mjs +2 -2
- 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/authoring/shadcn/source-variants.d.mts +1 -1
- package/authoring/shadcn/source-variants.mjs +32 -10
- 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 +237 -45
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- 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-preview-add.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 +190 -46
- 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 +72 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/clients/cli/run.mjs +49 -0
- package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
- package/foundation/agent-docs/agent-docs-target.mjs +9 -17
- package/foundation/agent-docs/agent-docs.mjs +3 -2
- package/foundation/config/config-writer.mjs +2 -2
- package/foundation/config/project.mjs +60 -14
- package/foundation/discovery/component-discovery.mjs +5 -17
- package/foundation/discovery/icon-set-writer.mjs +1 -1
- package/foundation/discovery/module-exports.mjs +1 -15
- package/foundation/discovery/template-adapter.mjs +44 -19
- package/foundation/discovery/template-source-tree.mjs +3 -16
- package/foundation/discovery/theme-discovery.d.mts +5 -1
- package/foundation/discovery/theme-discovery.mjs +30 -35
- package/foundation/fs/exact-codec.d.mts +35 -0
- package/foundation/fs/exact-codec.mjs +148 -0
- package/foundation/fs/gather-cache.d.mts +15 -5
- package/foundation/fs/gather-cache.mjs +123 -30
- package/foundation/fs/paths.d.mts +39 -0
- package/foundation/fs/paths.mjs +44 -11
- package/foundation/fs/read-record.mjs +11 -1
- package/foundation/integrations/contribution-fixes.mjs +1 -16
- package/foundation/integrations/may-have-integrations.mjs +3 -2
- package/foundation/integrations/public-imports.mjs +1 -1
- package/foundation/render/embedded-imports.mjs +1 -1
- 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/foundation/runtime/lazy-dependencies.d.mts +14 -0
- package/foundation/runtime/lazy-dependencies.mjs +82 -0
- package/foundation/xle/browser.d.mts +2 -2
- 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,11 +78,14 @@ 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,
|
|
88
|
+
buildSuggestion,
|
|
81
89
|
writeDeferredBuildOutputs,
|
|
82
90
|
} from '../../../api/theme/build/build.mjs';
|
|
83
91
|
import {defineCommand} from '../lib/define-command.mjs';
|
|
@@ -111,8 +119,10 @@ import {doc as themePaletteGenerateFn} from '../../../api/theme/themePaletteGene
|
|
|
111
119
|
* @property {string} group - The group's command path: `theme` or `experimental theme`.
|
|
112
120
|
* @property {string} build - The build subcommand's name: `build` or `compile`.
|
|
113
121
|
* @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
|
-
* @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.
|
|
122
|
+
* @property {(files: string[], options: {cwd: string, check?: boolean, family?: boolean, iconsSpecifier?: string, out?: string}) => Promise<import('../../../api/error.mjs').AstryxError | null>} [preflight] - A refusal before a build starts, or null.
|
|
115
123
|
* @property {(files: string[], options: {cwd: string}) => Promise<() => Promise<void>>} [hold] - Locks held while a build or check runs; resolves to their release.
|
|
124
|
+
* @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.
|
|
125
|
+
* @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
126
|
*/
|
|
117
127
|
|
|
118
128
|
/** @type {ThemeCommandWords} */
|
|
@@ -222,6 +232,20 @@ function themeCommand(words, sub, args = [], reason = '') {
|
|
|
222
232
|
};
|
|
223
233
|
}
|
|
224
234
|
|
|
235
|
+
/**
|
|
236
|
+
* The message type a `theme build` child sends its watcher in place of a
|
|
237
|
+
* warning a build prints once per invocation (the --out editor-folder
|
|
238
|
+
* warning), so a watch session prints it once, not on every rebuild.
|
|
239
|
+
*/
|
|
240
|
+
const WATCH_WARNING = 'astryx.theme.build.warning';
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The `argv0` a watcher starts each `theme build` child with. With the IPC
|
|
244
|
+
* channel it marks the child as the watcher's own, so a CLI run another way
|
|
245
|
+
* with an IPC channel (forked by a tool or test runner) still prints.
|
|
246
|
+
*/
|
|
247
|
+
const WATCH_CHILD_ARGV0 = 'astryx-theme-watch';
|
|
248
|
+
|
|
225
249
|
/**
|
|
226
250
|
* Path to this CLI's real entry (clients/cli/bin/astryx.mjs), resolved from
|
|
227
251
|
* this module's location (clients/cli/commands/theme.mjs → ../bin/
|
|
@@ -244,9 +268,17 @@ function resolveCliBin() {
|
|
|
244
268
|
* @param {(child: import('node:child_process').ChildProcess) => void} [onSpawn] -
|
|
245
269
|
* Receives the child, so a watcher that stops can stop it too.
|
|
246
270
|
* @param {ThemeCommandWords} [words]
|
|
271
|
+
* @param {(message: unknown) => void} [onMessage] - Receives what the child
|
|
272
|
+
* hands over the channel (WATCH_WARNING messages).
|
|
247
273
|
* @returns {Promise<number>}
|
|
248
274
|
*/
|
|
249
|
-
function runThemeBuildOnceChild(
|
|
275
|
+
function runThemeBuildOnceChild(
|
|
276
|
+
file,
|
|
277
|
+
options,
|
|
278
|
+
onSpawn,
|
|
279
|
+
words = THEME_WORDS,
|
|
280
|
+
onMessage,
|
|
281
|
+
) {
|
|
250
282
|
const cliBin = resolveCliBin();
|
|
251
283
|
const command = [...words.group.split(' '), words.build];
|
|
252
284
|
// A detail level the user chose applies to every rebuild.
|
|
@@ -257,10 +289,15 @@ function runThemeBuildOnceChild(file, options, onSpawn, words = THEME_WORDS) {
|
|
|
257
289
|
if (options.iconsSpecifier)
|
|
258
290
|
args.push('--icons-specifier', options.iconsSpecifier);
|
|
259
291
|
return new Promise((/** @type {(code: number) => void} */ resolve) => {
|
|
292
|
+
// The IPC channel and argv0 tell the child it builds for this watcher: it
|
|
293
|
+
// hands its once-per-invocation warnings over the channel instead of
|
|
294
|
+
// printing them.
|
|
260
295
|
const child = spawn(process.execPath, args, {
|
|
261
|
-
|
|
296
|
+
argv0: WATCH_CHILD_ARGV0,
|
|
297
|
+
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
|
262
298
|
env: process.env,
|
|
263
299
|
});
|
|
300
|
+
child.on('message', message => onMessage?.(message));
|
|
264
301
|
onSpawn?.(child);
|
|
265
302
|
child.on('close', code => resolve(code ?? 0));
|
|
266
303
|
child.on('error', () => resolve(1));
|
|
@@ -290,9 +327,29 @@ async function runThemeBuildWatch(entries, options, words = THEME_WORDS) {
|
|
|
290
327
|
.map(e => rel(e.filePath))
|
|
291
328
|
.join(', ')} for changes — press Ctrl-C to stop.`;
|
|
292
329
|
|
|
330
|
+
// A warning a build prints once per invocation is printed at most once
|
|
331
|
+
// per watch session (spec:AST-017 FR29a), not on every rebuild.
|
|
332
|
+
/** @type {Set<string>} each warning once, whichever build printed it */
|
|
333
|
+
const warned = new Set();
|
|
334
|
+
// Watch never runs under --json, so the logger prints (cli-surface INV12).
|
|
335
|
+
logger.setSilent(false);
|
|
336
|
+
const onMessage = (/** @type {unknown} */ message) => {
|
|
337
|
+
const m = /** @type {{type?: unknown, text?: unknown}} */ (message);
|
|
338
|
+
if (m?.type !== WATCH_WARNING || typeof m.text !== 'string') return;
|
|
339
|
+
if (warned.has(m.text)) return;
|
|
340
|
+
warned.add(m.text);
|
|
341
|
+
logger.warn(m.text);
|
|
342
|
+
};
|
|
343
|
+
|
|
293
344
|
// Initial build.
|
|
294
345
|
for (const entry of entries) {
|
|
295
|
-
await runThemeBuildOnceChild(
|
|
346
|
+
await runThemeBuildOnceChild(
|
|
347
|
+
entry.file,
|
|
348
|
+
options,
|
|
349
|
+
undefined,
|
|
350
|
+
words,
|
|
351
|
+
onMessage,
|
|
352
|
+
);
|
|
296
353
|
}
|
|
297
354
|
|
|
298
355
|
let building = false;
|
|
@@ -323,6 +380,7 @@ async function runThemeBuildWatch(entries, options, words = THEME_WORDS) {
|
|
|
323
380
|
rebuildChild = child;
|
|
324
381
|
},
|
|
325
382
|
words,
|
|
383
|
+
onMessage,
|
|
326
384
|
);
|
|
327
385
|
rebuildDone = done.then(() => {});
|
|
328
386
|
await done;
|
|
@@ -645,11 +703,35 @@ function printThemeEject(result, words = THEME_WORDS) {
|
|
|
645
703
|
]
|
|
646
704
|
: []),
|
|
647
705
|
text(
|
|
648
|
-
`This is a local fork. Build it with ${getCliInvocation()
|
|
706
|
+
`This is a local fork. Build it with ${buildStep(getCliInvocation(), words, path.join(data.outputDir, data.entry))}.`,
|
|
649
707
|
),
|
|
650
708
|
);
|
|
651
709
|
}
|
|
652
710
|
|
|
711
|
+
/**
|
|
712
|
+
* The build command for a theme file a command just wrote, as it works from
|
|
713
|
+
* the current folder: a build writes its outputs beside the source and only
|
|
714
|
+
* inside the folder it runs from, so a file above that folder is built from
|
|
715
|
+
* the project root (`cd ../.. && … theme build theme.template.ts`).
|
|
716
|
+
* @param {string} invocation
|
|
717
|
+
* @param {{group: string, build: string}} words
|
|
718
|
+
* @param {string} file relative to the current folder
|
|
719
|
+
*/
|
|
720
|
+
function buildStep(invocation, words, file) {
|
|
721
|
+
const cwd = process.cwd();
|
|
722
|
+
const abs = path.resolve(cwd, file);
|
|
723
|
+
const rel = path.relative(cwd, abs);
|
|
724
|
+
const posix = (/** @type {string} */ p) => p.split(path.sep).join('/');
|
|
725
|
+
if (!rel.startsWith('..'))
|
|
726
|
+
return `${invocation} ${words.group} ${words.build} ${quoteCommandArgument(posix(rel))}`;
|
|
727
|
+
const root = findPackageRoot(path.dirname(abs)) ?? path.dirname(abs);
|
|
728
|
+
// The shell's own form of "in that folder" (PowerShell has no &&).
|
|
729
|
+
return commandInFolder(
|
|
730
|
+
posix(path.relative(cwd, root)),
|
|
731
|
+
`${invocation} ${words.group} ${words.build} ${quoteCommandArgument(posix(path.relative(root, abs)))}`,
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
|
|
653
735
|
/**
|
|
654
736
|
* The CommandDocs one copy of the theme subcommands is built from.
|
|
655
737
|
* @typedef {object} ThemeCommandDocs
|
|
@@ -884,30 +966,52 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
884
966
|
const guesses = looksGlobby
|
|
885
967
|
? []
|
|
886
968
|
: themeSourceGuesses(entry.file, process.cwd());
|
|
969
|
+
// An editor theme's own source, deleted by hand: the editor writes
|
|
970
|
+
// it again.
|
|
971
|
+
const rewrite = looksGlobby
|
|
972
|
+
? null
|
|
973
|
+
: (words.missingSource?.(entry.file, process.cwd()) ?? null);
|
|
887
974
|
return cliError(`File not found: ${entry.filePath}`, {
|
|
888
975
|
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
|
-
|
|
976
|
+
suggestions: rewrite
|
|
977
|
+
? [rewrite]
|
|
978
|
+
: looksGlobby
|
|
979
|
+
? [
|
|
980
|
+
{
|
|
981
|
+
// The pattern stays unquoted: the shell expands it.
|
|
982
|
+
// The caller's mode follows it, quoted, and a family
|
|
983
|
+
// run stays one.
|
|
984
|
+
name: buildSuggestion(
|
|
985
|
+
entry.file,
|
|
986
|
+
options,
|
|
987
|
+
process.cwd(),
|
|
988
|
+
words,
|
|
989
|
+
{
|
|
990
|
+
glob: true,
|
|
991
|
+
family: Boolean(options.family),
|
|
992
|
+
...(options.family && options.familyKey
|
|
993
|
+
? {familyKey: String(options.familyKey)}
|
|
994
|
+
: {}),
|
|
995
|
+
},
|
|
996
|
+
),
|
|
997
|
+
reason:
|
|
998
|
+
'globs are expanded by your shell; pass the pattern unquoted, or list the files',
|
|
999
|
+
},
|
|
1000
|
+
]
|
|
1001
|
+
: guesses.length > 0
|
|
1002
|
+
? guesses.map(guess => ({
|
|
1003
|
+
// The same build of that source: a --check stays a check.
|
|
1004
|
+
name: buildSuggestion(guess, options, process.cwd(), words),
|
|
1005
|
+
reason: 'a theme source that exists',
|
|
1006
|
+
}))
|
|
1007
|
+
: [
|
|
1008
|
+
themeCommand(
|
|
1009
|
+
words,
|
|
1010
|
+
'template',
|
|
1011
|
+
['theme.template.ts'],
|
|
1012
|
+
'start a theme source from the annotated template',
|
|
1013
|
+
),
|
|
1014
|
+
],
|
|
911
1015
|
});
|
|
912
1016
|
}
|
|
913
1017
|
|
|
@@ -999,6 +1103,9 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
999
1103
|
...(options.out && files.length === 1
|
|
1000
1104
|
? ['--out', options.out]
|
|
1001
1105
|
: []),
|
|
1106
|
+
...(options.iconsSpecifier
|
|
1107
|
+
? ['--icons-specifier', options.iconsSpecifier]
|
|
1108
|
+
: []),
|
|
1002
1109
|
...(options.check ? ['--check'] : []),
|
|
1003
1110
|
],
|
|
1004
1111
|
'build each theme on its own',
|
|
@@ -1074,15 +1181,32 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1074
1181
|
// [ok]/[warn] lines, and the install instructions are all emitted from
|
|
1075
1182
|
// inside themeBuild via the shared logger.
|
|
1076
1183
|
logger.setSilent(json);
|
|
1184
|
+
// Started by a watcher (runThemeBuildWatch): hand the editor-folder
|
|
1185
|
+
// warning to it, and let the channel not keep this build alive.
|
|
1186
|
+
const watchChild =
|
|
1187
|
+
typeof process.send === 'function' &&
|
|
1188
|
+
process.argv0 === WATCH_CHILD_ARGV0;
|
|
1189
|
+
if (watchChild) {
|
|
1190
|
+
process.channel?.unref();
|
|
1191
|
+
setEditorFolderListener(warning => {
|
|
1192
|
+
// Held open until the message is out, then let go again.
|
|
1193
|
+
process.channel?.ref();
|
|
1194
|
+
process.send?.({type: WATCH_WARNING, text: warning}, () =>
|
|
1195
|
+
process.channel?.unref(),
|
|
1196
|
+
);
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1077
1199
|
let privateVarError = false;
|
|
1078
|
-
|
|
1200
|
+
setPrivateVarErrorListener(() => {
|
|
1079
1201
|
privateVarError = true;
|
|
1080
|
-
};
|
|
1202
|
+
});
|
|
1081
1203
|
|
|
1082
1204
|
const refused = await words.preflight?.(files, {
|
|
1083
1205
|
cwd: process.cwd(),
|
|
1084
1206
|
check: options.check,
|
|
1085
1207
|
family: Boolean(options.family),
|
|
1208
|
+
iconsSpecifier: options.iconsSpecifier,
|
|
1209
|
+
out: options.out,
|
|
1086
1210
|
});
|
|
1087
1211
|
if (refused) return themeError(refused, words, buildFallback);
|
|
1088
1212
|
|
|
@@ -1094,15 +1218,19 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1094
1218
|
familyKey: /** @type {string} */ (options.familyKey),
|
|
1095
1219
|
check: options.check,
|
|
1096
1220
|
iconsSpecifier: options.iconsSpecifier,
|
|
1097
|
-
__onPrivateVarError: onPrivateVarError,
|
|
1098
|
-
__commandWords: words,
|
|
1099
1221
|
},
|
|
1100
1222
|
{cwd: process.cwd()},
|
|
1223
|
+
{commandWords: words},
|
|
1101
1224
|
);
|
|
1102
1225
|
if (json) jsonOut(result);
|
|
1103
1226
|
if (
|
|
1104
1227
|
privateVarError ||
|
|
1105
|
-
(result.type === 'theme.build.check' &&
|
|
1228
|
+
(result.type === 'theme.build.check' &&
|
|
1229
|
+
!(
|
|
1230
|
+
/** @type {import('../../../api/theme/theme.type.mjs').ThemeBuildCheckResponse} */ (
|
|
1231
|
+
result
|
|
1232
|
+
).data.upToDate
|
|
1233
|
+
))
|
|
1106
1234
|
) {
|
|
1107
1235
|
process.exitCode = 1;
|
|
1108
1236
|
}
|
|
@@ -1173,10 +1301,12 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1173
1301
|
out: options.out,
|
|
1174
1302
|
check: options.check,
|
|
1175
1303
|
iconsSpecifier: options.iconsSpecifier,
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1304
|
+
};
|
|
1305
|
+
/** @type {import('../../../api/theme/build/build.mjs').ThemeBuildHandOff} */
|
|
1306
|
+
const handOff = {
|
|
1307
|
+
claimedOutputs,
|
|
1308
|
+
deferredWrites: deferred ? writes : undefined,
|
|
1309
|
+
commandWords: words,
|
|
1180
1310
|
};
|
|
1181
1311
|
let result;
|
|
1182
1312
|
if (report) {
|
|
@@ -1185,6 +1315,7 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1185
1315
|
buildOptions,
|
|
1186
1316
|
{cwd: process.cwd()},
|
|
1187
1317
|
{compact},
|
|
1318
|
+
handOff,
|
|
1188
1319
|
);
|
|
1189
1320
|
result = built.receipt;
|
|
1190
1321
|
if (built.trailer) trailers.push(built.trailer);
|
|
@@ -1200,9 +1331,12 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1200
1331
|
else show();
|
|
1201
1332
|
}
|
|
1202
1333
|
} else {
|
|
1203
|
-
result = await
|
|
1204
|
-
|
|
1205
|
-
|
|
1334
|
+
result = await themeBuildWithHandOff(
|
|
1335
|
+
entry.file,
|
|
1336
|
+
buildOptions,
|
|
1337
|
+
{cwd: process.cwd()},
|
|
1338
|
+
handOff,
|
|
1339
|
+
);
|
|
1206
1340
|
}
|
|
1207
1341
|
logger.log = log;
|
|
1208
1342
|
logger.warn = warn;
|
|
@@ -1471,6 +1605,9 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1471
1605
|
const json = program.opts().json || false;
|
|
1472
1606
|
/** @type {import('../../../api/theme/theme.type.mjs').ThemeEjectResponse} */
|
|
1473
1607
|
let result;
|
|
1608
|
+
// Eject's warnings go to stderr in text mode; the logger is silent
|
|
1609
|
+
// under --json (cli-surface INV12).
|
|
1610
|
+
logger.setSilent(json);
|
|
1474
1611
|
try {
|
|
1475
1612
|
result = await themeEject(slug, {
|
|
1476
1613
|
targetPath,
|
|
@@ -1503,7 +1640,9 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1503
1640
|
/** @type {import('../../../api/theme/theme.type.mjs').ThemeTemplateResponse} */
|
|
1504
1641
|
let result;
|
|
1505
1642
|
try {
|
|
1506
|
-
|
|
1643
|
+
// The experimental command passes its own write, which protects
|
|
1644
|
+
// only the editor's own files.
|
|
1645
|
+
result = (words.template ?? themeTemplate)({
|
|
1507
1646
|
targetPath,
|
|
1508
1647
|
overwrite: options.overwrite,
|
|
1509
1648
|
cwd: process.cwd(),
|
|
@@ -1512,15 +1651,22 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1512
1651
|
const err =
|
|
1513
1652
|
/** @type {import('../../../api/error.mjs').AstryxError} */ (e);
|
|
1514
1653
|
return themeError(err, words, [
|
|
1654
|
+
// No path: the template at the project root, from any folder.
|
|
1515
1655
|
themeCommand(
|
|
1516
1656
|
words,
|
|
1517
1657
|
'template',
|
|
1518
|
-
[
|
|
1658
|
+
[],
|
|
1519
1659
|
'write the template at the project root',
|
|
1520
1660
|
),
|
|
1521
1661
|
]);
|
|
1522
1662
|
}
|
|
1523
1663
|
|
|
1664
|
+
// Outside a project the template is written here, with one warning
|
|
1665
|
+
// on stderr when a file was written; the logger is silent under --json
|
|
1666
|
+
// (cli-surface INV12).
|
|
1667
|
+
logger.setSilent(json);
|
|
1668
|
+
if (result.data.written && !findPackageRoot(process.cwd()))
|
|
1669
|
+
logger.warn(OUTSIDE_PROJECT_WARNING);
|
|
1524
1670
|
// Writes a starter theme file, or declines to overwrite one.
|
|
1525
1671
|
if (json) {
|
|
1526
1672
|
jsonOut(result);
|
|
@@ -1551,9 +1697,7 @@ function registerThemeCommands(theme, program, docs, words) {
|
|
|
1551
1697
|
'It documents every defineTheme field, the token families, and the component override syntax. ' +
|
|
1552
1698
|
'Copy what you need into your own theme file, then delete it.',
|
|
1553
1699
|
),
|
|
1554
|
-
code(
|
|
1555
|
-
`${invocation} ${words.group} ${words.build} ${quoteCommandArgument(result.data.path)}`,
|
|
1556
|
-
),
|
|
1700
|
+
code(buildStep(invocation, words, result.data.path)),
|
|
1557
1701
|
);
|
|
1558
1702
|
return NO_RESULT_SET;
|
|
1559
1703
|
},
|
|
@@ -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,75 @@ 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
|
+
return editorMissingSuggestions(cmd);
|
|
305
|
+
if (code !== 'commander.optionMissingArgument') return undefined;
|
|
298
306
|
return [{name: `${parts.join(' ')} ${cmd.usage()}`.trim(), reason: 'usage'}];
|
|
299
307
|
}
|
|
300
308
|
|
|
309
|
+
/**
|
|
310
|
+
* The theme editor's message for a missing argument: what the command takes
|
|
311
|
+
* and the words it was given, in order.
|
|
312
|
+
* @param {unknown} err
|
|
313
|
+
* @param {string} message Commander's message
|
|
314
|
+
*/
|
|
315
|
+
function editorMissingMessage(err, message) {
|
|
316
|
+
const cmd = /** @type {any} */ (err)?.[REJECTED_COMMAND];
|
|
317
|
+
const wants = (cmd?.registeredArguments ?? [])
|
|
318
|
+
.filter((/** @type {any} */ a) => a.required)
|
|
319
|
+
.map((/** @type {any} */ a) => a.name());
|
|
320
|
+
return editorMissingArgument(
|
|
321
|
+
cmd,
|
|
322
|
+
wants,
|
|
323
|
+
/'([^']+)'/.exec(message)?.[1],
|
|
324
|
+
).message;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* The theme editor's usage and help suggestions for a missing argument, as
|
|
329
|
+
* the project runs the CLI.
|
|
330
|
+
* @param {any} cmd
|
|
331
|
+
* @returns {Array<{name: string, reason: string}>}
|
|
332
|
+
*/
|
|
333
|
+
function editorMissingSuggestions(cmd) {
|
|
334
|
+
const parts = [];
|
|
335
|
+
for (let node = cmd; node; node = node.parent) parts.unshift(node.name());
|
|
336
|
+
const words = parts.slice(1).join(' ');
|
|
337
|
+
const invocation = getCliInvocation(process.cwd());
|
|
338
|
+
return [
|
|
339
|
+
{name: `${invocation} ${words} ${cmd.usage()}`.trim(), reason: 'usage'},
|
|
340
|
+
{name: `${invocation} ${words} --help`, reason: 'what each argument is'},
|
|
341
|
+
];
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* The theme editor's missing-argument report: what the command takes, the
|
|
346
|
+
* words it was given and what each was read as, and its usage and help.
|
|
347
|
+
* The parser's error uses it, and so does a command that checks its own
|
|
348
|
+
* arguments (set, whose value may come inside a pasted declaration).
|
|
349
|
+
* @param {any} cmd the Commander command
|
|
350
|
+
* @param {string[]} wants the argument names it takes, in order
|
|
351
|
+
* @param {string | undefined} missing the argument that is missing
|
|
352
|
+
* @returns {{message: string, suggestions: Array<{name: string, reason: string}>}}
|
|
353
|
+
*/
|
|
354
|
+
export function editorMissingArgument(cmd, wants, missing) {
|
|
355
|
+
const given = /** @type {string[]} */ (cmd?.args ?? []);
|
|
356
|
+
const shown = wants.map(w => `<${w}>`);
|
|
357
|
+
return {
|
|
358
|
+
message: `${cmd.name()} takes ${shown.join(' ')}, and ${given.length ? `was given ${given.length} (${given.join(' ')}), read as ${shown.slice(0, given.length).join(' ')}` : 'was given none'}: ${missing ? `<${missing}>` : 'an argument'} is missing.`,
|
|
359
|
+
suggestions: editorMissingSuggestions(cmd),
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
301
363
|
/** Marks a command whose `command`/`addCommand` already self-install the shim. */
|
|
302
364
|
const SELF_INSTALLING = Symbol.for('astryx.jsonShim.selfInstalling');
|
|
303
365
|
|
|
@@ -469,8 +531,14 @@ export function handleCommanderError(err) {
|
|
|
469
531
|
|
|
470
532
|
// Real error paths. Strip Commander's "error: " prefix once: in the envelope
|
|
471
533
|
// the key is already `error`, and in text mode the Astryx prefix replaces it.
|
|
472
|
-
const cleaned = message.replace(/^error:\s*/i, '');
|
|
473
534
|
const suggestions = usageSuggestion(err, code);
|
|
535
|
+
// In the theme editor a missing argument names what was given: in
|
|
536
|
+
// `set corners small` the first word is read as the theme, so "value" alone
|
|
537
|
+
// would name the wrong thing.
|
|
538
|
+
const cleaned =
|
|
539
|
+
suggestions?.length === 2
|
|
540
|
+
? editorMissingMessage(err, message)
|
|
541
|
+
: message.replace(/^error:\s*/i, '');
|
|
474
542
|
if (jsonActive()) {
|
|
475
543
|
emitJsonError(
|
|
476
544
|
cleaned,
|
|
@@ -482,6 +550,8 @@ export function handleCommanderError(err) {
|
|
|
482
550
|
// same as every other CLI error — the `Error: …` line cliError prints.
|
|
483
551
|
process.stderr.write(`Error: ${cleaned}\n`);
|
|
484
552
|
if (suggestions) process.stderr.write(`Usage: ${suggestions[0].name}\n`);
|
|
553
|
+
if (suggestions?.[1])
|
|
554
|
+
process.stderr.write(`Run: ${suggestions[1].name}\n`);
|
|
485
555
|
}
|
|
486
556
|
process.exit(exitCode || 1);
|
|
487
557
|
}
|