@jskit-ai/jskit-cli 0.2.40 → 0.2.42

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.
@@ -2,6 +2,8 @@ function createRunCli({
2
2
  parseArgs,
3
3
  printUsage,
4
4
  shouldShowCommandHelpOnBareInvocation,
5
+ validateCommandOptions,
6
+ resolveCommandDescriptor,
5
7
  commandHandlers,
6
8
  cleanupMaterializedPackageRoots,
7
9
  createCliError
@@ -15,6 +17,12 @@ function createRunCli({
15
17
  if (typeof shouldShowCommandHelpOnBareInvocation !== "function") {
16
18
  throw new TypeError("createRunCli requires shouldShowCommandHelpOnBareInvocation.");
17
19
  }
20
+ if (typeof validateCommandOptions !== "function") {
21
+ throw new TypeError("createRunCli requires validateCommandOptions.");
22
+ }
23
+ if (typeof resolveCommandDescriptor !== "function") {
24
+ throw new TypeError("createRunCli requires resolveCommandDescriptor.");
25
+ }
18
26
  if (!commandHandlers || typeof commandHandlers !== "object") {
19
27
  throw new TypeError("createRunCli requires commandHandlers.");
20
28
  }
@@ -33,6 +41,16 @@ function createRunCli({
33
41
 
34
42
  try {
35
43
  const { command, options, positional } = parseArgs(argv, { createCliError });
44
+ validateCommandOptions(
45
+ { command, positional, options },
46
+ {
47
+ createCliError,
48
+ renderUsage: () => {
49
+ const helpCommand = command === "help" ? String(positional[0] || "").trim() : command;
50
+ printUsage(stderr, { command: helpCommand });
51
+ }
52
+ }
53
+ );
36
54
  if (options.help || command === "help") {
37
55
  const helpCommand = command === "help" ? String(positional[0] || "").trim() : command;
38
56
  printUsage(stdout, { command: helpCommand });
@@ -44,80 +62,22 @@ function createRunCli({
44
62
  return 0;
45
63
  }
46
64
 
47
- if (command === "create") {
48
- return await commandHandlers.commandCreate({
49
- positional,
50
- options,
51
- cwd,
52
- io: { stdin, stdout, stderr }
53
- });
54
- }
55
- if (command === "list") {
56
- return await commandHandlers.commandList({ positional, options, cwd, stdout });
57
- }
58
- if (command === "list-placements") {
59
- return await commandHandlers.commandListPlacements({ options, cwd, stdout });
60
- }
61
- if (command === "list-link-items") {
62
- return await commandHandlers.commandListLinkItems({ options, cwd, stdout });
63
- }
64
- if (command === "show") {
65
- return await commandHandlers.commandShow({ positional, options, stdout });
66
- }
67
- if (command === "migrations") {
68
- return await commandHandlers.commandMigrations({
69
- positional,
70
- options,
71
- cwd,
72
- io: { stdin, stdout, stderr }
73
- });
74
- }
75
- if (command === "add") {
76
- return await commandHandlers.commandAdd({
77
- positional,
78
- options,
79
- cwd,
80
- io: { stdin, stdout, stderr }
81
- });
82
- }
83
- if (command === "generate") {
84
- return await commandHandlers.commandGenerate({
85
- positional,
86
- options,
87
- cwd,
88
- io: { stdin, stdout, stderr }
89
- });
90
- }
91
- if (command === "position") {
92
- return await commandHandlers.commandPosition({
93
- positional,
94
- options,
95
- cwd,
96
- io: { stdin, stdout, stderr }
97
- });
98
- }
99
- if (command === "update") {
100
- return await commandHandlers.commandUpdate({
65
+ const commandDescriptor = resolveCommandDescriptor(command);
66
+ const handlerName = String(commandDescriptor?.handlerName || "").trim();
67
+ if (handlerName) {
68
+ const commandHandler = commandHandlers[handlerName];
69
+ if (typeof commandHandler !== "function") {
70
+ throw createCliError(`Unhandled command: ${command}`, { showUsage: true });
71
+ }
72
+ return await commandHandler({
101
73
  positional,
102
74
  options,
103
75
  cwd,
76
+ stdout,
77
+ stderr,
104
78
  io: { stdin, stdout, stderr }
105
79
  });
106
80
  }
107
- if (command === "remove") {
108
- return await commandHandlers.commandRemove({
109
- positional,
110
- options,
111
- cwd,
112
- io: { stdin, stdout, stderr }
113
- });
114
- }
115
- if (command === "doctor") {
116
- return await commandHandlers.commandDoctor({ cwd, options, stdout });
117
- }
118
- if (command === "lint-descriptors") {
119
- return await commandHandlers.commandLintDescriptors({ options, stdout });
120
- }
121
81
 
122
82
  throw createCliError(`Unhandled command: ${command}`, { showUsage: true });
123
83
  } catch (error) {
@@ -1,323 +1,13 @@
1
- import { resolveCommandAlias } from "./commandCatalog.js";
1
+ import {
2
+ listOverviewCommandDescriptors,
3
+ resolveCommandDescriptor,
4
+ shouldShowCommandHelpOnBareInvocation
5
+ } from "./commandCatalog.js";
2
6
  import {
3
7
  createColorFormatter,
4
8
  writeWrappedLines
5
9
  } from "../shared/outputFormatting.js";
6
10
 
7
- const COMMAND_OVERVIEW = Object.freeze([
8
- Object.freeze({
9
- command: "create",
10
- summary: "Scaffold an app-local runtime package."
11
- }),
12
- Object.freeze({
13
- command: "add",
14
- summary: "Install a runtime bundle or package into the current app."
15
- }),
16
- Object.freeze({
17
- command: "generate",
18
- summary: "Run a generator package (or generator subcommand)."
19
- }),
20
- Object.freeze({
21
- command: "list",
22
- summary: "List bundles, runtime packages, or generator packages."
23
- }),
24
- Object.freeze({
25
- command: "list-placements",
26
- summary: "List discovered UI placement targets."
27
- }),
28
- Object.freeze({
29
- command: "list-link-items",
30
- summary: "List available placement link-item component tokens."
31
- }),
32
- Object.freeze({
33
- command: "show",
34
- summary: "Show detailed metadata for a bundle or package."
35
- }),
36
- Object.freeze({
37
- command: "migrations",
38
- summary: "Generate managed migration files only."
39
- }),
40
- Object.freeze({
41
- command: "position",
42
- summary: "Re-apply positioning-only mutations for an installed package."
43
- }),
44
- Object.freeze({
45
- command: "update",
46
- summary: "Re-apply one installed package."
47
- }),
48
- Object.freeze({
49
- command: "remove",
50
- summary: "Remove one installed package."
51
- }),
52
- Object.freeze({
53
- command: "doctor",
54
- summary: "Validate lockfile and managed-file integrity."
55
- }),
56
- Object.freeze({
57
- command: "lint-descriptors",
58
- summary: "Validate bundle and package descriptor contracts."
59
- })
60
- ]);
61
-
62
- const COMMAND_HELP = Object.freeze({
63
- create: Object.freeze({
64
- title: "create",
65
- minimalUse: "jskit create package <name>",
66
- parameters: Object.freeze([
67
- Object.freeze({
68
- name: "<name>",
69
- description: "Local package slug used to scaffold packages/<name>."
70
- })
71
- ]),
72
- defaults: Object.freeze([
73
- "No npm install runs unless --run-npm-install is passed.",
74
- "If --scope is omitted, scope is inferred from app name.",
75
- "If --package-id is omitted, it is derived from scope + name."
76
- ]),
77
- fullUse: "jskit create package <name> [--scope <scope>] [--package-id <id>] [--description <text>] [--dry-run] [--run-npm-install] [--json]"
78
- }),
79
- add: Object.freeze({
80
- title: "add",
81
- minimalUse: "jskit add package <packageId>",
82
- parameters: Object.freeze([
83
- Object.freeze({
84
- name: "package | bundle",
85
- description: "Target type. Use package for one runtime package, bundle for a bundle id."
86
- }),
87
- Object.freeze({
88
- name: "<packageId|bundleId>",
89
- description: "Catalog id or installed node_modules package id."
90
- })
91
- ]),
92
- defaults: Object.freeze([
93
- "No npm install runs unless --run-npm-install is passed.",
94
- "Short ids resolve to @jskit-ai/<id> when available.",
95
- "Running without args lists bundles and runtime packages.",
96
- "Existing matching version is skipped unless options force reapply."
97
- ]),
98
- fullUse: "jskit add <package|bundle> <id> [--<option> <value>...] [--dry-run] [--run-npm-install] [--json] [--verbose]"
99
- }),
100
- generate: Object.freeze({
101
- title: "generate",
102
- minimalUse: "jskit generate <generatorId>",
103
- parameters: Object.freeze([
104
- Object.freeze({
105
- name: "<generatorId>",
106
- description: "Generator package id (for example: crud-ui-generator)."
107
- }),
108
- Object.freeze({
109
- name: "[subcommand]",
110
- description: "Optional generator subcommand (for example: scaffold or scaffold-field)."
111
- }),
112
- Object.freeze({
113
- name: "[subcommand args...]",
114
- description: "Optional positional args consumed by the chosen subcommand."
115
- })
116
- ]),
117
- defaults: Object.freeze([
118
- "No npm install runs unless --run-npm-install is passed.",
119
- "Short ids resolve to @jskit-ai/<id> when available.",
120
- "Running without args lists available generators.",
121
- "Running with only <generatorId> shows generator help.",
122
- "Use jskit generate <generatorId> <subcommand> help for subcommand-specific usage."
123
- ]),
124
- examples: Object.freeze([
125
- Object.freeze({
126
- label: "Common usage",
127
- lines: Object.freeze([
128
- "npx jskit generate ui-generator page \\",
129
- " admin/reports/index.vue"
130
- ])
131
- }),
132
- Object.freeze({
133
- label: "More advanced usage",
134
- lines: Object.freeze([
135
- "npx jskit generate crud-ui-generator crud \\",
136
- " admin/catalog/index/products \\",
137
- " --resource-file packages/products/src/shared/productResource.js"
138
- ])
139
- })
140
- ]),
141
- fullUse: "jskit generate <generatorId> [subcommand] [subcommand args...] [--<option> <value>...] [--dry-run] [--run-npm-install] [--json] [--verbose]"
142
- }),
143
- list: Object.freeze({
144
- title: "list",
145
- minimalUse: "jskit list",
146
- parameters: Object.freeze([
147
- Object.freeze({
148
- name: "[mode]",
149
- description: "Optional mode: bundles, packages, or generators."
150
- })
151
- ]),
152
- defaults: Object.freeze([
153
- "Without mode, list prints bundles + runtime packages + generators.",
154
- "placements are listed by the dedicated list-placements command.",
155
- "--full and --expanded only affect bundle/package listing views."
156
- ]),
157
- fullUse: "jskit list [bundles|packages|generators] [--full] [--expanded] [--json]"
158
- }),
159
- "list-placements": Object.freeze({
160
- title: "list-placements",
161
- minimalUse: "jskit list-placements",
162
- parameters: Object.freeze([]),
163
- defaults: Object.freeze([
164
- "Discovers placement outlets from app Vue ShellOutlet tags and route meta.",
165
- "Includes placement outlets contributed by installed package metadata.",
166
- "Shows plain text by default; use --json for structured output."
167
- ]),
168
- fullUse: "jskit list-placements [--json]"
169
- }),
170
- "list-link-items": Object.freeze({
171
- title: "list-link-items",
172
- minimalUse: "jskit list-link-items",
173
- parameters: Object.freeze([
174
- Object.freeze({
175
- name: "[--prefix <value>]",
176
- description: "Optional token prefix filter (example: local.main. or users.web.shell.)."
177
- }),
178
- Object.freeze({
179
- name: "[--all]",
180
- description: "Include all discovered tokens (including non-link-item and client container/runtime tokens)."
181
- })
182
- ]),
183
- defaults: Object.freeze([
184
- "Default output shows link-item tokens only (token names ending with link-item).",
185
- "Default includes app and installed-package placement-linked token sources.",
186
- "Use --prefix to narrow quickly (recommended: --prefix local.main.).",
187
- "Use --all when you want the full discovered token set.",
188
- "Shows plain text by default; use --json for structured output."
189
- ]),
190
- fullUse: "jskit list-link-items [--prefix <value>] [--all] [--json]"
191
- }),
192
- show: Object.freeze({
193
- title: "show",
194
- minimalUse: "jskit show <id>",
195
- parameters: Object.freeze([
196
- Object.freeze({
197
- name: "<id>",
198
- description: "Bundle id or package id to inspect."
199
- })
200
- ]),
201
- defaults: Object.freeze([
202
- "view is an alias of show.",
203
- "Basic output is compact; --details expands capability and runtime sections.",
204
- "--debug-exports implies --details."
205
- ]),
206
- fullUse: "jskit show <id> [--details] [--debug-exports] [--json]"
207
- }),
208
- migrations: Object.freeze({
209
- title: "migrations",
210
- minimalUse: "jskit migrations changed",
211
- parameters: Object.freeze([
212
- Object.freeze({
213
- name: "<scope>",
214
- description: "all | changed | package."
215
- }),
216
- Object.freeze({
217
- name: "[packageId]",
218
- description: "Required only when scope is package."
219
- })
220
- ]),
221
- defaults: Object.freeze([
222
- "No npm install runs unless --run-npm-install is passed.",
223
- "Inline options are accepted only for 'migrations package <packageId>'.",
224
- "Without --json, output lists touched migration files."
225
- ]),
226
- fullUse: "jskit migrations <all|changed|package> [packageId] [--<option> <value>...] [--dry-run] [--json] [--verbose]"
227
- }),
228
- position: Object.freeze({
229
- title: "position",
230
- minimalUse: "jskit position element <packageId>",
231
- parameters: Object.freeze([
232
- Object.freeze({
233
- name: "element",
234
- description: "Target type for positioning command."
235
- }),
236
- Object.freeze({
237
- name: "<packageId>",
238
- description: "Installed package id to re-position."
239
- })
240
- ]),
241
- defaults: Object.freeze([
242
- "Only positioning mutations are applied.",
243
- "No npm install runs unless --run-npm-install is passed.",
244
- "Reads current options from lock unless overridden inline."
245
- ]),
246
- fullUse: "jskit position element <packageId> [--<option> <value>...] [--dry-run] [--json]"
247
- }),
248
- update: Object.freeze({
249
- title: "update",
250
- minimalUse: "jskit update package <packageId>",
251
- parameters: Object.freeze([
252
- Object.freeze({
253
- name: "package",
254
- description: "Target type for update command."
255
- }),
256
- Object.freeze({
257
- name: "<packageId>",
258
- description: "Installed package id to re-apply."
259
- })
260
- ]),
261
- defaults: Object.freeze([
262
- "No npm install runs unless --run-npm-install is passed.",
263
- "Existing lock options are reused unless overridden inline.",
264
- "update reuses add package flow with forced reapply."
265
- ]),
266
- fullUse: "jskit update package <packageId> [--<option> <value>...] [--dry-run] [--run-npm-install] [--json]"
267
- }),
268
- remove: Object.freeze({
269
- title: "remove",
270
- minimalUse: "jskit remove package <packageId>",
271
- parameters: Object.freeze([
272
- Object.freeze({
273
- name: "package",
274
- description: "Target type for remove command."
275
- }),
276
- Object.freeze({
277
- name: "<packageId>",
278
- description: "Installed package id to remove."
279
- })
280
- ]),
281
- defaults: Object.freeze([
282
- "No npm install runs unless --run-npm-install is passed.",
283
- "Managed files and lock entries are removed for the package.",
284
- "Local package source directories are not deleted."
285
- ]),
286
- fullUse: "jskit remove package <packageId> [--dry-run] [--run-npm-install] [--json]"
287
- }),
288
- doctor: Object.freeze({
289
- title: "doctor",
290
- minimalUse: "jskit doctor",
291
- parameters: Object.freeze([]),
292
- defaults: Object.freeze([
293
- "Validates lock entries, managed files, and registry visibility.",
294
- "Reports issues as plain text by default.",
295
- "Use --json for machine-readable diagnostics."
296
- ]),
297
- fullUse: "jskit doctor [--json]"
298
- }),
299
- "lint-descriptors": Object.freeze({
300
- title: "lint-descriptors",
301
- minimalUse: "jskit lint-descriptors",
302
- parameters: Object.freeze([]),
303
- defaults: Object.freeze([
304
- "Runs descriptor consistency checks.",
305
- "check-di-labels is optional and adds stricter DI token label checks.",
306
- "Outputs plain text by default and supports --json."
307
- ]),
308
- fullUse: "jskit lint-descriptors [--check-di-labels] [--json]"
309
- })
310
- });
311
-
312
- const BARE_COMMAND_HELP = new Set([
313
- "create",
314
- "show",
315
- "migrations",
316
- "position",
317
- "update",
318
- "remove"
319
- ]);
320
-
321
11
  function appendSeparatedBlocks(lines = [], blocks = []) {
322
12
  const normalizedBlocks = Array.isArray(blocks) ? blocks : [];
323
13
  for (const [index, block] of normalizedBlocks.entries()) {
@@ -346,18 +36,14 @@ function printTopLevelHelp(stream = process.stderr) {
346
36
  lines.push("Use: jskit help <command> for command-specific usage.");
347
37
  lines.push("");
348
38
  lines.push(color.heading("Available commands:"));
349
- for (const entry of COMMAND_OVERVIEW) {
39
+ for (const entry of listOverviewCommandDescriptors()) {
350
40
  lines.push(` ${color.item(entry.command.padEnd(16, " "))} ${entry.summary}`);
351
41
  }
352
- lines.push("");
353
- lines.push(color.heading("Global flags:"));
354
- lines.push(" --dry-run --run-npm-install --json --verbose --help");
355
42
  writeHelpLines(stream, lines);
356
43
  }
357
44
 
358
45
  function printCommandHelp(stream = process.stderr, command = "") {
359
- const resolvedCommand = resolveCommandAlias(command);
360
- const entry = COMMAND_HELP[resolvedCommand];
46
+ const entry = resolveCommandDescriptor(command);
361
47
  if (!entry) {
362
48
  printTopLevelHelp(stream);
363
49
  return;
@@ -365,7 +51,7 @@ function printCommandHelp(stream = process.stderr, command = "") {
365
51
 
366
52
  const color = createColorFormatter(stream);
367
53
  const lines = [];
368
- lines.push(`Command: ${color.emphasis(entry.title)}`);
54
+ lines.push(`Command: ${color.emphasis(entry.command)}`);
369
55
  lines.push("");
370
56
 
371
57
  let sectionNumber = 1;
@@ -423,15 +109,6 @@ function printUsage(stream = process.stderr, { command = "" } = {}) {
423
109
  printCommandHelp(stream, normalizedCommand);
424
110
  }
425
111
 
426
- function shouldShowCommandHelpOnBareInvocation(command = "", positional = []) {
427
- const resolvedCommand = resolveCommandAlias(command);
428
- const argumentList = Array.isArray(positional) ? positional : [];
429
- if (!BARE_COMMAND_HELP.has(resolvedCommand)) {
430
- return false;
431
- }
432
- return argumentList.length < 1;
433
- }
434
-
435
112
  export {
436
113
  printUsage,
437
114
  shouldShowCommandHelpOnBareInvocation
@@ -209,6 +209,80 @@ function normalizePathValue(value) {
209
209
  .join("/");
210
210
  }
211
211
 
212
+ function normalizePromptChoices(rawChoices = []) {
213
+ return ensureArray(rawChoices)
214
+ .map((entry) => {
215
+ if (!entry || typeof entry !== "object") {
216
+ return null;
217
+ }
218
+ const value = String(entry.value || "").trim();
219
+ const label = String(entry.label || value).trim();
220
+ if (!value || !label) {
221
+ return null;
222
+ }
223
+ return Object.freeze({ value, label });
224
+ })
225
+ .filter(Boolean);
226
+ }
227
+
228
+ function findPromptChoice(promptChoices = [], answer = "") {
229
+ const normalizedAnswer = String(answer || "").trim();
230
+ if (!normalizedAnswer) {
231
+ return null;
232
+ }
233
+
234
+ if (/^\d+$/.test(normalizedAnswer)) {
235
+ const index = Number.parseInt(normalizedAnswer, 10) - 1;
236
+ if (index >= 0 && index < promptChoices.length) {
237
+ return promptChoices[index];
238
+ }
239
+ }
240
+
241
+ return promptChoices.find((entry) => {
242
+ return entry.value === normalizedAnswer || entry.label === normalizedAnswer;
243
+ }) || null;
244
+ }
245
+
246
+ async function promptForChoice({
247
+ promptText = "",
248
+ promptChoices = [],
249
+ stdin,
250
+ stdout,
251
+ required = false,
252
+ defaultValue = ""
253
+ }) {
254
+ const rl = createInterface({
255
+ input: stdin,
256
+ output: stdout
257
+ });
258
+
259
+ try {
260
+ while (true) {
261
+ const answer = String(await rl.question(promptText)).trim();
262
+ if (!answer && defaultValue) {
263
+ return defaultValue;
264
+ }
265
+ if (!answer && !required) {
266
+ return "";
267
+ }
268
+ if (!answer && required) {
269
+ throw createCliError("A selection is required.");
270
+ }
271
+
272
+ const matchedChoice = findPromptChoice(promptChoices, answer);
273
+ if (matchedChoice) {
274
+ return matchedChoice.value;
275
+ }
276
+
277
+ const values = promptChoices.map((entry) => entry.value).join(", ");
278
+ stdout.write(`Invalid selection. Enter a number or one of: ${values}.
279
+ `);
280
+ }
281
+ } finally {
282
+ rl.close();
283
+ }
284
+ }
285
+
212
286
  function parseTransformSpec(transform) {
213
287
  const normalized = String(transform || "").trim();
214
288
  if (!normalized) {
@@ -359,6 +433,7 @@ async function promptForRequiredOption({
359
433
  ownerId,
360
434
  optionName,
361
435
  optionSchema,
436
+ promptChoices = [],
362
437
  stdin = process.stdin,
363
438
  stdout = process.stdout
364
439
  }) {
@@ -387,6 +462,24 @@ async function promptForRequiredOption({
387
462
  const defaultHint = defaultValue ? ` [default: ${defaultValue}]` : "";
388
463
  const hintSuffix = promptHint ? ` ${promptHint}` : "";
389
464
  const promptText = `${label}${defaultHint}${hintSuffix}: `;
465
+ const normalizedPromptChoices = normalizePromptChoices(promptChoices);
466
+
467
+ if (normalizedPromptChoices.length > 0) {
468
+ stdout.write(`${label}${defaultHint}${hintSuffix}
469
+ `);
470
+ normalizedPromptChoices.forEach((entry, index) => {
471
+ stdout.write(` ${index + 1}) ${entry.label}
472
+ `);
473
+ });
474
+ return promptForChoice({
475
+ promptText: "Select a surface by number or id: ",
476
+ promptChoices: normalizedPromptChoices,
477
+ stdin,
478
+ stdout,
479
+ required,
480
+ defaultValue
481
+ });
482
+ }
390
483
 
391
484
  let answer = "";
392
485