@astryxdesign/cli 0.7.8-canary.5e05bdf → 0.7.8-canary.830f875
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/clients/cli/index.mjs +56 -11
- package/clients/cli/program.mjs +15 -0
- package/clients/cli/run.mjs +4 -1
- package/package.json +9 -9
package/clients/cli/index.mjs
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @file Astryx CLI — Commander program setup
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* (bad import, syntax error)
|
|
6
|
+
* Commands load lazily: a bin run loads only the one its arguments name.
|
|
7
|
+
* One that fails to load (bad import, syntax error) leaves the rest working.
|
|
8
8
|
*
|
|
9
9
|
* The program is built by {@link createProgram} — a factory so tests can drive
|
|
10
10
|
* a FRESH program in-process (via parseAsync) instead of spawning `node
|
|
11
|
-
* bin/astryx.mjs` per assertion.
|
|
12
|
-
*
|
|
11
|
+
* bin/astryx.mjs` per assertion. Code that reads every command at once uses
|
|
12
|
+
* the full program in program.mjs.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import {Command, Option} from 'commander';
|
|
@@ -329,6 +329,52 @@ const commands = [
|
|
|
329
329
|
{name: 'postinstall', path: './commands/postinstall.mjs', register: 'registerPostinstall'},
|
|
330
330
|
];
|
|
331
331
|
|
|
332
|
+
/** The name each registry entry registers, in registration order. */
|
|
333
|
+
export const COMMAND_NAMES = Object.freeze(commands.map(cmd => cmd.name));
|
|
334
|
+
|
|
335
|
+
/** Commands whose run reads every other command: the manifest lists them. */
|
|
336
|
+
const READS_EVERY_COMMAND = new Set(['manifest']);
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* The commands a run of the bin loads. Commander dispatches a run to its
|
|
340
|
+
* first operand after the root's own options, so this reads the arguments the
|
|
341
|
+
* same way. It returns that one command, no command for a run that only
|
|
342
|
+
* prints the version, or null for every command. These runs load every
|
|
343
|
+
* command: help, the manifest, `help <command>`, an unknown word, and a flag
|
|
344
|
+
* the root does not declare. They print or read the whole list.
|
|
345
|
+
*
|
|
346
|
+
* @param {import('commander').Command} program the root, with its options
|
|
347
|
+
* @param {string[]} argv the arguments after `astryx`
|
|
348
|
+
* @returns {Set<string> | null}
|
|
349
|
+
*/
|
|
350
|
+
export function commandsForArgs(program, argv) {
|
|
351
|
+
let printsVersion = false;
|
|
352
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
353
|
+
const arg = argv[i];
|
|
354
|
+
// Commander reads a lone `-` as an operand, as it reads any word.
|
|
355
|
+
if (arg.length < 2 || arg[0] !== '-') {
|
|
356
|
+
return commands.some(cmd => cmd.name === arg) && !READS_EVERY_COMMAND.has(arg)
|
|
357
|
+
? new Set([arg])
|
|
358
|
+
: null;
|
|
359
|
+
}
|
|
360
|
+
const equals = arg.startsWith('--') ? arg.indexOf('=') : -1;
|
|
361
|
+
const flag = equals === -1 ? arg : arg.slice(0, equals);
|
|
362
|
+
const option = program.options.find(o => o.long === flag || o.short === flag);
|
|
363
|
+
// Help flags, `--`, combined short flags and unknown flags read the whole
|
|
364
|
+
// list, or make Commander stop dispatching by name.
|
|
365
|
+
if (option == null) return null;
|
|
366
|
+
const takesValue = option.required || option.optional;
|
|
367
|
+
if (equals !== -1 && !takesValue) return null;
|
|
368
|
+
if (equals === -1 && option.required) i += 1;
|
|
369
|
+
const next = argv[i + 1];
|
|
370
|
+
if (equals === -1 && option.optional && next != null && !(next.length > 1 && next[0] === '-')) {
|
|
371
|
+
i += 1;
|
|
372
|
+
}
|
|
373
|
+
if (option.long === '--version') printsVersion = true;
|
|
374
|
+
}
|
|
375
|
+
return printsVersion ? new Set() : null;
|
|
376
|
+
}
|
|
377
|
+
|
|
332
378
|
const SETUP_NUDGE_EXEMPT = new Set(['init', 'agent-docs']);
|
|
333
379
|
|
|
334
380
|
/**
|
|
@@ -363,9 +409,12 @@ const INTEGRATION_MANIFEST_FILES = [
|
|
|
363
409
|
* lazy-imported. Each call returns an independent Command so tests can
|
|
364
410
|
* parseAsync repeatedly without commander state leaking between runs.
|
|
365
411
|
*
|
|
412
|
+
* @param {{argv?: string[]}} [options] `argv`, the arguments after `astryx`:
|
|
413
|
+
* load only the commands a run of them needs (commandsForArgs). Without
|
|
414
|
+
* it, every command loads.
|
|
366
415
|
* @returns {Promise<import('commander').Command>}
|
|
367
416
|
*/
|
|
368
|
-
export async function createProgram() {
|
|
417
|
+
export async function createProgram({argv} = {}) {
|
|
369
418
|
const program = new Command();
|
|
370
419
|
|
|
371
420
|
// Deterministic, single-line help. Commander wraps each option/command
|
|
@@ -708,7 +757,9 @@ export async function createProgram() {
|
|
|
708
757
|
}
|
|
709
758
|
});
|
|
710
759
|
|
|
760
|
+
const loads = argv == null ? null : commandsForArgs(program, argv);
|
|
711
761
|
for (const cmd of commands) {
|
|
762
|
+
if (loads != null && !loads.has(cmd.name)) continue;
|
|
712
763
|
try {
|
|
713
764
|
const mod = await import(cmd.path);
|
|
714
765
|
mod[cmd.register](program, {jsonSupported: JSON_SUPPORTED, version: pkg.version});
|
|
@@ -740,9 +791,3 @@ export async function createProgram() {
|
|
|
740
791
|
|
|
741
792
|
return program;
|
|
742
793
|
}
|
|
743
|
-
|
|
744
|
-
/**
|
|
745
|
-
* Eager singleton program for `bin/astryx.mjs` and legacy importers. Tests
|
|
746
|
-
* should call {@link createProgram} to get an isolated instance.
|
|
747
|
-
*/
|
|
748
|
-
export const program = await createProgram();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The full Astryx CLI program, with every command loaded.
|
|
5
|
+
*
|
|
6
|
+
* @input createProgram (index.mjs).
|
|
7
|
+
* @output `program`, built once when this module loads.
|
|
8
|
+
* @position For code that reads every command at once, such as tests of the
|
|
9
|
+
* manifest and the docs drift check. A run of the bin builds its own
|
|
10
|
+
* program from its arguments (run.mjs), so it does not load this module.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {createProgram} from './index.mjs';
|
|
14
|
+
|
|
15
|
+
export const program = await createProgram();
|
package/clients/cli/run.mjs
CHANGED
|
@@ -33,11 +33,14 @@ export async function runCli({cliRoot, argv, declinedProjectCli}) {
|
|
|
33
33
|
if (answered) return answered;
|
|
34
34
|
|
|
35
35
|
const {
|
|
36
|
-
|
|
36
|
+
createProgram,
|
|
37
37
|
loadProjectDebugHandler,
|
|
38
38
|
loadProjectForHelp,
|
|
39
39
|
handleVersionJsonPreflight,
|
|
40
40
|
} = await import('./index.mjs');
|
|
41
|
+
// Only the commands these arguments need load, before anything below runs,
|
|
42
|
+
// as the full program did.
|
|
43
|
+
const program = await createProgram({argv: process.argv.slice(2)});
|
|
41
44
|
const {isJsonMode, toErrorEnvelope} =
|
|
42
45
|
await import('../../foundation/response/json.mjs');
|
|
43
46
|
const {handleCommanderError} = await import('./lib/json-shim.mjs');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.8-canary.
|
|
3
|
+
"version": "0.7.8-canary.830f875",
|
|
4
4
|
"displayName": "CLI",
|
|
5
5
|
"description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -124,10 +124,10 @@
|
|
|
124
124
|
"zod": "^4.4.3"
|
|
125
125
|
},
|
|
126
126
|
"peerDependencies": {
|
|
127
|
-
"@astryxdesign/charts": "0.7.8-canary.
|
|
128
|
-
"@astryxdesign/core": "0.7.8-canary.
|
|
129
|
-
"@astryxdesign/lab": "0.7.8-canary.
|
|
130
|
-
"@astryxdesign/theme-neutral": "0.7.8-canary.
|
|
127
|
+
"@astryxdesign/charts": "0.7.8-canary.830f875",
|
|
128
|
+
"@astryxdesign/core": "0.7.8-canary.830f875",
|
|
129
|
+
"@astryxdesign/lab": "0.7.8-canary.830f875",
|
|
130
|
+
"@astryxdesign/theme-neutral": "0.7.8-canary.830f875"
|
|
131
131
|
},
|
|
132
132
|
"peerDependenciesMeta": {
|
|
133
133
|
"@astryxdesign/charts": {
|
|
@@ -144,10 +144,10 @@
|
|
|
144
144
|
}
|
|
145
145
|
},
|
|
146
146
|
"devDependencies": {
|
|
147
|
-
"@astryxdesign/charts": "0.7.8-canary.
|
|
148
|
-
"@astryxdesign/core": "0.7.8-canary.
|
|
149
|
-
"@astryxdesign/lab": "0.7.8-canary.
|
|
150
|
-
"@astryxdesign/theme-neutral": "0.7.8-canary.
|
|
147
|
+
"@astryxdesign/charts": "0.7.8-canary.830f875",
|
|
148
|
+
"@astryxdesign/core": "0.7.8-canary.830f875",
|
|
149
|
+
"@astryxdesign/lab": "0.7.8-canary.830f875",
|
|
150
|
+
"@astryxdesign/theme-neutral": "0.7.8-canary.830f875",
|
|
151
151
|
"@heroicons/react": "^2.2.0",
|
|
152
152
|
"@stylexjs/stylex": "^0.19.0",
|
|
153
153
|
"@types/babel__core": "^7.20.5",
|