@jskit-ai/jskit-cli 0.2.10 → 0.2.12
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 -2
- package/src/server/argParser.js +187 -0
- package/src/server/cliEntrypoint.js +1 -14
- package/src/server/cliError.js +1 -8
- package/src/server/cliRuntime.js +4359 -0
- package/src/server/index.js +1 -4604
- package/src/server/optionInterpolation.js +19 -7
- package/src/server/runCli.js +103 -0
- package/src/server/runtimeDeps.js +55 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/jskit-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"description": "Bundle and package orchestration CLI for JSKIT apps.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"test": "node --test"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@jskit-ai/
|
|
23
|
+
"@jskit-ai/cli-runtime": "0.1.0",
|
|
24
|
+
"@jskit-ai/jskit-catalog": "0.1.12"
|
|
24
25
|
},
|
|
25
26
|
"engines": {
|
|
26
27
|
"node": "20.x"
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
const KNOWN_COMMANDS = new Set([
|
|
2
|
+
"help",
|
|
3
|
+
"create",
|
|
4
|
+
"list",
|
|
5
|
+
"show",
|
|
6
|
+
"view",
|
|
7
|
+
"add",
|
|
8
|
+
"position",
|
|
9
|
+
"update",
|
|
10
|
+
"remove",
|
|
11
|
+
"doctor",
|
|
12
|
+
"lint-descriptors"
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
const COMMAND_ALIASES = Object.freeze({
|
|
16
|
+
view: "show",
|
|
17
|
+
ls: "list"
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function resolveCommandAlias(rawCommand) {
|
|
21
|
+
const command = String(rawCommand || "").trim();
|
|
22
|
+
if (!command) {
|
|
23
|
+
return "";
|
|
24
|
+
}
|
|
25
|
+
return COMMAND_ALIASES[command] || command;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function parseArgs(argv, { createCliError } = {}) {
|
|
29
|
+
if (typeof createCliError !== "function") {
|
|
30
|
+
throw new TypeError("parseArgs requires createCliError.");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const args = Array.isArray(argv) ? [...argv] : [];
|
|
34
|
+
const firstToken = String(args[0] || "").trim();
|
|
35
|
+
if (firstToken === "--help" || firstToken === "-h") {
|
|
36
|
+
args.shift();
|
|
37
|
+
return {
|
|
38
|
+
command: "help",
|
|
39
|
+
options: {
|
|
40
|
+
dryRun: false,
|
|
41
|
+
noInstall: false,
|
|
42
|
+
full: false,
|
|
43
|
+
expanded: false,
|
|
44
|
+
details: false,
|
|
45
|
+
debugExports: false,
|
|
46
|
+
json: false,
|
|
47
|
+
all: false,
|
|
48
|
+
help: true,
|
|
49
|
+
inlineOptions: {}
|
|
50
|
+
},
|
|
51
|
+
positional: []
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const rawCommand = String(args.shift() || "help").trim() || "help";
|
|
56
|
+
const command = resolveCommandAlias(rawCommand);
|
|
57
|
+
|
|
58
|
+
if (!KNOWN_COMMANDS.has(command)) {
|
|
59
|
+
throw createCliError(`Unknown command: ${rawCommand}`, { showUsage: true });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const options = {
|
|
63
|
+
dryRun: false,
|
|
64
|
+
noInstall: false,
|
|
65
|
+
full: false,
|
|
66
|
+
expanded: false,
|
|
67
|
+
details: false,
|
|
68
|
+
debugExports: false,
|
|
69
|
+
json: false,
|
|
70
|
+
all: false,
|
|
71
|
+
help: false,
|
|
72
|
+
inlineOptions: {}
|
|
73
|
+
};
|
|
74
|
+
const positional = [];
|
|
75
|
+
|
|
76
|
+
while (args.length > 0) {
|
|
77
|
+
const token = String(args.shift() || "");
|
|
78
|
+
|
|
79
|
+
if (token === "--dry-run") {
|
|
80
|
+
options.dryRun = true;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (token === "--no-install") {
|
|
84
|
+
options.noInstall = true;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (token === "--full") {
|
|
88
|
+
options.full = true;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (token === "--expanded") {
|
|
92
|
+
options.expanded = true;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (token === "--details") {
|
|
96
|
+
options.details = true;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (token === "--debug-exports") {
|
|
100
|
+
options.debugExports = true;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (token === "--json") {
|
|
104
|
+
options.json = true;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (token === "--all") {
|
|
108
|
+
options.all = true;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (token === "--help" || token === "-h") {
|
|
112
|
+
options.help = true;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (token.startsWith("--")) {
|
|
117
|
+
const withoutPrefix = token.slice(2);
|
|
118
|
+
const hasInlineValue = withoutPrefix.includes("=");
|
|
119
|
+
const optionName = hasInlineValue ? withoutPrefix.slice(0, withoutPrefix.indexOf("=")) : withoutPrefix;
|
|
120
|
+
const optionValueRaw = hasInlineValue
|
|
121
|
+
? withoutPrefix.slice(withoutPrefix.indexOf("=") + 1)
|
|
122
|
+
: args.shift();
|
|
123
|
+
|
|
124
|
+
if (!/^[a-z][a-z0-9-]*$/.test(optionName)) {
|
|
125
|
+
throw createCliError(`Unknown option: ${token}`, { showUsage: true });
|
|
126
|
+
}
|
|
127
|
+
if (typeof optionValueRaw !== "string") {
|
|
128
|
+
throw createCliError(`--${optionName} requires a value.`, { showUsage: true });
|
|
129
|
+
}
|
|
130
|
+
const optionValue = optionValueRaw.trim();
|
|
131
|
+
if (!hasInlineValue && optionValue.startsWith("-")) {
|
|
132
|
+
throw createCliError(`--${optionName} requires a value.`, { showUsage: true });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
options.inlineOptions[optionName] = optionValue;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (token.startsWith("-")) {
|
|
140
|
+
throw createCliError(`Unknown option: ${token}`, { showUsage: true });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
positional.push(token);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (options.debugExports) {
|
|
147
|
+
options.details = true;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
command,
|
|
152
|
+
options,
|
|
153
|
+
positional
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function printUsage(stream = process.stderr) {
|
|
158
|
+
stream.write("Usage: jskit <command> [options]\n\n");
|
|
159
|
+
stream.write("Commands:\n");
|
|
160
|
+
stream.write(" create package <name> Scaffold app-local package under packages/ and install it\n");
|
|
161
|
+
stream.write(" list [bundles [all]|packages] List available bundles/packages and installed status\n");
|
|
162
|
+
stream.write(" lint-descriptors Validate bundle/package descriptor files\n");
|
|
163
|
+
stream.write(" add bundle <bundleId> Add one bundle (bundle is a package shortcut)\n");
|
|
164
|
+
stream.write(" add package <packageId> Add one package to current app (catalog/app-local/installed external)\n");
|
|
165
|
+
stream.write(" position element <packageId> Re-apply positioning mutations for one installed package\n");
|
|
166
|
+
stream.write(" show <id> Show details for bundle id or package id\n");
|
|
167
|
+
stream.write(" view <id> Alias of show <id>\n");
|
|
168
|
+
stream.write(" update package <packageId> Re-apply one installed package\n");
|
|
169
|
+
stream.write(" remove package <packageId> Remove one installed package\n");
|
|
170
|
+
stream.write(" doctor Validate lockfile + managed files\n");
|
|
171
|
+
stream.write("\n");
|
|
172
|
+
stream.write("Options:\n");
|
|
173
|
+
stream.write(" --dry-run Print planned changes only\n");
|
|
174
|
+
stream.write(" --no-install Skip npm install during create/add/update/remove\n");
|
|
175
|
+
stream.write(" --scope <scope> (create package) override generated package scope\n");
|
|
176
|
+
stream.write(" --package-id <id> (create package) explicit @scope/name package id\n");
|
|
177
|
+
stream.write(" --description <text> (create package) descriptor description text\n");
|
|
178
|
+
stream.write(" --full Show bundle package ids (declared packages)\n");
|
|
179
|
+
stream.write(" --expanded Show expanded/transitive package ids\n");
|
|
180
|
+
stream.write(" --details Show extra capability detail in show output\n");
|
|
181
|
+
stream.write(" --debug-exports Show export provenance/re-export source details in show output\n");
|
|
182
|
+
stream.write(" --<option> <value> Package option (for packages requiring input)\n");
|
|
183
|
+
stream.write(" --json Print structured output\n");
|
|
184
|
+
stream.write(" -h, --help Show help\n");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export { parseArgs, printUsage };
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
async function runCliEntrypoint(runCli, argv = process.argv.slice(2)) {
|
|
4
|
-
if (typeof runCli !== "function") {
|
|
5
|
-
throw new TypeError("runCliEntrypoint requires a runCli function");
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const exitCode = await runCli(argv);
|
|
9
|
-
if (exitCode !== 0) {
|
|
10
|
-
process.exit(exitCode);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { runCliEntrypoint };
|
|
1
|
+
export { runCliEntrypoint } from "@jskit-ai/cli-runtime/server";
|
package/src/server/cliError.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const error = new Error(String(message || "Unknown CLI error"));
|
|
3
|
-
error.name = "CliError";
|
|
4
|
-
error.showUsage = Boolean(showUsage);
|
|
5
|
-
return error;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export { createCliError };
|
|
1
|
+
export { createCliError } from "@jskit-ai/cli-runtime/server";
|