@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.
- package/package.json +3 -3
- package/src/server/cliRuntime/mutations/textMutations.js +11 -6
- package/src/server/cliRuntime/packageInstallFlow.js +7 -2
- package/src/server/cliRuntime/packageOptions.js +20 -0
- package/src/server/cliRuntime/packageTemplateResolution.js +23 -2
- package/src/server/commandHandlers/packageCommands/add.js +7 -2
- package/src/server/commandHandlers/packageCommands/generate.js +8 -32
- package/src/server/commandHandlers/shared.js +39 -0
- package/src/server/core/argParser.js +3 -2
- package/src/server/core/commandCatalog.js +551 -32
- package/src/server/core/createCliRunner.js +6 -0
- package/src/server/core/dispatchCli.js +28 -68
- package/src/server/core/usageHelp.js +8 -331
- package/src/server/shared/optionInterpolation.js +93 -0
|
@@ -1,50 +1,569 @@
|
|
|
1
|
-
const
|
|
2
|
-
"
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"position",
|
|
13
|
-
"update",
|
|
14
|
-
"remove",
|
|
15
|
-
"doctor",
|
|
16
|
-
"lint-descriptors"
|
|
17
|
-
]);
|
|
18
|
-
|
|
19
|
-
const KNOWN_COMMANDS = new Set(KNOWN_COMMAND_IDS);
|
|
20
|
-
|
|
21
|
-
const COMMAND_ALIASES = Object.freeze({
|
|
22
|
-
view: "show",
|
|
23
|
-
ls: "list",
|
|
24
|
-
gen: "generate",
|
|
25
|
-
lp: "list-placements",
|
|
26
|
-
lpct: "list-link-items",
|
|
27
|
-
"list-placement-component-tokens": "list-link-items"
|
|
1
|
+
const OPTION_FLAG_LABELS = Object.freeze({
|
|
2
|
+
dryRun: "--dry-run",
|
|
3
|
+
runNpmInstall: "--run-npm-install",
|
|
4
|
+
full: "--full",
|
|
5
|
+
expanded: "--expanded",
|
|
6
|
+
details: "--details",
|
|
7
|
+
debugExports: "--debug-exports",
|
|
8
|
+
checkDiLabels: "--check-di-labels",
|
|
9
|
+
verbose: "--verbose",
|
|
10
|
+
json: "--json",
|
|
11
|
+
all: "--all"
|
|
28
12
|
});
|
|
29
13
|
|
|
14
|
+
const PARSED_BOOLEAN_OPTION_KEYS = Object.freeze(Object.keys(OPTION_FLAG_LABELS));
|
|
15
|
+
|
|
16
|
+
function isHelpToken(value = "") {
|
|
17
|
+
return String(value || "").trim().toLowerCase() === "help";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function canDelegateAddInlineOptions(positional = []) {
|
|
21
|
+
const [first, second, third] = Array.isArray(positional) ? positional : [];
|
|
22
|
+
const targetType = String(first || "").trim();
|
|
23
|
+
const targetId = String(second || "").trim();
|
|
24
|
+
if (!targetType || !targetId || isHelpToken(targetId) || isHelpToken(third)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return targetType === "package" || targetType === "bundle";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function canDelegateGenerateInlineOptions(positional = []) {
|
|
31
|
+
const normalizedPositionals = Array.isArray(positional) ? positional : [];
|
|
32
|
+
const first = String(normalizedPositionals[0] || "").trim();
|
|
33
|
+
const second = String(normalizedPositionals[1] || "").trim();
|
|
34
|
+
const last = String(normalizedPositionals[normalizedPositionals.length - 1] || "").trim();
|
|
35
|
+
if (!first || !second || isHelpToken(first) || isHelpToken(second) || isHelpToken(last)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function canDelegateMigrationsInlineOptions(positional = []) {
|
|
42
|
+
const [first, second] = Array.isArray(positional) ? positional : [];
|
|
43
|
+
return String(first || "").trim().toLowerCase() === "package" && Boolean(String(second || "").trim());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function canDelegatePackageTargetInlineOptions(positional = [], expectedTargetType = "") {
|
|
47
|
+
const [first, second] = Array.isArray(positional) ? positional : [];
|
|
48
|
+
const targetType = String(first || "").trim();
|
|
49
|
+
const targetId = String(second || "").trim();
|
|
50
|
+
if (!targetType || !targetId || isHelpToken(targetId)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return targetType === String(expectedTargetType || "").trim();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const COMMAND_DESCRIPTORS = Object.freeze({
|
|
57
|
+
help: Object.freeze({
|
|
58
|
+
command: "help",
|
|
59
|
+
aliases: Object.freeze([]),
|
|
60
|
+
showInOverview: false,
|
|
61
|
+
summary: "Show command-specific usage.",
|
|
62
|
+
minimalUse: "jskit help [command]",
|
|
63
|
+
parameters: Object.freeze([
|
|
64
|
+
Object.freeze({
|
|
65
|
+
name: "[command]",
|
|
66
|
+
description: "Optional command name to inspect."
|
|
67
|
+
})
|
|
68
|
+
]),
|
|
69
|
+
defaults: Object.freeze([
|
|
70
|
+
"Without a command, help prints the top-level overview.",
|
|
71
|
+
"Use jskit help <command> for command-specific usage."
|
|
72
|
+
]),
|
|
73
|
+
fullUse: "jskit help [command]",
|
|
74
|
+
showHelpOnBareInvocation: false,
|
|
75
|
+
handlerName: "",
|
|
76
|
+
allowedFlagKeys: Object.freeze([]),
|
|
77
|
+
inlineOptionMode: "none",
|
|
78
|
+
allowedValueOptionNames: Object.freeze([])
|
|
79
|
+
}),
|
|
80
|
+
create: Object.freeze({
|
|
81
|
+
command: "create",
|
|
82
|
+
aliases: Object.freeze([]),
|
|
83
|
+
showInOverview: true,
|
|
84
|
+
summary: "Scaffold an app-local runtime package.",
|
|
85
|
+
minimalUse: "jskit create package <name>",
|
|
86
|
+
parameters: Object.freeze([
|
|
87
|
+
Object.freeze({
|
|
88
|
+
name: "<name>",
|
|
89
|
+
description: "Local package slug used to scaffold packages/<name>."
|
|
90
|
+
})
|
|
91
|
+
]),
|
|
92
|
+
defaults: Object.freeze([
|
|
93
|
+
"No npm install runs unless --run-npm-install is passed.",
|
|
94
|
+
"If --scope is omitted, scope is inferred from app name.",
|
|
95
|
+
"If --package-id is omitted, it is derived from scope + name."
|
|
96
|
+
]),
|
|
97
|
+
fullUse:
|
|
98
|
+
"jskit create package <name> [--scope <scope>] [--package-id <id>] [--description <text>] [--dry-run] [--run-npm-install] [--json]",
|
|
99
|
+
showHelpOnBareInvocation: true,
|
|
100
|
+
handlerName: "commandCreate",
|
|
101
|
+
allowedFlagKeys: Object.freeze(["dryRun", "runNpmInstall", "json"]),
|
|
102
|
+
inlineOptionMode: "enumerated",
|
|
103
|
+
allowedValueOptionNames: Object.freeze(["scope", "package-id", "description"])
|
|
104
|
+
}),
|
|
105
|
+
add: Object.freeze({
|
|
106
|
+
command: "add",
|
|
107
|
+
aliases: Object.freeze([]),
|
|
108
|
+
showInOverview: true,
|
|
109
|
+
summary: "Install a runtime bundle or package into the current app.",
|
|
110
|
+
minimalUse: "jskit add package <packageId>",
|
|
111
|
+
parameters: Object.freeze([
|
|
112
|
+
Object.freeze({
|
|
113
|
+
name: "package | bundle",
|
|
114
|
+
description: "Target type. Use package for one runtime package, bundle for a bundle id."
|
|
115
|
+
}),
|
|
116
|
+
Object.freeze({
|
|
117
|
+
name: "<packageId|bundleId>",
|
|
118
|
+
description: "Catalog id or installed node_modules package id."
|
|
119
|
+
})
|
|
120
|
+
]),
|
|
121
|
+
defaults: Object.freeze([
|
|
122
|
+
"No npm install runs unless --run-npm-install is passed.",
|
|
123
|
+
"Short ids resolve to @jskit-ai/<id> when available.",
|
|
124
|
+
"Running without args lists bundles and runtime packages.",
|
|
125
|
+
"Existing matching version is skipped unless options force reapply."
|
|
126
|
+
]),
|
|
127
|
+
fullUse:
|
|
128
|
+
"jskit add <package|bundle> <id> [--<option> <value>...] [--dry-run] [--run-npm-install] [--json] [--verbose]",
|
|
129
|
+
showHelpOnBareInvocation: false,
|
|
130
|
+
handlerName: "commandAdd",
|
|
131
|
+
allowedFlagKeys: Object.freeze(["dryRun", "runNpmInstall", "json", "verbose"]),
|
|
132
|
+
inlineOptionMode: "delegate",
|
|
133
|
+
allowedValueOptionNames: Object.freeze([]),
|
|
134
|
+
canDelegateInlineOptions: canDelegateAddInlineOptions
|
|
135
|
+
}),
|
|
136
|
+
generate: Object.freeze({
|
|
137
|
+
command: "generate",
|
|
138
|
+
aliases: Object.freeze(["gen"]),
|
|
139
|
+
showInOverview: true,
|
|
140
|
+
summary: "Run a generator package (or generator subcommand).",
|
|
141
|
+
minimalUse: "jskit generate <generatorId>",
|
|
142
|
+
parameters: Object.freeze([
|
|
143
|
+
Object.freeze({
|
|
144
|
+
name: "<generatorId>",
|
|
145
|
+
description: "Generator package id (for example: crud-ui-generator)."
|
|
146
|
+
}),
|
|
147
|
+
Object.freeze({
|
|
148
|
+
name: "[subcommand]",
|
|
149
|
+
description: "Optional generator subcommand (for example: scaffold or scaffold-field)."
|
|
150
|
+
}),
|
|
151
|
+
Object.freeze({
|
|
152
|
+
name: "[subcommand args...]",
|
|
153
|
+
description: "Optional positional args consumed by the chosen subcommand."
|
|
154
|
+
})
|
|
155
|
+
]),
|
|
156
|
+
defaults: Object.freeze([
|
|
157
|
+
"No npm install runs unless --run-npm-install is passed.",
|
|
158
|
+
"Short ids resolve to @jskit-ai/<id> when available.",
|
|
159
|
+
"Running without args lists available generators.",
|
|
160
|
+
"Running with only <generatorId> shows generator help.",
|
|
161
|
+
"Use jskit generate <generatorId> <subcommand> help for subcommand-specific usage."
|
|
162
|
+
]),
|
|
163
|
+
examples: Object.freeze([
|
|
164
|
+
Object.freeze({
|
|
165
|
+
label: "Common usage",
|
|
166
|
+
lines: Object.freeze([
|
|
167
|
+
"npx jskit generate ui-generator page \\",
|
|
168
|
+
" admin/reports/index.vue"
|
|
169
|
+
])
|
|
170
|
+
}),
|
|
171
|
+
Object.freeze({
|
|
172
|
+
label: "More advanced usage",
|
|
173
|
+
lines: Object.freeze([
|
|
174
|
+
"npx jskit generate crud-ui-generator crud \\",
|
|
175
|
+
" admin/catalog/index/products \\",
|
|
176
|
+
" --resource-file packages/products/src/shared/productResource.js"
|
|
177
|
+
])
|
|
178
|
+
})
|
|
179
|
+
]),
|
|
180
|
+
fullUse:
|
|
181
|
+
"jskit generate <generatorId> [subcommand] [subcommand args...] [--<option> <value>...] [--dry-run] [--run-npm-install] [--json] [--verbose]",
|
|
182
|
+
showHelpOnBareInvocation: false,
|
|
183
|
+
handlerName: "commandGenerate",
|
|
184
|
+
allowedFlagKeys: Object.freeze(["dryRun", "runNpmInstall", "json", "verbose"]),
|
|
185
|
+
inlineOptionMode: "delegate",
|
|
186
|
+
allowedValueOptionNames: Object.freeze([]),
|
|
187
|
+
canDelegateInlineOptions: canDelegateGenerateInlineOptions
|
|
188
|
+
}),
|
|
189
|
+
list: Object.freeze({
|
|
190
|
+
command: "list",
|
|
191
|
+
aliases: Object.freeze(["ls"]),
|
|
192
|
+
showInOverview: true,
|
|
193
|
+
summary: "List bundles, runtime packages, or generator packages.",
|
|
194
|
+
minimalUse: "jskit list",
|
|
195
|
+
parameters: Object.freeze([
|
|
196
|
+
Object.freeze({
|
|
197
|
+
name: "[mode]",
|
|
198
|
+
description: "Optional mode: bundles, packages, or generators."
|
|
199
|
+
})
|
|
200
|
+
]),
|
|
201
|
+
defaults: Object.freeze([
|
|
202
|
+
"Without mode, list prints bundles + runtime packages + generators.",
|
|
203
|
+
"placements are listed by the dedicated list-placements command.",
|
|
204
|
+
"--full and --expanded only affect bundle/package listing views."
|
|
205
|
+
]),
|
|
206
|
+
fullUse: "jskit list [bundles|packages|generators] [--full] [--expanded] [--json]",
|
|
207
|
+
showHelpOnBareInvocation: false,
|
|
208
|
+
handlerName: "commandList",
|
|
209
|
+
allowedFlagKeys: Object.freeze(["full", "expanded", "json"]),
|
|
210
|
+
inlineOptionMode: "none",
|
|
211
|
+
allowedValueOptionNames: Object.freeze([])
|
|
212
|
+
}),
|
|
213
|
+
"list-placements": Object.freeze({
|
|
214
|
+
command: "list-placements",
|
|
215
|
+
aliases: Object.freeze(["lp"]),
|
|
216
|
+
showInOverview: true,
|
|
217
|
+
summary: "List discovered UI placement targets.",
|
|
218
|
+
minimalUse: "jskit list-placements",
|
|
219
|
+
parameters: Object.freeze([]),
|
|
220
|
+
defaults: Object.freeze([
|
|
221
|
+
"Discovers placement outlets from app Vue ShellOutlet tags and route meta.",
|
|
222
|
+
"Includes placement outlets contributed by installed package metadata.",
|
|
223
|
+
"Shows plain text by default; use --json for structured output."
|
|
224
|
+
]),
|
|
225
|
+
fullUse: "jskit list-placements [--json]",
|
|
226
|
+
showHelpOnBareInvocation: false,
|
|
227
|
+
handlerName: "commandListPlacements",
|
|
228
|
+
allowedFlagKeys: Object.freeze(["json"]),
|
|
229
|
+
inlineOptionMode: "none",
|
|
230
|
+
allowedValueOptionNames: Object.freeze([])
|
|
231
|
+
}),
|
|
232
|
+
"list-link-items": Object.freeze({
|
|
233
|
+
command: "list-link-items",
|
|
234
|
+
aliases: Object.freeze(["lpct", "list-placement-component-tokens"]),
|
|
235
|
+
showInOverview: true,
|
|
236
|
+
summary: "List available placement link-item component tokens.",
|
|
237
|
+
minimalUse: "jskit list-link-items",
|
|
238
|
+
parameters: Object.freeze([
|
|
239
|
+
Object.freeze({
|
|
240
|
+
name: "[--prefix <value>]",
|
|
241
|
+
description: "Optional token prefix filter (example: local.main. or users.web.shell.)."
|
|
242
|
+
}),
|
|
243
|
+
Object.freeze({
|
|
244
|
+
name: "[--all]",
|
|
245
|
+
description: "Include all discovered tokens (including non-link-item and client container/runtime tokens)."
|
|
246
|
+
})
|
|
247
|
+
]),
|
|
248
|
+
defaults: Object.freeze([
|
|
249
|
+
"Default output shows link-item tokens only (token names ending with link-item).",
|
|
250
|
+
"Default includes app and installed-package placement-linked token sources.",
|
|
251
|
+
"Use --prefix to narrow quickly (recommended: --prefix local.main.).",
|
|
252
|
+
"Use --all when you want the full discovered token set.",
|
|
253
|
+
"Shows plain text by default; use --json for structured output."
|
|
254
|
+
]),
|
|
255
|
+
fullUse: "jskit list-link-items [--prefix <value>] [--all] [--json]",
|
|
256
|
+
showHelpOnBareInvocation: false,
|
|
257
|
+
handlerName: "commandListLinkItems",
|
|
258
|
+
allowedFlagKeys: Object.freeze(["json", "all"]),
|
|
259
|
+
inlineOptionMode: "enumerated",
|
|
260
|
+
allowedValueOptionNames: Object.freeze(["prefix"])
|
|
261
|
+
}),
|
|
262
|
+
show: Object.freeze({
|
|
263
|
+
command: "show",
|
|
264
|
+
aliases: Object.freeze(["view"]),
|
|
265
|
+
showInOverview: true,
|
|
266
|
+
summary: "Show detailed metadata for a bundle or package.",
|
|
267
|
+
minimalUse: "jskit show <id>",
|
|
268
|
+
parameters: Object.freeze([
|
|
269
|
+
Object.freeze({
|
|
270
|
+
name: "<id>",
|
|
271
|
+
description: "Bundle id or package id to inspect."
|
|
272
|
+
})
|
|
273
|
+
]),
|
|
274
|
+
defaults: Object.freeze([
|
|
275
|
+
"view is an alias of show.",
|
|
276
|
+
"Basic output is compact; --details expands capability and runtime sections.",
|
|
277
|
+
"--debug-exports implies --details."
|
|
278
|
+
]),
|
|
279
|
+
fullUse: "jskit show <id> [--details] [--debug-exports] [--json]",
|
|
280
|
+
showHelpOnBareInvocation: true,
|
|
281
|
+
handlerName: "commandShow",
|
|
282
|
+
allowedFlagKeys: Object.freeze(["details", "debugExports", "json"]),
|
|
283
|
+
inlineOptionMode: "none",
|
|
284
|
+
allowedValueOptionNames: Object.freeze([])
|
|
285
|
+
}),
|
|
286
|
+
migrations: Object.freeze({
|
|
287
|
+
command: "migrations",
|
|
288
|
+
aliases: Object.freeze([]),
|
|
289
|
+
showInOverview: true,
|
|
290
|
+
summary: "Generate managed migration files only.",
|
|
291
|
+
minimalUse: "jskit migrations changed",
|
|
292
|
+
parameters: Object.freeze([
|
|
293
|
+
Object.freeze({
|
|
294
|
+
name: "<scope>",
|
|
295
|
+
description: "all | changed | package."
|
|
296
|
+
}),
|
|
297
|
+
Object.freeze({
|
|
298
|
+
name: "[packageId]",
|
|
299
|
+
description: "Required only when scope is package."
|
|
300
|
+
})
|
|
301
|
+
]),
|
|
302
|
+
defaults: Object.freeze([
|
|
303
|
+
"Inline options are accepted only for 'migrations package <packageId>'.",
|
|
304
|
+
"This command only materializes managed migration files; it does not run npm install.",
|
|
305
|
+
"Without --json, output lists touched migration files."
|
|
306
|
+
]),
|
|
307
|
+
fullUse: "jskit migrations <all|changed|package> [packageId] [--<option> <value>...] [--dry-run] [--json] [--verbose]",
|
|
308
|
+
showHelpOnBareInvocation: true,
|
|
309
|
+
handlerName: "commandMigrations",
|
|
310
|
+
allowedFlagKeys: Object.freeze(["dryRun", "json", "verbose"]),
|
|
311
|
+
inlineOptionMode: "delegate",
|
|
312
|
+
allowedValueOptionNames: Object.freeze([]),
|
|
313
|
+
canDelegateInlineOptions: canDelegateMigrationsInlineOptions
|
|
314
|
+
}),
|
|
315
|
+
position: Object.freeze({
|
|
316
|
+
command: "position",
|
|
317
|
+
aliases: Object.freeze([]),
|
|
318
|
+
showInOverview: true,
|
|
319
|
+
summary: "Re-apply positioning-only mutations for an installed package.",
|
|
320
|
+
minimalUse: "jskit position element <packageId>",
|
|
321
|
+
parameters: Object.freeze([
|
|
322
|
+
Object.freeze({
|
|
323
|
+
name: "element",
|
|
324
|
+
description: "Target type for positioning command."
|
|
325
|
+
}),
|
|
326
|
+
Object.freeze({
|
|
327
|
+
name: "<packageId>",
|
|
328
|
+
description: "Installed package id to re-position."
|
|
329
|
+
})
|
|
330
|
+
]),
|
|
331
|
+
defaults: Object.freeze([
|
|
332
|
+
"Only positioning mutations are applied.",
|
|
333
|
+
"This command does not run npm install.",
|
|
334
|
+
"Reads current options from lock unless overridden inline."
|
|
335
|
+
]),
|
|
336
|
+
fullUse: "jskit position element <packageId> [--<option> <value>...] [--dry-run] [--json]",
|
|
337
|
+
showHelpOnBareInvocation: true,
|
|
338
|
+
handlerName: "commandPosition",
|
|
339
|
+
allowedFlagKeys: Object.freeze(["dryRun", "json"]),
|
|
340
|
+
inlineOptionMode: "delegate",
|
|
341
|
+
allowedValueOptionNames: Object.freeze([]),
|
|
342
|
+
canDelegateInlineOptions: (positional = []) => canDelegatePackageTargetInlineOptions(positional, "element")
|
|
343
|
+
}),
|
|
344
|
+
update: Object.freeze({
|
|
345
|
+
command: "update",
|
|
346
|
+
aliases: Object.freeze([]),
|
|
347
|
+
showInOverview: true,
|
|
348
|
+
summary: "Re-apply one installed package.",
|
|
349
|
+
minimalUse: "jskit update package <packageId>",
|
|
350
|
+
parameters: Object.freeze([
|
|
351
|
+
Object.freeze({
|
|
352
|
+
name: "package",
|
|
353
|
+
description: "Target type for update command."
|
|
354
|
+
}),
|
|
355
|
+
Object.freeze({
|
|
356
|
+
name: "<packageId>",
|
|
357
|
+
description: "Installed package id to re-apply."
|
|
358
|
+
})
|
|
359
|
+
]),
|
|
360
|
+
defaults: Object.freeze([
|
|
361
|
+
"No npm install runs unless --run-npm-install is passed.",
|
|
362
|
+
"Existing lock options are reused unless overridden inline.",
|
|
363
|
+
"update reuses add package flow with forced reapply."
|
|
364
|
+
]),
|
|
365
|
+
fullUse: "jskit update package <packageId> [--<option> <value>...] [--dry-run] [--run-npm-install] [--json]",
|
|
366
|
+
showHelpOnBareInvocation: true,
|
|
367
|
+
handlerName: "commandUpdate",
|
|
368
|
+
allowedFlagKeys: Object.freeze(["dryRun", "runNpmInstall", "json"]),
|
|
369
|
+
inlineOptionMode: "delegate",
|
|
370
|
+
allowedValueOptionNames: Object.freeze([]),
|
|
371
|
+
canDelegateInlineOptions: (positional = []) => canDelegatePackageTargetInlineOptions(positional, "package")
|
|
372
|
+
}),
|
|
373
|
+
remove: Object.freeze({
|
|
374
|
+
command: "remove",
|
|
375
|
+
aliases: Object.freeze([]),
|
|
376
|
+
showInOverview: true,
|
|
377
|
+
summary: "Remove one installed package.",
|
|
378
|
+
minimalUse: "jskit remove package <packageId>",
|
|
379
|
+
parameters: Object.freeze([
|
|
380
|
+
Object.freeze({
|
|
381
|
+
name: "package",
|
|
382
|
+
description: "Target type for remove command."
|
|
383
|
+
}),
|
|
384
|
+
Object.freeze({
|
|
385
|
+
name: "<packageId>",
|
|
386
|
+
description: "Installed package id to remove."
|
|
387
|
+
})
|
|
388
|
+
]),
|
|
389
|
+
defaults: Object.freeze([
|
|
390
|
+
"No npm install runs unless --run-npm-install is passed.",
|
|
391
|
+
"Managed files and lock entries are removed for the package.",
|
|
392
|
+
"Local package source directories are not deleted."
|
|
393
|
+
]),
|
|
394
|
+
fullUse: "jskit remove package <packageId> [--dry-run] [--run-npm-install] [--json]",
|
|
395
|
+
showHelpOnBareInvocation: true,
|
|
396
|
+
handlerName: "commandRemove",
|
|
397
|
+
allowedFlagKeys: Object.freeze(["dryRun", "runNpmInstall", "json"]),
|
|
398
|
+
inlineOptionMode: "none",
|
|
399
|
+
allowedValueOptionNames: Object.freeze([])
|
|
400
|
+
}),
|
|
401
|
+
doctor: Object.freeze({
|
|
402
|
+
command: "doctor",
|
|
403
|
+
aliases: Object.freeze([]),
|
|
404
|
+
showInOverview: true,
|
|
405
|
+
summary: "Validate lockfile and managed-file integrity.",
|
|
406
|
+
minimalUse: "jskit doctor",
|
|
407
|
+
parameters: Object.freeze([]),
|
|
408
|
+
defaults: Object.freeze([
|
|
409
|
+
"Validates lock entries, managed files, and registry visibility.",
|
|
410
|
+
"Reports issues as plain text by default.",
|
|
411
|
+
"Use --json for machine-readable diagnostics."
|
|
412
|
+
]),
|
|
413
|
+
fullUse: "jskit doctor [--json]",
|
|
414
|
+
showHelpOnBareInvocation: false,
|
|
415
|
+
handlerName: "commandDoctor",
|
|
416
|
+
allowedFlagKeys: Object.freeze(["json"]),
|
|
417
|
+
inlineOptionMode: "none",
|
|
418
|
+
allowedValueOptionNames: Object.freeze([])
|
|
419
|
+
}),
|
|
420
|
+
"lint-descriptors": Object.freeze({
|
|
421
|
+
command: "lint-descriptors",
|
|
422
|
+
aliases: Object.freeze([]),
|
|
423
|
+
showInOverview: true,
|
|
424
|
+
summary: "Validate bundle and package descriptor contracts.",
|
|
425
|
+
minimalUse: "jskit lint-descriptors",
|
|
426
|
+
parameters: Object.freeze([]),
|
|
427
|
+
defaults: Object.freeze([
|
|
428
|
+
"Runs descriptor consistency checks.",
|
|
429
|
+
"check-di-labels is optional and adds stricter DI token label checks.",
|
|
430
|
+
"Outputs plain text by default and supports --json."
|
|
431
|
+
]),
|
|
432
|
+
fullUse: "jskit lint-descriptors [--check-di-labels] [--json]",
|
|
433
|
+
showHelpOnBareInvocation: false,
|
|
434
|
+
handlerName: "commandLintDescriptors",
|
|
435
|
+
allowedFlagKeys: Object.freeze(["checkDiLabels", "json"]),
|
|
436
|
+
inlineOptionMode: "none",
|
|
437
|
+
allowedValueOptionNames: Object.freeze([])
|
|
438
|
+
})
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
const COMMAND_ALIAS_TO_ID = Object.freeze(
|
|
442
|
+
Object.fromEntries(
|
|
443
|
+
Object.values(COMMAND_DESCRIPTORS)
|
|
444
|
+
.flatMap((descriptor) =>
|
|
445
|
+
Array.isArray(descriptor.aliases)
|
|
446
|
+
? descriptor.aliases.map((alias) => [alias, descriptor.command])
|
|
447
|
+
: [])
|
|
448
|
+
.sort((left, right) => String(left[0] || "").localeCompare(String(right[0] || "")))
|
|
449
|
+
)
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
const COMMAND_IDS = Object.freeze(Object.keys(COMMAND_DESCRIPTORS));
|
|
453
|
+
const KNOWN_COMMANDS = new Set(COMMAND_IDS);
|
|
454
|
+
|
|
30
455
|
function resolveCommandAlias(rawCommand) {
|
|
31
456
|
const command = String(rawCommand || "").trim();
|
|
32
457
|
if (!command) {
|
|
33
458
|
return "";
|
|
34
459
|
}
|
|
35
|
-
return
|
|
460
|
+
return COMMAND_ALIAS_TO_ID[command] || command;
|
|
36
461
|
}
|
|
37
462
|
|
|
38
|
-
function
|
|
463
|
+
function resolveCommandDescriptor(rawCommand) {
|
|
39
464
|
const command = resolveCommandAlias(rawCommand);
|
|
40
465
|
if (!command) {
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
return COMMAND_DESCRIPTORS[command] || null;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function isKnownCommandName(rawCommand) {
|
|
472
|
+
const descriptor = resolveCommandDescriptor(rawCommand);
|
|
473
|
+
return Boolean(descriptor && KNOWN_COMMANDS.has(descriptor.command));
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function listOverviewCommandDescriptors() {
|
|
477
|
+
return Object.values(COMMAND_DESCRIPTORS)
|
|
478
|
+
.filter((descriptor) => descriptor.showInOverview !== false)
|
|
479
|
+
.sort((left, right) => left.command.localeCompare(right.command));
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function shouldShowCommandHelpOnBareInvocation(command = "", positional = []) {
|
|
483
|
+
const descriptor = resolveCommandDescriptor(command);
|
|
484
|
+
if (!descriptor || descriptor.showHelpOnBareInvocation !== true) {
|
|
41
485
|
return false;
|
|
42
486
|
}
|
|
43
|
-
|
|
487
|
+
const argumentList = Array.isArray(positional) ? positional : [];
|
|
488
|
+
return argumentList.length < 1;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function sortOptionLabels(labels = []) {
|
|
492
|
+
return [...new Set((Array.isArray(labels) ? labels : []).filter(Boolean))]
|
|
493
|
+
.sort((left, right) => left.localeCompare(right));
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function validateCommandOptions(
|
|
497
|
+
{ command = "", positional = [], options = {} } = {},
|
|
498
|
+
{ createCliError, renderUsage = null } = {}
|
|
499
|
+
) {
|
|
500
|
+
if (typeof createCliError !== "function") {
|
|
501
|
+
throw new TypeError("validateCommandOptions requires createCliError.");
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
const descriptor = resolveCommandDescriptor(command);
|
|
505
|
+
if (!descriptor) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
const allowedFlagKeys = new Set(Array.isArray(descriptor.allowedFlagKeys) ? descriptor.allowedFlagKeys : []);
|
|
510
|
+
const unsupportedOptionLabels = [];
|
|
511
|
+
for (const flagKey of PARSED_BOOLEAN_OPTION_KEYS) {
|
|
512
|
+
if (options?.[flagKey] !== true) {
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
if (!allowedFlagKeys.has(flagKey)) {
|
|
516
|
+
unsupportedOptionLabels.push(OPTION_FLAG_LABELS[flagKey]);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
const inlineOptions = options && typeof options === "object" ? options.inlineOptions : null;
|
|
521
|
+
const inlineOptionNames = Object.keys(inlineOptions && typeof inlineOptions === "object" ? inlineOptions : {});
|
|
522
|
+
const inlineOptionMode = String(descriptor.inlineOptionMode || "none").trim().toLowerCase() || "none";
|
|
523
|
+
if (inlineOptionMode === "none") {
|
|
524
|
+
for (const optionName of inlineOptionNames) {
|
|
525
|
+
unsupportedOptionLabels.push(`--${optionName}`);
|
|
526
|
+
}
|
|
527
|
+
} else if (inlineOptionMode === "enumerated") {
|
|
528
|
+
const allowedValueOptionNames = new Set(
|
|
529
|
+
Array.isArray(descriptor.allowedValueOptionNames) ? descriptor.allowedValueOptionNames : []
|
|
530
|
+
);
|
|
531
|
+
for (const optionName of inlineOptionNames) {
|
|
532
|
+
if (!allowedValueOptionNames.has(optionName)) {
|
|
533
|
+
unsupportedOptionLabels.push(`--${optionName}`);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
} else if (
|
|
537
|
+
inlineOptionMode === "delegate" &&
|
|
538
|
+
inlineOptionNames.length > 0 &&
|
|
539
|
+
typeof descriptor.canDelegateInlineOptions === "function" &&
|
|
540
|
+
descriptor.canDelegateInlineOptions(positional) !== true
|
|
541
|
+
) {
|
|
542
|
+
for (const optionName of inlineOptionNames) {
|
|
543
|
+
unsupportedOptionLabels.push(`--${optionName}`);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const normalizedUnsupportedLabels = sortOptionLabels(unsupportedOptionLabels);
|
|
548
|
+
if (normalizedUnsupportedLabels.length < 1) {
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
throw createCliError(
|
|
553
|
+
`Unknown option${normalizedUnsupportedLabels.length === 1 ? "" : "s"} for command ${descriptor.command}: ${normalizedUnsupportedLabels.join(", ")}.`,
|
|
554
|
+
{
|
|
555
|
+
renderUsage: typeof renderUsage === "function" ? renderUsage : null
|
|
556
|
+
}
|
|
557
|
+
);
|
|
44
558
|
}
|
|
45
559
|
|
|
46
560
|
export {
|
|
47
|
-
|
|
561
|
+
COMMAND_IDS,
|
|
562
|
+
OPTION_FLAG_LABELS,
|
|
48
563
|
resolveCommandAlias,
|
|
49
|
-
|
|
564
|
+
resolveCommandDescriptor,
|
|
565
|
+
isKnownCommandName,
|
|
566
|
+
listOverviewCommandDescriptors,
|
|
567
|
+
shouldShowCommandHelpOnBareInvocation,
|
|
568
|
+
validateCommandOptions
|
|
50
569
|
};
|
|
@@ -15,6 +15,10 @@ import {
|
|
|
15
15
|
import { createCommandHandlers } from "./createCommandHandlers.js";
|
|
16
16
|
import { parseArgs } from "./argParser.js";
|
|
17
17
|
import { printUsage, shouldShowCommandHelpOnBareInvocation } from "./usageHelp.js";
|
|
18
|
+
import {
|
|
19
|
+
resolveCommandDescriptor,
|
|
20
|
+
validateCommandOptions
|
|
21
|
+
} from "./commandCatalog.js";
|
|
18
22
|
import { createCommandHandlerDeps } from "./buildCommandDeps.js";
|
|
19
23
|
import { createRunCli } from "./dispatchCli.js";
|
|
20
24
|
import {
|
|
@@ -148,6 +152,8 @@ const runCli = createRunCli({
|
|
|
148
152
|
parseArgs,
|
|
149
153
|
printUsage,
|
|
150
154
|
shouldShowCommandHelpOnBareInvocation,
|
|
155
|
+
validateCommandOptions,
|
|
156
|
+
resolveCommandDescriptor,
|
|
151
157
|
commandHandlers,
|
|
152
158
|
cleanupMaterializedPackageRoots,
|
|
153
159
|
createCliError
|