@seedcli/core 0.1.0
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/LICENSE +21 -0
- package/dist/command/help.d.ts +59 -0
- package/dist/command/help.d.ts.map +1 -0
- package/dist/command/help.js +216 -0
- package/dist/command/help.js.map +1 -0
- package/dist/command/parser.d.ts +27 -0
- package/dist/command/parser.d.ts.map +1 -0
- package/dist/command/parser.js +259 -0
- package/dist/command/parser.js.map +1 -0
- package/dist/command/router.d.ts +34 -0
- package/dist/command/router.d.ts.map +1 -0
- package/dist/command/router.js +90 -0
- package/dist/command/router.js.map +1 -0
- package/dist/discovery/auto-discover.d.ts +26 -0
- package/dist/discovery/auto-discover.d.ts.map +1 -0
- package/dist/discovery/auto-discover.js +138 -0
- package/dist/discovery/auto-discover.js.map +1 -0
- package/dist/discovery/index.d.ts +3 -0
- package/dist/discovery/index.d.ts.map +1 -0
- package/dist/discovery/index.js +2 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/errors.d.ts +23 -0
- package/dist/plugin/errors.d.ts.map +1 -0
- package/dist/plugin/errors.js +45 -0
- package/dist/plugin/errors.js.map +1 -0
- package/dist/plugin/index.d.ts +6 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +6 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/loader.d.ts +12 -0
- package/dist/plugin/loader.d.ts.map +1 -0
- package/dist/plugin/loader.js +33 -0
- package/dist/plugin/loader.js.map +1 -0
- package/dist/plugin/registry.d.ts +32 -0
- package/dist/plugin/registry.d.ts.map +1 -0
- package/dist/plugin/registry.js +101 -0
- package/dist/plugin/registry.js.map +1 -0
- package/dist/plugin/topo-sort.d.ts +8 -0
- package/dist/plugin/topo-sort.d.ts.map +1 -0
- package/dist/plugin/topo-sort.js +60 -0
- package/dist/plugin/topo-sort.js.map +1 -0
- package/dist/plugin/validator.d.ts +17 -0
- package/dist/plugin/validator.d.ts.map +1 -0
- package/dist/plugin/validator.js +58 -0
- package/dist/plugin/validator.js.map +1 -0
- package/dist/runtime/builder.d.ts +70 -0
- package/dist/runtime/builder.d.ts.map +1 -0
- package/dist/runtime/builder.js +108 -0
- package/dist/runtime/builder.js.map +1 -0
- package/dist/runtime/runtime.d.ts +53 -0
- package/dist/runtime/runtime.d.ts.map +1 -0
- package/dist/runtime/runtime.js +424 -0
- package/dist/runtime/runtime.js.map +1 -0
- package/dist/types/args.d.ts +93 -0
- package/dist/types/args.d.ts.map +1 -0
- package/dist/types/args.js +9 -0
- package/dist/types/args.js.map +1 -0
- package/dist/types/command.d.ts +60 -0
- package/dist/types/command.d.ts.map +1 -0
- package/dist/types/command.js +26 -0
- package/dist/types/command.js.map +1 -0
- package/dist/types/config.d.ts +61 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +17 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/extension.d.ts +30 -0
- package/dist/types/extension.d.ts.map +1 -0
- package/dist/types/extension.js +16 -0
- package/dist/types/extension.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/modules.d.ts +47 -0
- package/dist/types/modules.d.ts.map +1 -0
- package/dist/types/modules.js +5 -0
- package/dist/types/modules.js.map +1 -0
- package/dist/types/plugin.d.ts +40 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/plugin.js +17 -0
- package/dist/types/plugin.js.map +1 -0
- package/dist/types/toolbox.d.ts +54 -0
- package/dist/types/toolbox.d.ts.map +1 -0
- package/dist/types/toolbox.js +2 -0
- package/dist/types/toolbox.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { renderCommandHelp, renderGlobalHelp } from "../command/help.js";
|
|
2
|
+
import { ParseError, parse } from "../command/parser.js";
|
|
3
|
+
import { route } from "../command/router.js";
|
|
4
|
+
import { discover } from "../discovery/auto-discover.js";
|
|
5
|
+
import { ExtensionSetupError } from "../plugin/errors.js";
|
|
6
|
+
import { loadPlugins } from "../plugin/loader.js";
|
|
7
|
+
import { PluginRegistry } from "../plugin/registry.js";
|
|
8
|
+
import { topoSort } from "../plugin/topo-sort.js";
|
|
9
|
+
import { validateSeedcliVersion } from "../plugin/validator.js";
|
|
10
|
+
/**
|
|
11
|
+
* Quick-start function for simple CLIs without the builder pattern.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { run } from "@seedcli/core";
|
|
15
|
+
*
|
|
16
|
+
* await run({
|
|
17
|
+
* name: "mycli",
|
|
18
|
+
* version: "1.0.0",
|
|
19
|
+
* commands: [hello, deploy],
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export async function run(config) {
|
|
24
|
+
const { build } = await import("./builder.js");
|
|
25
|
+
const builder = build(config.name).commands(config.commands).help().version(config.version);
|
|
26
|
+
if (config.defaultCommand) {
|
|
27
|
+
builder.defaultCommand(config.defaultCommand);
|
|
28
|
+
}
|
|
29
|
+
const runtime = builder.create();
|
|
30
|
+
await runtime.run();
|
|
31
|
+
}
|
|
32
|
+
const DEFAULT_SETUP_TIMEOUT = 10_000;
|
|
33
|
+
/**
|
|
34
|
+
* The CLI runtime — executes the full lifecycle:
|
|
35
|
+
* 1. Load and validate plugins
|
|
36
|
+
* 2. Parse argv
|
|
37
|
+
* 3. Route to command
|
|
38
|
+
* 4. Run extensions setup (topological order)
|
|
39
|
+
* 5. Execute middleware chain
|
|
40
|
+
* 6. Run command handler
|
|
41
|
+
* 7. Run extensions teardown (reverse order)
|
|
42
|
+
*/
|
|
43
|
+
export class Runtime {
|
|
44
|
+
config;
|
|
45
|
+
registry = new PluginRegistry();
|
|
46
|
+
initialized = false;
|
|
47
|
+
constructor(config) {
|
|
48
|
+
this.config = config;
|
|
49
|
+
}
|
|
50
|
+
async run(argv) {
|
|
51
|
+
const raw = argv ?? process.argv.slice(2);
|
|
52
|
+
try {
|
|
53
|
+
// ─── Handle --version ───
|
|
54
|
+
if (this.config.versionEnabled && (raw.includes("--version") || raw.includes("-v"))) {
|
|
55
|
+
const version = this.config.version ?? "0.0.0";
|
|
56
|
+
console.log(`${this.config.brand} v${version}`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// ─── Handle --help (global) ───
|
|
60
|
+
if (this.config.helpEnabled && raw.length === 0) {
|
|
61
|
+
await this.initPlugins();
|
|
62
|
+
this.printGlobalHelp();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (this.config.helpEnabled &&
|
|
66
|
+
(raw.includes("--help") || raw.includes("-h")) &&
|
|
67
|
+
raw.length === 1) {
|
|
68
|
+
await this.initPlugins();
|
|
69
|
+
this.printGlobalHelp();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// ─── Initialize plugins ───
|
|
73
|
+
await this.initPlugins();
|
|
74
|
+
// ─── Route to command ───
|
|
75
|
+
const result = route(raw, this.config.commands);
|
|
76
|
+
if (!result.command) {
|
|
77
|
+
// Try default command
|
|
78
|
+
if (this.config.defaultCommand) {
|
|
79
|
+
await this.executeCommand(this.config.defaultCommand, raw);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// No match — show suggestions or help
|
|
83
|
+
if (result.suggestions.length > 0) {
|
|
84
|
+
const suggestions = result.suggestions
|
|
85
|
+
.map((s) => ` ${s.name} ${s.description ?? ""}`)
|
|
86
|
+
.join("\n");
|
|
87
|
+
console.error(`Command "${raw[0]}" not found.\n\nDid you mean?\n${suggestions}\n\nRun \`${this.config.brand} --help\` for a list of available commands.`);
|
|
88
|
+
}
|
|
89
|
+
else if (this.config.helpEnabled) {
|
|
90
|
+
this.printGlobalHelp();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
console.error(`Command "${raw[0]}" not found.`);
|
|
94
|
+
}
|
|
95
|
+
process.exitCode = 1;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
// ─── Handle per-command --help ───
|
|
99
|
+
if (this.config.helpEnabled && result.argv.includes("--help")) {
|
|
100
|
+
const helpText = renderCommandHelp(result.command, {
|
|
101
|
+
brand: this.config.brand,
|
|
102
|
+
...this.config.helpOptions,
|
|
103
|
+
});
|
|
104
|
+
console.log(helpText);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
// ─── Execute command ───
|
|
108
|
+
await this.executeCommand(result.command, result.argv);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
await this.handleError(err);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async initPlugins() {
|
|
115
|
+
if (this.initialized)
|
|
116
|
+
return;
|
|
117
|
+
this.initialized = true;
|
|
118
|
+
// ─── Auto-discovery ───
|
|
119
|
+
if (this.config.srcDir) {
|
|
120
|
+
const discovered = await discover(this.config.srcDir);
|
|
121
|
+
this.config.commands.push(...discovered.commands);
|
|
122
|
+
this.config.extensions.push(...discovered.extensions);
|
|
123
|
+
}
|
|
124
|
+
// ─── Scan plugin directories ───
|
|
125
|
+
for (const { dir, options } of this.config.pluginDirs) {
|
|
126
|
+
const scanned = await this.scanPluginDir(dir, options?.matching);
|
|
127
|
+
this.config.plugins.push(...scanned);
|
|
128
|
+
}
|
|
129
|
+
if (this.config.plugins.length === 0) {
|
|
130
|
+
// Still inject completions even without plugins
|
|
131
|
+
if (this.config.completionsEnabled) {
|
|
132
|
+
this.config.commands.push(this.createCompletionsCommand());
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
// Load all plugin configs (dynamic imports for string sources)
|
|
137
|
+
const loaded = await loadPlugins(this.config.plugins);
|
|
138
|
+
// Validate seedcli version compatibility
|
|
139
|
+
const runtimeVersion = this.config.version ?? "0.0.0";
|
|
140
|
+
for (const plugin of loaded) {
|
|
141
|
+
validateSeedcliVersion(plugin, runtimeVersion);
|
|
142
|
+
}
|
|
143
|
+
// Register each plugin (validates on register, deduplicates, checks conflicts)
|
|
144
|
+
for (const plugin of loaded) {
|
|
145
|
+
this.registry.register(plugin);
|
|
146
|
+
}
|
|
147
|
+
// Validate peer dependencies across all plugins
|
|
148
|
+
this.registry.validateAll();
|
|
149
|
+
// Merge plugin commands into config
|
|
150
|
+
const pluginCommands = this.registry.commands();
|
|
151
|
+
this.config.commands.push(...pluginCommands);
|
|
152
|
+
// Merge plugin extensions into config
|
|
153
|
+
const pluginExtensions = this.registry.extensions();
|
|
154
|
+
this.config.extensions.push(...pluginExtensions);
|
|
155
|
+
// Inject completions command if enabled
|
|
156
|
+
if (this.config.completionsEnabled) {
|
|
157
|
+
this.config.commands.push(this.createCompletionsCommand());
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async scanPluginDir(dir, matching) {
|
|
161
|
+
const { resolve } = await import("node:path");
|
|
162
|
+
const { readdir } = await import("node:fs/promises");
|
|
163
|
+
const resolvedDir = resolve(dir);
|
|
164
|
+
const entries = await readdir(resolvedDir, { withFileTypes: true });
|
|
165
|
+
const pluginPaths = [];
|
|
166
|
+
for (const entry of entries) {
|
|
167
|
+
if (!entry.isDirectory())
|
|
168
|
+
continue;
|
|
169
|
+
if (matching) {
|
|
170
|
+
const glob = new Bun.Glob(matching);
|
|
171
|
+
if (!glob.match(entry.name))
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
pluginPaths.push(resolve(resolvedDir, entry.name));
|
|
175
|
+
}
|
|
176
|
+
return pluginPaths;
|
|
177
|
+
}
|
|
178
|
+
async executeCommand(cmd, argv) {
|
|
179
|
+
// Parse args and flags
|
|
180
|
+
const parsed = parse(argv, cmd);
|
|
181
|
+
// Assemble toolbox
|
|
182
|
+
const toolbox = this.assembleToolbox(parsed.args, parsed.flags, cmd.name);
|
|
183
|
+
// Run onReady
|
|
184
|
+
if (this.config.onReady) {
|
|
185
|
+
await this.config.onReady(toolbox);
|
|
186
|
+
}
|
|
187
|
+
// ─── Run extension setup (topological order) ───
|
|
188
|
+
const allExtensions = [...this.config.extensions];
|
|
189
|
+
const sorted = allExtensions.length > 0 ? topoSort(allExtensions) : [];
|
|
190
|
+
const setupCompleted = [];
|
|
191
|
+
for (const ext of sorted) {
|
|
192
|
+
await this.runExtensionSetup(ext, toolbox);
|
|
193
|
+
setupCompleted.push(ext);
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
// Build middleware chain
|
|
197
|
+
const allMiddleware = [...this.config.middleware, ...(cmd.middleware ?? [])];
|
|
198
|
+
if (allMiddleware.length > 0) {
|
|
199
|
+
await this.runMiddleware(allMiddleware, toolbox, async () => {
|
|
200
|
+
if (cmd.run) {
|
|
201
|
+
await cmd.run(toolbox);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
else if (cmd.run) {
|
|
206
|
+
await cmd.run(toolbox);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
// ─── Run extension teardown (reverse order) ───
|
|
211
|
+
for (const ext of [...setupCompleted].reverse()) {
|
|
212
|
+
if (ext.teardown) {
|
|
213
|
+
try {
|
|
214
|
+
await ext.teardown(toolbox);
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
// Teardown errors are swallowed to ensure all teardowns run
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
async runExtensionSetup(ext, toolbox) {
|
|
224
|
+
const timeout = DEFAULT_SETUP_TIMEOUT;
|
|
225
|
+
const setupPromise = Promise.resolve(ext.setup(toolbox));
|
|
226
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
227
|
+
setTimeout(() => {
|
|
228
|
+
reject(new ExtensionSetupError(`Extension "${ext.name}" setup timed out after ${timeout}ms`, ext.name));
|
|
229
|
+
}, timeout);
|
|
230
|
+
});
|
|
231
|
+
await Promise.race([setupPromise, timeoutPromise]);
|
|
232
|
+
}
|
|
233
|
+
async runMiddleware(middleware, toolbox, final) {
|
|
234
|
+
let index = 0;
|
|
235
|
+
const next = async () => {
|
|
236
|
+
if (index < middleware.length) {
|
|
237
|
+
const fn = middleware[index++];
|
|
238
|
+
await fn(toolbox, next);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
await final();
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
await next();
|
|
245
|
+
}
|
|
246
|
+
assembleToolbox(args, flags, commandName) {
|
|
247
|
+
const cache = {};
|
|
248
|
+
const excluded = new Set(this.config.excludeModules ?? []);
|
|
249
|
+
const toolbox = {
|
|
250
|
+
args,
|
|
251
|
+
flags,
|
|
252
|
+
parameters: {
|
|
253
|
+
raw: process.argv.slice(2),
|
|
254
|
+
argv: Object.values(args).map(String),
|
|
255
|
+
command: commandName,
|
|
256
|
+
},
|
|
257
|
+
meta: {
|
|
258
|
+
version: this.config.version ?? "0.0.0",
|
|
259
|
+
commandName,
|
|
260
|
+
brand: this.config.brand,
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
// [toolbox key, package name, named export to extract]
|
|
264
|
+
// When a named export is specified, that export is used instead of the
|
|
265
|
+
// full module namespace. This is needed when the module's namespace
|
|
266
|
+
// contains raw functions whose signatures differ from the toolbox
|
|
267
|
+
// interface (e.g. @seedcli/print exports table() returning string,
|
|
268
|
+
// but PrintModule.table() returns void because it logs automatically).
|
|
269
|
+
const modules = [
|
|
270
|
+
["print", "@seedcli/print", "print"],
|
|
271
|
+
["prompt", "@seedcli/prompt"],
|
|
272
|
+
["filesystem", "@seedcli/filesystem"],
|
|
273
|
+
["system", "@seedcli/system"],
|
|
274
|
+
["http", "@seedcli/http"],
|
|
275
|
+
["template", "@seedcli/template"],
|
|
276
|
+
["strings", "@seedcli/strings"],
|
|
277
|
+
["semver", "@seedcli/semver"],
|
|
278
|
+
["packageManager", "@seedcli/package-manager"],
|
|
279
|
+
["config", "@seedcli/config"],
|
|
280
|
+
["patching", "@seedcli/patching"],
|
|
281
|
+
];
|
|
282
|
+
for (const [name, pkg, namedExport] of modules) {
|
|
283
|
+
if (excluded.has(name)) {
|
|
284
|
+
Object.defineProperty(toolbox, name, {
|
|
285
|
+
get: () => {
|
|
286
|
+
throw new Error(`The "${name}" module was excluded from this CLI. To use it, remove "${name}" from the .exclude() call in your CLI builder.`);
|
|
287
|
+
},
|
|
288
|
+
enumerable: true,
|
|
289
|
+
configurable: true,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
Object.defineProperty(toolbox, name, {
|
|
294
|
+
get: () => {
|
|
295
|
+
if (!cache[name]) {
|
|
296
|
+
const mod = require(pkg);
|
|
297
|
+
cache[name] = namedExport ? mod[namedExport] : mod;
|
|
298
|
+
}
|
|
299
|
+
return cache[name];
|
|
300
|
+
},
|
|
301
|
+
enumerable: true,
|
|
302
|
+
configurable: true,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return toolbox;
|
|
307
|
+
}
|
|
308
|
+
extractCompletionInfo() {
|
|
309
|
+
return {
|
|
310
|
+
brand: this.config.brand,
|
|
311
|
+
commands: this.config.commands
|
|
312
|
+
.filter((c) => c.name !== "completions" && !c.hidden)
|
|
313
|
+
.map((cmd) => ({
|
|
314
|
+
name: cmd.name,
|
|
315
|
+
description: cmd.description,
|
|
316
|
+
aliases: cmd.alias,
|
|
317
|
+
subcommands: cmd.subcommands?.map((sub) => ({
|
|
318
|
+
name: sub.name,
|
|
319
|
+
description: sub.description,
|
|
320
|
+
flags: sub.flags
|
|
321
|
+
? Object.entries(sub.flags).map(([name, def]) => ({
|
|
322
|
+
name,
|
|
323
|
+
alias: def.alias,
|
|
324
|
+
description: def.description,
|
|
325
|
+
type: def.type,
|
|
326
|
+
choices: def.choices,
|
|
327
|
+
}))
|
|
328
|
+
: undefined,
|
|
329
|
+
})),
|
|
330
|
+
flags: cmd.flags
|
|
331
|
+
? Object.entries(cmd.flags).map(([name, def]) => ({
|
|
332
|
+
name,
|
|
333
|
+
alias: def.alias,
|
|
334
|
+
description: def.description,
|
|
335
|
+
type: def.type,
|
|
336
|
+
choices: def.choices,
|
|
337
|
+
}))
|
|
338
|
+
: undefined,
|
|
339
|
+
args: cmd.args
|
|
340
|
+
? Object.entries(cmd.args).map(([name, def]) => ({
|
|
341
|
+
name,
|
|
342
|
+
description: def.description,
|
|
343
|
+
choices: def.choices,
|
|
344
|
+
}))
|
|
345
|
+
: undefined,
|
|
346
|
+
})),
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
createCompletionsCommand() {
|
|
350
|
+
return {
|
|
351
|
+
name: "completions",
|
|
352
|
+
description: "Generate shell completion scripts",
|
|
353
|
+
subcommands: [
|
|
354
|
+
{
|
|
355
|
+
name: "install",
|
|
356
|
+
description: "Auto-detect shell and install completions",
|
|
357
|
+
run: async () => {
|
|
358
|
+
const { install } = await import("@seedcli/completions");
|
|
359
|
+
const info = this.extractCompletionInfo();
|
|
360
|
+
const result = await install(info);
|
|
361
|
+
console.log(`Installed ${result.shell} completions to ${result.path}`);
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
name: "bash",
|
|
366
|
+
description: "Print bash completion script",
|
|
367
|
+
run: async () => {
|
|
368
|
+
const { bash } = await import("@seedcli/completions");
|
|
369
|
+
console.log(bash(this.extractCompletionInfo()));
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
name: "zsh",
|
|
374
|
+
description: "Print zsh completion script",
|
|
375
|
+
run: async () => {
|
|
376
|
+
const { zsh } = await import("@seedcli/completions");
|
|
377
|
+
console.log(zsh(this.extractCompletionInfo()));
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
name: "fish",
|
|
382
|
+
description: "Print fish completion script",
|
|
383
|
+
run: async () => {
|
|
384
|
+
const { fish } = await import("@seedcli/completions");
|
|
385
|
+
console.log(fish(this.extractCompletionInfo()));
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
name: "powershell",
|
|
390
|
+
description: "Print PowerShell completion script",
|
|
391
|
+
run: async () => {
|
|
392
|
+
const { powershell } = await import("@seedcli/completions");
|
|
393
|
+
console.log(powershell(this.extractCompletionInfo()));
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
],
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
printGlobalHelp() {
|
|
400
|
+
const helpText = renderGlobalHelp(this.config.commands, {
|
|
401
|
+
brand: this.config.brand,
|
|
402
|
+
version: this.config.version,
|
|
403
|
+
...this.config.helpOptions,
|
|
404
|
+
});
|
|
405
|
+
console.log(helpText);
|
|
406
|
+
}
|
|
407
|
+
async handleError(err) {
|
|
408
|
+
if (err instanceof ParseError) {
|
|
409
|
+
console.error(`ERROR: ${err.message}`);
|
|
410
|
+
process.exitCode = 1;
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
414
|
+
if (this.config.onError) {
|
|
415
|
+
const toolbox = this.assembleToolbox({}, {}, "");
|
|
416
|
+
await this.config.onError(error, toolbox);
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
console.error(`ERROR: ${error.message}`);
|
|
420
|
+
process.exitCode = 1;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/runtime/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM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@ -0,0 +1,93 @@
|
|
|
1
|
+
export type ArgType = "string" | "number";
|
|
2
|
+
export interface ArgDef<TType extends ArgType = ArgType, TRequired extends boolean = boolean, TChoices extends readonly string[] | undefined = readonly string[] | undefined, TDefault extends string | number | undefined = string | number | undefined> {
|
|
3
|
+
type: TType;
|
|
4
|
+
required?: TRequired;
|
|
5
|
+
choices?: TChoices;
|
|
6
|
+
default?: TDefault;
|
|
7
|
+
description?: string;
|
|
8
|
+
validate?: (value: unknown) => boolean | string;
|
|
9
|
+
}
|
|
10
|
+
export type FlagType = "boolean" | "string" | "number" | "string[]" | "number[]";
|
|
11
|
+
export interface FlagDef<TType extends FlagType = FlagType, TRequired extends boolean = boolean, TChoices extends readonly string[] | undefined = readonly string[] | undefined, TDefault = unknown> {
|
|
12
|
+
type: TType;
|
|
13
|
+
required?: TRequired;
|
|
14
|
+
choices?: TChoices;
|
|
15
|
+
default?: TDefault;
|
|
16
|
+
alias?: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
hidden?: boolean;
|
|
19
|
+
validate?: (value: unknown) => boolean | string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolve the TypeScript type for an arg definition.
|
|
23
|
+
*
|
|
24
|
+
* Priority:
|
|
25
|
+
* 1. If choices are defined → union of choices
|
|
26
|
+
* 2. Else use the declared type (string | number)
|
|
27
|
+
* 3. If required or has default → non-optional
|
|
28
|
+
* 4. Else → T | undefined
|
|
29
|
+
*/
|
|
30
|
+
export type ResolveArgType<T extends ArgDef> = T extends {
|
|
31
|
+
choices: readonly (infer C)[];
|
|
32
|
+
} ? T extends {
|
|
33
|
+
required: true;
|
|
34
|
+
} ? C : T extends {
|
|
35
|
+
default: infer _D;
|
|
36
|
+
} ? C : C | undefined : T extends {
|
|
37
|
+
type: "number";
|
|
38
|
+
} ? T extends {
|
|
39
|
+
required: true;
|
|
40
|
+
} ? number : T extends {
|
|
41
|
+
default: infer _D;
|
|
42
|
+
} ? number : number | undefined : T extends {
|
|
43
|
+
required: true;
|
|
44
|
+
} ? string : T extends {
|
|
45
|
+
default: infer _D;
|
|
46
|
+
} ? string : string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Resolve the TypeScript type for a flag definition.
|
|
49
|
+
*/
|
|
50
|
+
export type ResolveFlagType<T extends FlagDef> = T extends {
|
|
51
|
+
type: "boolean";
|
|
52
|
+
} ? T extends {
|
|
53
|
+
default: infer _D;
|
|
54
|
+
} ? boolean : boolean | undefined : T extends {
|
|
55
|
+
type: "string";
|
|
56
|
+
} ? T extends {
|
|
57
|
+
choices: readonly (infer C)[];
|
|
58
|
+
} ? T extends {
|
|
59
|
+
required: true;
|
|
60
|
+
} ? C : T extends {
|
|
61
|
+
default: infer _D;
|
|
62
|
+
} ? C : C | undefined : T extends {
|
|
63
|
+
required: true;
|
|
64
|
+
} ? string : T extends {
|
|
65
|
+
default: infer _D;
|
|
66
|
+
} ? string : string | undefined : T extends {
|
|
67
|
+
type: "number";
|
|
68
|
+
} ? T extends {
|
|
69
|
+
required: true;
|
|
70
|
+
} ? number : T extends {
|
|
71
|
+
default: infer _D;
|
|
72
|
+
} ? number : number | undefined : T extends {
|
|
73
|
+
type: "string[]";
|
|
74
|
+
} ? T extends {
|
|
75
|
+
required: true;
|
|
76
|
+
} ? string[] : T extends {
|
|
77
|
+
default: infer _D;
|
|
78
|
+
} ? string[] : string[] | undefined : T extends {
|
|
79
|
+
type: "number[]";
|
|
80
|
+
} ? T extends {
|
|
81
|
+
required: true;
|
|
82
|
+
} ? number[] : T extends {
|
|
83
|
+
default: infer _D;
|
|
84
|
+
} ? number[] : number[] | undefined : unknown;
|
|
85
|
+
export type InferArgs<T extends Record<string, ArgDef>> = {
|
|
86
|
+
[K in keyof T]: ResolveArgType<T[K]>;
|
|
87
|
+
};
|
|
88
|
+
export type InferFlags<T extends Record<string, FlagDef>> = {
|
|
89
|
+
[K in keyof T]: ResolveFlagType<T[K]>;
|
|
90
|
+
};
|
|
91
|
+
export declare function arg<TType extends ArgType, TRequired extends boolean = false, TChoices extends readonly string[] | undefined = undefined, TDefault extends string | number | undefined = undefined>(def: ArgDef<TType, TRequired, TChoices, TDefault>): ArgDef<TType, TRequired, TChoices, TDefault>;
|
|
92
|
+
export declare function flag<TType extends FlagType, TRequired extends boolean = false, TChoices extends readonly string[] | undefined = undefined, TDefault = undefined>(def: FlagDef<TType, TRequired, TChoices, TDefault>): FlagDef<TType, TRequired, TChoices, TDefault>;
|
|
93
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../src/types/args.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE1C,MAAM,WAAW,MAAM,CACtB,KAAK,SAAS,OAAO,GAAG,OAAO,EAC/B,SAAS,SAAS,OAAO,GAAG,OAAO,EACnC,QAAQ,SAAS,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,EAC9E,QAAQ,SAAS,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS;IAE1E,IAAI,EAAE,KAAK,CAAC;IACZ,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,GAAG,MAAM,CAAC;CAChD;AAID,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC;AAEjF,MAAM,WAAW,OAAO,CACvB,KAAK,SAAS,QAAQ,GAAG,QAAQ,EACjC,SAAS,SAAS,OAAO,GAAG,OAAO,EACnC,QAAQ,SAAS,SAAS,MAAM,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AU,GAAG,CAKjB,GAAiD;IAClD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,IAAI,CAMnB,GAAkD;IAElD,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ArgDef, FlagDef, InferArgs, InferFlags } from "./args.js";
|
|
2
|
+
import type { Toolbox } from "./toolbox.js";
|
|
3
|
+
export type Middleware = (toolbox: Toolbox<Record<string, unknown>, Record<string, unknown>>, next: () => Promise<void>) => Promise<void> | void;
|
|
4
|
+
export interface CommandConfig<TArgs extends Record<string, ArgDef> = Record<string, ArgDef>, TFlags extends Record<string, FlagDef> = Record<string, FlagDef>> {
|
|
5
|
+
/** Command name (used for routing) */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Human-readable description (shown in help) */
|
|
8
|
+
description?: string;
|
|
9
|
+
/** Alternative names for this command */
|
|
10
|
+
alias?: string[];
|
|
11
|
+
/** Hide from help output */
|
|
12
|
+
hidden?: boolean;
|
|
13
|
+
/** Positional argument definitions */
|
|
14
|
+
args?: TArgs;
|
|
15
|
+
/** Flag/option definitions */
|
|
16
|
+
flags?: TFlags;
|
|
17
|
+
/** Nested subcommands */
|
|
18
|
+
subcommands?: Command[];
|
|
19
|
+
/** Per-command middleware */
|
|
20
|
+
middleware?: Middleware[];
|
|
21
|
+
/** The command handler */
|
|
22
|
+
run?: (toolbox: Toolbox<InferArgs<TArgs>, InferFlags<TFlags>>) => Promise<void> | void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A resolved command object (output of `command()`).
|
|
26
|
+
*/
|
|
27
|
+
export interface Command {
|
|
28
|
+
name: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
alias?: string[];
|
|
31
|
+
hidden?: boolean;
|
|
32
|
+
args?: Record<string, ArgDef>;
|
|
33
|
+
flags?: Record<string, FlagDef>;
|
|
34
|
+
subcommands?: Command[];
|
|
35
|
+
middleware?: Middleware[];
|
|
36
|
+
run?: (toolbox: Toolbox<Record<string, unknown>, Record<string, unknown>>) => Promise<void> | void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Define a command with full type inference for args and flags.
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* const greet = command({
|
|
43
|
+
* name: "greet",
|
|
44
|
+
* args: {
|
|
45
|
+
* name: arg({ type: "string", required: true }),
|
|
46
|
+
* },
|
|
47
|
+
* flags: {
|
|
48
|
+
* loud: flag({ type: "boolean", default: false }),
|
|
49
|
+
* },
|
|
50
|
+
* run: async ({ args, flags, print }) => {
|
|
51
|
+
* // args.name: string (inferred as required)
|
|
52
|
+
* // flags.loud: boolean (inferred from default)
|
|
53
|
+
* const msg = `Hello, ${args.name}!`;
|
|
54
|
+
* print.info(flags.loud ? msg.toUpperCase() : msg);
|
|
55
|
+
* },
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function command<TArgs extends Record<string, ArgDef>, TFlags extends Record<string, FlagDef>>(config: CommandConfig<TArgs, TFlags>): Command;
|
|
60
|
+
//# sourceMappingURL=command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/types/command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C,MAAM,MAAM,UAAU,GAAG,CACxB,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAClE,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KACrB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAI1B,MAAM,WAAW,aAAa,CAC7B,KA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OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KAC9D,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC1B;AAID;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,OAAO,CACtB,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,MAAM,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,CAE/C"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// ─── Command Factory ───
|
|
2
|
+
/**
|
|
3
|
+
* Define a command with full type inference for args and flags.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* const greet = command({
|
|
7
|
+
* name: "greet",
|
|
8
|
+
* args: {
|
|
9
|
+
* name: arg({ type: "string", required: true }),
|
|
10
|
+
* },
|
|
11
|
+
* flags: {
|
|
12
|
+
* loud: flag({ type: "boolean", default: false }),
|
|
13
|
+
* },
|
|
14
|
+
* run: async ({ args, flags, print }) => {
|
|
15
|
+
* // args.name: string (inferred as required)
|
|
16
|
+
* // flags.loud: boolean (inferred from default)
|
|
17
|
+
* const msg = `Hello, ${args.name}!`;
|
|
18
|
+
* print.info(flags.loud ? msg.toUpperCase() : msg);
|
|
19
|
+
* },
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function command(config) {
|
|
24
|
+
return config;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/types/command.ts"],"names":[],"mappings":"AA6DA,0BAA0B;AAE1B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,OAAO,CAGrB,MAAoC;IACrC,OAAO,MAA4B,CAAC;AACrC,CAAC"}
|