zdev 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 +13 -0
- package/README.md +311 -0
- package/bun.lock +29 -0
- package/dist/index.js +3098 -0
- package/package.json +36 -0
- package/src/commands/clean.ts +122 -0
- package/src/commands/config.ts +105 -0
- package/src/commands/create.ts +381 -0
- package/src/commands/init.ts +80 -0
- package/src/commands/list.ts +78 -0
- package/src/commands/seed.ts +98 -0
- package/src/commands/start.ts +306 -0
- package/src/commands/stop.ts +101 -0
- package/src/config.ts +106 -0
- package/src/index.ts +129 -0
- package/src/utils.ts +230 -0
- package/tsconfig.json +17 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3098 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
10
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
11
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
12
|
+
for (let key of __getOwnPropNames(mod))
|
|
13
|
+
if (!__hasOwnProp.call(to, key))
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => mod[key],
|
|
16
|
+
enumerable: true
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
21
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
22
|
+
|
|
23
|
+
// node_modules/commander/lib/error.js
|
|
24
|
+
var require_error = __commonJS((exports) => {
|
|
25
|
+
class CommanderError extends Error {
|
|
26
|
+
constructor(exitCode, code, message) {
|
|
27
|
+
super(message);
|
|
28
|
+
Error.captureStackTrace(this, this.constructor);
|
|
29
|
+
this.name = this.constructor.name;
|
|
30
|
+
this.code = code;
|
|
31
|
+
this.exitCode = exitCode;
|
|
32
|
+
this.nestedError = undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
class InvalidArgumentError extends CommanderError {
|
|
37
|
+
constructor(message) {
|
|
38
|
+
super(1, "commander.invalidArgument", message);
|
|
39
|
+
Error.captureStackTrace(this, this.constructor);
|
|
40
|
+
this.name = this.constructor.name;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.CommanderError = CommanderError;
|
|
44
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// node_modules/commander/lib/argument.js
|
|
48
|
+
var require_argument = __commonJS((exports) => {
|
|
49
|
+
var { InvalidArgumentError } = require_error();
|
|
50
|
+
|
|
51
|
+
class Argument {
|
|
52
|
+
constructor(name, description) {
|
|
53
|
+
this.description = description || "";
|
|
54
|
+
this.variadic = false;
|
|
55
|
+
this.parseArg = undefined;
|
|
56
|
+
this.defaultValue = undefined;
|
|
57
|
+
this.defaultValueDescription = undefined;
|
|
58
|
+
this.argChoices = undefined;
|
|
59
|
+
switch (name[0]) {
|
|
60
|
+
case "<":
|
|
61
|
+
this.required = true;
|
|
62
|
+
this._name = name.slice(1, -1);
|
|
63
|
+
break;
|
|
64
|
+
case "[":
|
|
65
|
+
this.required = false;
|
|
66
|
+
this._name = name.slice(1, -1);
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
this.required = true;
|
|
70
|
+
this._name = name;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
if (this._name.length > 3 && this._name.slice(-3) === "...") {
|
|
74
|
+
this.variadic = true;
|
|
75
|
+
this._name = this._name.slice(0, -3);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
name() {
|
|
79
|
+
return this._name;
|
|
80
|
+
}
|
|
81
|
+
_concatValue(value, previous) {
|
|
82
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
83
|
+
return [value];
|
|
84
|
+
}
|
|
85
|
+
return previous.concat(value);
|
|
86
|
+
}
|
|
87
|
+
default(value, description) {
|
|
88
|
+
this.defaultValue = value;
|
|
89
|
+
this.defaultValueDescription = description;
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
argParser(fn) {
|
|
93
|
+
this.parseArg = fn;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
choices(values) {
|
|
97
|
+
this.argChoices = values.slice();
|
|
98
|
+
this.parseArg = (arg, previous) => {
|
|
99
|
+
if (!this.argChoices.includes(arg)) {
|
|
100
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
101
|
+
}
|
|
102
|
+
if (this.variadic) {
|
|
103
|
+
return this._concatValue(arg, previous);
|
|
104
|
+
}
|
|
105
|
+
return arg;
|
|
106
|
+
};
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
argRequired() {
|
|
110
|
+
this.required = true;
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
argOptional() {
|
|
114
|
+
this.required = false;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function humanReadableArgName(arg) {
|
|
119
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
120
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
121
|
+
}
|
|
122
|
+
exports.Argument = Argument;
|
|
123
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// node_modules/commander/lib/help.js
|
|
127
|
+
var require_help = __commonJS((exports) => {
|
|
128
|
+
var { humanReadableArgName } = require_argument();
|
|
129
|
+
|
|
130
|
+
class Help {
|
|
131
|
+
constructor() {
|
|
132
|
+
this.helpWidth = undefined;
|
|
133
|
+
this.sortSubcommands = false;
|
|
134
|
+
this.sortOptions = false;
|
|
135
|
+
this.showGlobalOptions = false;
|
|
136
|
+
}
|
|
137
|
+
visibleCommands(cmd) {
|
|
138
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
139
|
+
const helpCommand = cmd._getHelpCommand();
|
|
140
|
+
if (helpCommand && !helpCommand._hidden) {
|
|
141
|
+
visibleCommands.push(helpCommand);
|
|
142
|
+
}
|
|
143
|
+
if (this.sortSubcommands) {
|
|
144
|
+
visibleCommands.sort((a, b) => {
|
|
145
|
+
return a.name().localeCompare(b.name());
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return visibleCommands;
|
|
149
|
+
}
|
|
150
|
+
compareOptions(a, b) {
|
|
151
|
+
const getSortKey = (option) => {
|
|
152
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
153
|
+
};
|
|
154
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
155
|
+
}
|
|
156
|
+
visibleOptions(cmd) {
|
|
157
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
158
|
+
const helpOption = cmd._getHelpOption();
|
|
159
|
+
if (helpOption && !helpOption.hidden) {
|
|
160
|
+
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
161
|
+
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
162
|
+
if (!removeShort && !removeLong) {
|
|
163
|
+
visibleOptions.push(helpOption);
|
|
164
|
+
} else if (helpOption.long && !removeLong) {
|
|
165
|
+
visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
|
|
166
|
+
} else if (helpOption.short && !removeShort) {
|
|
167
|
+
visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (this.sortOptions) {
|
|
171
|
+
visibleOptions.sort(this.compareOptions);
|
|
172
|
+
}
|
|
173
|
+
return visibleOptions;
|
|
174
|
+
}
|
|
175
|
+
visibleGlobalOptions(cmd) {
|
|
176
|
+
if (!this.showGlobalOptions)
|
|
177
|
+
return [];
|
|
178
|
+
const globalOptions = [];
|
|
179
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
180
|
+
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
|
|
181
|
+
globalOptions.push(...visibleOptions);
|
|
182
|
+
}
|
|
183
|
+
if (this.sortOptions) {
|
|
184
|
+
globalOptions.sort(this.compareOptions);
|
|
185
|
+
}
|
|
186
|
+
return globalOptions;
|
|
187
|
+
}
|
|
188
|
+
visibleArguments(cmd) {
|
|
189
|
+
if (cmd._argsDescription) {
|
|
190
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
191
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
195
|
+
return cmd.registeredArguments;
|
|
196
|
+
}
|
|
197
|
+
return [];
|
|
198
|
+
}
|
|
199
|
+
subcommandTerm(cmd) {
|
|
200
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
201
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
202
|
+
}
|
|
203
|
+
optionTerm(option) {
|
|
204
|
+
return option.flags;
|
|
205
|
+
}
|
|
206
|
+
argumentTerm(argument) {
|
|
207
|
+
return argument.name();
|
|
208
|
+
}
|
|
209
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
210
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
211
|
+
return Math.max(max, helper.subcommandTerm(command).length);
|
|
212
|
+
}, 0);
|
|
213
|
+
}
|
|
214
|
+
longestOptionTermLength(cmd, helper) {
|
|
215
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
216
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
217
|
+
}, 0);
|
|
218
|
+
}
|
|
219
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
220
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
221
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
222
|
+
}, 0);
|
|
223
|
+
}
|
|
224
|
+
longestArgumentTermLength(cmd, helper) {
|
|
225
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
226
|
+
return Math.max(max, helper.argumentTerm(argument).length);
|
|
227
|
+
}, 0);
|
|
228
|
+
}
|
|
229
|
+
commandUsage(cmd) {
|
|
230
|
+
let cmdName = cmd._name;
|
|
231
|
+
if (cmd._aliases[0]) {
|
|
232
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
233
|
+
}
|
|
234
|
+
let ancestorCmdNames = "";
|
|
235
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
236
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
237
|
+
}
|
|
238
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
239
|
+
}
|
|
240
|
+
commandDescription(cmd) {
|
|
241
|
+
return cmd.description();
|
|
242
|
+
}
|
|
243
|
+
subcommandDescription(cmd) {
|
|
244
|
+
return cmd.summary() || cmd.description();
|
|
245
|
+
}
|
|
246
|
+
optionDescription(option) {
|
|
247
|
+
const extraInfo = [];
|
|
248
|
+
if (option.argChoices) {
|
|
249
|
+
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
250
|
+
}
|
|
251
|
+
if (option.defaultValue !== undefined) {
|
|
252
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
253
|
+
if (showDefault) {
|
|
254
|
+
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (option.presetArg !== undefined && option.optional) {
|
|
258
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
259
|
+
}
|
|
260
|
+
if (option.envVar !== undefined) {
|
|
261
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
262
|
+
}
|
|
263
|
+
if (extraInfo.length > 0) {
|
|
264
|
+
return `${option.description} (${extraInfo.join(", ")})`;
|
|
265
|
+
}
|
|
266
|
+
return option.description;
|
|
267
|
+
}
|
|
268
|
+
argumentDescription(argument) {
|
|
269
|
+
const extraInfo = [];
|
|
270
|
+
if (argument.argChoices) {
|
|
271
|
+
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
272
|
+
}
|
|
273
|
+
if (argument.defaultValue !== undefined) {
|
|
274
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
275
|
+
}
|
|
276
|
+
if (extraInfo.length > 0) {
|
|
277
|
+
const extraDescripton = `(${extraInfo.join(", ")})`;
|
|
278
|
+
if (argument.description) {
|
|
279
|
+
return `${argument.description} ${extraDescripton}`;
|
|
280
|
+
}
|
|
281
|
+
return extraDescripton;
|
|
282
|
+
}
|
|
283
|
+
return argument.description;
|
|
284
|
+
}
|
|
285
|
+
formatHelp(cmd, helper) {
|
|
286
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
287
|
+
const helpWidth = helper.helpWidth || 80;
|
|
288
|
+
const itemIndentWidth = 2;
|
|
289
|
+
const itemSeparatorWidth = 2;
|
|
290
|
+
function formatItem(term, description) {
|
|
291
|
+
if (description) {
|
|
292
|
+
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
293
|
+
return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
|
|
294
|
+
}
|
|
295
|
+
return term;
|
|
296
|
+
}
|
|
297
|
+
function formatList(textArray) {
|
|
298
|
+
return textArray.join(`
|
|
299
|
+
`).replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
300
|
+
}
|
|
301
|
+
let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
|
|
302
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
303
|
+
if (commandDescription.length > 0) {
|
|
304
|
+
output = output.concat([
|
|
305
|
+
helper.wrap(commandDescription, helpWidth, 0),
|
|
306
|
+
""
|
|
307
|
+
]);
|
|
308
|
+
}
|
|
309
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
310
|
+
return formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument));
|
|
311
|
+
});
|
|
312
|
+
if (argumentList.length > 0) {
|
|
313
|
+
output = output.concat(["Arguments:", formatList(argumentList), ""]);
|
|
314
|
+
}
|
|
315
|
+
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
316
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
317
|
+
});
|
|
318
|
+
if (optionList.length > 0) {
|
|
319
|
+
output = output.concat(["Options:", formatList(optionList), ""]);
|
|
320
|
+
}
|
|
321
|
+
if (this.showGlobalOptions) {
|
|
322
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
323
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
324
|
+
});
|
|
325
|
+
if (globalOptionList.length > 0) {
|
|
326
|
+
output = output.concat([
|
|
327
|
+
"Global Options:",
|
|
328
|
+
formatList(globalOptionList),
|
|
329
|
+
""
|
|
330
|
+
]);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
334
|
+
return formatItem(helper.subcommandTerm(cmd2), helper.subcommandDescription(cmd2));
|
|
335
|
+
});
|
|
336
|
+
if (commandList.length > 0) {
|
|
337
|
+
output = output.concat(["Commands:", formatList(commandList), ""]);
|
|
338
|
+
}
|
|
339
|
+
return output.join(`
|
|
340
|
+
`);
|
|
341
|
+
}
|
|
342
|
+
padWidth(cmd, helper) {
|
|
343
|
+
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
344
|
+
}
|
|
345
|
+
wrap(str, width, indent, minColumnWidth = 40) {
|
|
346
|
+
const indents = " \\f\\t\\v - \uFEFF";
|
|
347
|
+
const manualIndent = new RegExp(`[\\n][${indents}]+`);
|
|
348
|
+
if (str.match(manualIndent))
|
|
349
|
+
return str;
|
|
350
|
+
const columnWidth = width - indent;
|
|
351
|
+
if (columnWidth < minColumnWidth)
|
|
352
|
+
return str;
|
|
353
|
+
const leadingStr = str.slice(0, indent);
|
|
354
|
+
const columnText = str.slice(indent).replace(`\r
|
|
355
|
+
`, `
|
|
356
|
+
`);
|
|
357
|
+
const indentString = " ".repeat(indent);
|
|
358
|
+
const zeroWidthSpace = "";
|
|
359
|
+
const breaks = `\\s${zeroWidthSpace}`;
|
|
360
|
+
const regex = new RegExp(`
|
|
361
|
+
|.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`, "g");
|
|
362
|
+
const lines = columnText.match(regex) || [];
|
|
363
|
+
return leadingStr + lines.map((line, i) => {
|
|
364
|
+
if (line === `
|
|
365
|
+
`)
|
|
366
|
+
return "";
|
|
367
|
+
return (i > 0 ? indentString : "") + line.trimEnd();
|
|
368
|
+
}).join(`
|
|
369
|
+
`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
exports.Help = Help;
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// node_modules/commander/lib/option.js
|
|
376
|
+
var require_option = __commonJS((exports) => {
|
|
377
|
+
var { InvalidArgumentError } = require_error();
|
|
378
|
+
|
|
379
|
+
class Option {
|
|
380
|
+
constructor(flags, description) {
|
|
381
|
+
this.flags = flags;
|
|
382
|
+
this.description = description || "";
|
|
383
|
+
this.required = flags.includes("<");
|
|
384
|
+
this.optional = flags.includes("[");
|
|
385
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
386
|
+
this.mandatory = false;
|
|
387
|
+
const optionFlags = splitOptionFlags(flags);
|
|
388
|
+
this.short = optionFlags.shortFlag;
|
|
389
|
+
this.long = optionFlags.longFlag;
|
|
390
|
+
this.negate = false;
|
|
391
|
+
if (this.long) {
|
|
392
|
+
this.negate = this.long.startsWith("--no-");
|
|
393
|
+
}
|
|
394
|
+
this.defaultValue = undefined;
|
|
395
|
+
this.defaultValueDescription = undefined;
|
|
396
|
+
this.presetArg = undefined;
|
|
397
|
+
this.envVar = undefined;
|
|
398
|
+
this.parseArg = undefined;
|
|
399
|
+
this.hidden = false;
|
|
400
|
+
this.argChoices = undefined;
|
|
401
|
+
this.conflictsWith = [];
|
|
402
|
+
this.implied = undefined;
|
|
403
|
+
}
|
|
404
|
+
default(value, description) {
|
|
405
|
+
this.defaultValue = value;
|
|
406
|
+
this.defaultValueDescription = description;
|
|
407
|
+
return this;
|
|
408
|
+
}
|
|
409
|
+
preset(arg) {
|
|
410
|
+
this.presetArg = arg;
|
|
411
|
+
return this;
|
|
412
|
+
}
|
|
413
|
+
conflicts(names) {
|
|
414
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
415
|
+
return this;
|
|
416
|
+
}
|
|
417
|
+
implies(impliedOptionValues) {
|
|
418
|
+
let newImplied = impliedOptionValues;
|
|
419
|
+
if (typeof impliedOptionValues === "string") {
|
|
420
|
+
newImplied = { [impliedOptionValues]: true };
|
|
421
|
+
}
|
|
422
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
423
|
+
return this;
|
|
424
|
+
}
|
|
425
|
+
env(name) {
|
|
426
|
+
this.envVar = name;
|
|
427
|
+
return this;
|
|
428
|
+
}
|
|
429
|
+
argParser(fn) {
|
|
430
|
+
this.parseArg = fn;
|
|
431
|
+
return this;
|
|
432
|
+
}
|
|
433
|
+
makeOptionMandatory(mandatory = true) {
|
|
434
|
+
this.mandatory = !!mandatory;
|
|
435
|
+
return this;
|
|
436
|
+
}
|
|
437
|
+
hideHelp(hide = true) {
|
|
438
|
+
this.hidden = !!hide;
|
|
439
|
+
return this;
|
|
440
|
+
}
|
|
441
|
+
_concatValue(value, previous) {
|
|
442
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
443
|
+
return [value];
|
|
444
|
+
}
|
|
445
|
+
return previous.concat(value);
|
|
446
|
+
}
|
|
447
|
+
choices(values) {
|
|
448
|
+
this.argChoices = values.slice();
|
|
449
|
+
this.parseArg = (arg, previous) => {
|
|
450
|
+
if (!this.argChoices.includes(arg)) {
|
|
451
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
452
|
+
}
|
|
453
|
+
if (this.variadic) {
|
|
454
|
+
return this._concatValue(arg, previous);
|
|
455
|
+
}
|
|
456
|
+
return arg;
|
|
457
|
+
};
|
|
458
|
+
return this;
|
|
459
|
+
}
|
|
460
|
+
name() {
|
|
461
|
+
if (this.long) {
|
|
462
|
+
return this.long.replace(/^--/, "");
|
|
463
|
+
}
|
|
464
|
+
return this.short.replace(/^-/, "");
|
|
465
|
+
}
|
|
466
|
+
attributeName() {
|
|
467
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
468
|
+
}
|
|
469
|
+
is(arg) {
|
|
470
|
+
return this.short === arg || this.long === arg;
|
|
471
|
+
}
|
|
472
|
+
isBoolean() {
|
|
473
|
+
return !this.required && !this.optional && !this.negate;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
class DualOptions {
|
|
478
|
+
constructor(options) {
|
|
479
|
+
this.positiveOptions = new Map;
|
|
480
|
+
this.negativeOptions = new Map;
|
|
481
|
+
this.dualOptions = new Set;
|
|
482
|
+
options.forEach((option) => {
|
|
483
|
+
if (option.negate) {
|
|
484
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
485
|
+
} else {
|
|
486
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
this.negativeOptions.forEach((value, key) => {
|
|
490
|
+
if (this.positiveOptions.has(key)) {
|
|
491
|
+
this.dualOptions.add(key);
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
valueFromOption(value, option) {
|
|
496
|
+
const optionKey = option.attributeName();
|
|
497
|
+
if (!this.dualOptions.has(optionKey))
|
|
498
|
+
return true;
|
|
499
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
500
|
+
const negativeValue = preset !== undefined ? preset : false;
|
|
501
|
+
return option.negate === (negativeValue === value);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
function camelcase(str) {
|
|
505
|
+
return str.split("-").reduce((str2, word) => {
|
|
506
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
function splitOptionFlags(flags) {
|
|
510
|
+
let shortFlag;
|
|
511
|
+
let longFlag;
|
|
512
|
+
const flagParts = flags.split(/[ |,]+/);
|
|
513
|
+
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
514
|
+
shortFlag = flagParts.shift();
|
|
515
|
+
longFlag = flagParts.shift();
|
|
516
|
+
if (!shortFlag && /^-[^-]$/.test(longFlag)) {
|
|
517
|
+
shortFlag = longFlag;
|
|
518
|
+
longFlag = undefined;
|
|
519
|
+
}
|
|
520
|
+
return { shortFlag, longFlag };
|
|
521
|
+
}
|
|
522
|
+
exports.Option = Option;
|
|
523
|
+
exports.DualOptions = DualOptions;
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
// node_modules/commander/lib/suggestSimilar.js
|
|
527
|
+
var require_suggestSimilar = __commonJS((exports) => {
|
|
528
|
+
var maxDistance = 3;
|
|
529
|
+
function editDistance(a, b) {
|
|
530
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
531
|
+
return Math.max(a.length, b.length);
|
|
532
|
+
const d = [];
|
|
533
|
+
for (let i = 0;i <= a.length; i++) {
|
|
534
|
+
d[i] = [i];
|
|
535
|
+
}
|
|
536
|
+
for (let j = 0;j <= b.length; j++) {
|
|
537
|
+
d[0][j] = j;
|
|
538
|
+
}
|
|
539
|
+
for (let j = 1;j <= b.length; j++) {
|
|
540
|
+
for (let i = 1;i <= a.length; i++) {
|
|
541
|
+
let cost = 1;
|
|
542
|
+
if (a[i - 1] === b[j - 1]) {
|
|
543
|
+
cost = 0;
|
|
544
|
+
} else {
|
|
545
|
+
cost = 1;
|
|
546
|
+
}
|
|
547
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
548
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
549
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return d[a.length][b.length];
|
|
554
|
+
}
|
|
555
|
+
function suggestSimilar(word, candidates) {
|
|
556
|
+
if (!candidates || candidates.length === 0)
|
|
557
|
+
return "";
|
|
558
|
+
candidates = Array.from(new Set(candidates));
|
|
559
|
+
const searchingOptions = word.startsWith("--");
|
|
560
|
+
if (searchingOptions) {
|
|
561
|
+
word = word.slice(2);
|
|
562
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
563
|
+
}
|
|
564
|
+
let similar = [];
|
|
565
|
+
let bestDistance = maxDistance;
|
|
566
|
+
const minSimilarity = 0.4;
|
|
567
|
+
candidates.forEach((candidate) => {
|
|
568
|
+
if (candidate.length <= 1)
|
|
569
|
+
return;
|
|
570
|
+
const distance = editDistance(word, candidate);
|
|
571
|
+
const length = Math.max(word.length, candidate.length);
|
|
572
|
+
const similarity = (length - distance) / length;
|
|
573
|
+
if (similarity > minSimilarity) {
|
|
574
|
+
if (distance < bestDistance) {
|
|
575
|
+
bestDistance = distance;
|
|
576
|
+
similar = [candidate];
|
|
577
|
+
} else if (distance === bestDistance) {
|
|
578
|
+
similar.push(candidate);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
583
|
+
if (searchingOptions) {
|
|
584
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
585
|
+
}
|
|
586
|
+
if (similar.length > 1) {
|
|
587
|
+
return `
|
|
588
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
589
|
+
}
|
|
590
|
+
if (similar.length === 1) {
|
|
591
|
+
return `
|
|
592
|
+
(Did you mean ${similar[0]}?)`;
|
|
593
|
+
}
|
|
594
|
+
return "";
|
|
595
|
+
}
|
|
596
|
+
exports.suggestSimilar = suggestSimilar;
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
// node_modules/commander/lib/command.js
|
|
600
|
+
var require_command = __commonJS((exports) => {
|
|
601
|
+
var EventEmitter = __require("node:events").EventEmitter;
|
|
602
|
+
var childProcess = __require("node:child_process");
|
|
603
|
+
var path = __require("node:path");
|
|
604
|
+
var fs = __require("node:fs");
|
|
605
|
+
var process2 = __require("node:process");
|
|
606
|
+
var { Argument, humanReadableArgName } = require_argument();
|
|
607
|
+
var { CommanderError } = require_error();
|
|
608
|
+
var { Help } = require_help();
|
|
609
|
+
var { Option, DualOptions } = require_option();
|
|
610
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
611
|
+
|
|
612
|
+
class Command extends EventEmitter {
|
|
613
|
+
constructor(name) {
|
|
614
|
+
super();
|
|
615
|
+
this.commands = [];
|
|
616
|
+
this.options = [];
|
|
617
|
+
this.parent = null;
|
|
618
|
+
this._allowUnknownOption = false;
|
|
619
|
+
this._allowExcessArguments = true;
|
|
620
|
+
this.registeredArguments = [];
|
|
621
|
+
this._args = this.registeredArguments;
|
|
622
|
+
this.args = [];
|
|
623
|
+
this.rawArgs = [];
|
|
624
|
+
this.processedArgs = [];
|
|
625
|
+
this._scriptPath = null;
|
|
626
|
+
this._name = name || "";
|
|
627
|
+
this._optionValues = {};
|
|
628
|
+
this._optionValueSources = {};
|
|
629
|
+
this._storeOptionsAsProperties = false;
|
|
630
|
+
this._actionHandler = null;
|
|
631
|
+
this._executableHandler = false;
|
|
632
|
+
this._executableFile = null;
|
|
633
|
+
this._executableDir = null;
|
|
634
|
+
this._defaultCommandName = null;
|
|
635
|
+
this._exitCallback = null;
|
|
636
|
+
this._aliases = [];
|
|
637
|
+
this._combineFlagAndOptionalValue = true;
|
|
638
|
+
this._description = "";
|
|
639
|
+
this._summary = "";
|
|
640
|
+
this._argsDescription = undefined;
|
|
641
|
+
this._enablePositionalOptions = false;
|
|
642
|
+
this._passThroughOptions = false;
|
|
643
|
+
this._lifeCycleHooks = {};
|
|
644
|
+
this._showHelpAfterError = false;
|
|
645
|
+
this._showSuggestionAfterError = true;
|
|
646
|
+
this._outputConfiguration = {
|
|
647
|
+
writeOut: (str) => process2.stdout.write(str),
|
|
648
|
+
writeErr: (str) => process2.stderr.write(str),
|
|
649
|
+
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
|
|
650
|
+
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
|
|
651
|
+
outputError: (str, write) => write(str)
|
|
652
|
+
};
|
|
653
|
+
this._hidden = false;
|
|
654
|
+
this._helpOption = undefined;
|
|
655
|
+
this._addImplicitHelpCommand = undefined;
|
|
656
|
+
this._helpCommand = undefined;
|
|
657
|
+
this._helpConfiguration = {};
|
|
658
|
+
}
|
|
659
|
+
copyInheritedSettings(sourceCommand) {
|
|
660
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
661
|
+
this._helpOption = sourceCommand._helpOption;
|
|
662
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
663
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
664
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
665
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
666
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
667
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
668
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
669
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
670
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
671
|
+
return this;
|
|
672
|
+
}
|
|
673
|
+
_getCommandAndAncestors() {
|
|
674
|
+
const result = [];
|
|
675
|
+
for (let command = this;command; command = command.parent) {
|
|
676
|
+
result.push(command);
|
|
677
|
+
}
|
|
678
|
+
return result;
|
|
679
|
+
}
|
|
680
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
681
|
+
let desc = actionOptsOrExecDesc;
|
|
682
|
+
let opts = execOpts;
|
|
683
|
+
if (typeof desc === "object" && desc !== null) {
|
|
684
|
+
opts = desc;
|
|
685
|
+
desc = null;
|
|
686
|
+
}
|
|
687
|
+
opts = opts || {};
|
|
688
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
689
|
+
const cmd = this.createCommand(name);
|
|
690
|
+
if (desc) {
|
|
691
|
+
cmd.description(desc);
|
|
692
|
+
cmd._executableHandler = true;
|
|
693
|
+
}
|
|
694
|
+
if (opts.isDefault)
|
|
695
|
+
this._defaultCommandName = cmd._name;
|
|
696
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
697
|
+
cmd._executableFile = opts.executableFile || null;
|
|
698
|
+
if (args)
|
|
699
|
+
cmd.arguments(args);
|
|
700
|
+
this._registerCommand(cmd);
|
|
701
|
+
cmd.parent = this;
|
|
702
|
+
cmd.copyInheritedSettings(this);
|
|
703
|
+
if (desc)
|
|
704
|
+
return this;
|
|
705
|
+
return cmd;
|
|
706
|
+
}
|
|
707
|
+
createCommand(name) {
|
|
708
|
+
return new Command(name);
|
|
709
|
+
}
|
|
710
|
+
createHelp() {
|
|
711
|
+
return Object.assign(new Help, this.configureHelp());
|
|
712
|
+
}
|
|
713
|
+
configureHelp(configuration) {
|
|
714
|
+
if (configuration === undefined)
|
|
715
|
+
return this._helpConfiguration;
|
|
716
|
+
this._helpConfiguration = configuration;
|
|
717
|
+
return this;
|
|
718
|
+
}
|
|
719
|
+
configureOutput(configuration) {
|
|
720
|
+
if (configuration === undefined)
|
|
721
|
+
return this._outputConfiguration;
|
|
722
|
+
Object.assign(this._outputConfiguration, configuration);
|
|
723
|
+
return this;
|
|
724
|
+
}
|
|
725
|
+
showHelpAfterError(displayHelp = true) {
|
|
726
|
+
if (typeof displayHelp !== "string")
|
|
727
|
+
displayHelp = !!displayHelp;
|
|
728
|
+
this._showHelpAfterError = displayHelp;
|
|
729
|
+
return this;
|
|
730
|
+
}
|
|
731
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
732
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
733
|
+
return this;
|
|
734
|
+
}
|
|
735
|
+
addCommand(cmd, opts) {
|
|
736
|
+
if (!cmd._name) {
|
|
737
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
738
|
+
- specify the name in Command constructor or using .name()`);
|
|
739
|
+
}
|
|
740
|
+
opts = opts || {};
|
|
741
|
+
if (opts.isDefault)
|
|
742
|
+
this._defaultCommandName = cmd._name;
|
|
743
|
+
if (opts.noHelp || opts.hidden)
|
|
744
|
+
cmd._hidden = true;
|
|
745
|
+
this._registerCommand(cmd);
|
|
746
|
+
cmd.parent = this;
|
|
747
|
+
cmd._checkForBrokenPassThrough();
|
|
748
|
+
return this;
|
|
749
|
+
}
|
|
750
|
+
createArgument(name, description) {
|
|
751
|
+
return new Argument(name, description);
|
|
752
|
+
}
|
|
753
|
+
argument(name, description, fn, defaultValue) {
|
|
754
|
+
const argument = this.createArgument(name, description);
|
|
755
|
+
if (typeof fn === "function") {
|
|
756
|
+
argument.default(defaultValue).argParser(fn);
|
|
757
|
+
} else {
|
|
758
|
+
argument.default(fn);
|
|
759
|
+
}
|
|
760
|
+
this.addArgument(argument);
|
|
761
|
+
return this;
|
|
762
|
+
}
|
|
763
|
+
arguments(names) {
|
|
764
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
765
|
+
this.argument(detail);
|
|
766
|
+
});
|
|
767
|
+
return this;
|
|
768
|
+
}
|
|
769
|
+
addArgument(argument) {
|
|
770
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
771
|
+
if (previousArgument && previousArgument.variadic) {
|
|
772
|
+
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
773
|
+
}
|
|
774
|
+
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
775
|
+
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
776
|
+
}
|
|
777
|
+
this.registeredArguments.push(argument);
|
|
778
|
+
return this;
|
|
779
|
+
}
|
|
780
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
781
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
782
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
783
|
+
return this;
|
|
784
|
+
}
|
|
785
|
+
enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
786
|
+
const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
|
|
787
|
+
const helpDescription = description ?? "display help for command";
|
|
788
|
+
const helpCommand = this.createCommand(helpName);
|
|
789
|
+
helpCommand.helpOption(false);
|
|
790
|
+
if (helpArgs)
|
|
791
|
+
helpCommand.arguments(helpArgs);
|
|
792
|
+
if (helpDescription)
|
|
793
|
+
helpCommand.description(helpDescription);
|
|
794
|
+
this._addImplicitHelpCommand = true;
|
|
795
|
+
this._helpCommand = helpCommand;
|
|
796
|
+
return this;
|
|
797
|
+
}
|
|
798
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
799
|
+
if (typeof helpCommand !== "object") {
|
|
800
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
801
|
+
return this;
|
|
802
|
+
}
|
|
803
|
+
this._addImplicitHelpCommand = true;
|
|
804
|
+
this._helpCommand = helpCommand;
|
|
805
|
+
return this;
|
|
806
|
+
}
|
|
807
|
+
_getHelpCommand() {
|
|
808
|
+
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
809
|
+
if (hasImplicitHelpCommand) {
|
|
810
|
+
if (this._helpCommand === undefined) {
|
|
811
|
+
this.helpCommand(undefined, undefined);
|
|
812
|
+
}
|
|
813
|
+
return this._helpCommand;
|
|
814
|
+
}
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
hook(event, listener) {
|
|
818
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
819
|
+
if (!allowedValues.includes(event)) {
|
|
820
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
821
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
822
|
+
}
|
|
823
|
+
if (this._lifeCycleHooks[event]) {
|
|
824
|
+
this._lifeCycleHooks[event].push(listener);
|
|
825
|
+
} else {
|
|
826
|
+
this._lifeCycleHooks[event] = [listener];
|
|
827
|
+
}
|
|
828
|
+
return this;
|
|
829
|
+
}
|
|
830
|
+
exitOverride(fn) {
|
|
831
|
+
if (fn) {
|
|
832
|
+
this._exitCallback = fn;
|
|
833
|
+
} else {
|
|
834
|
+
this._exitCallback = (err) => {
|
|
835
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
836
|
+
throw err;
|
|
837
|
+
} else {}
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
return this;
|
|
841
|
+
}
|
|
842
|
+
_exit(exitCode, code, message) {
|
|
843
|
+
if (this._exitCallback) {
|
|
844
|
+
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
845
|
+
}
|
|
846
|
+
process2.exit(exitCode);
|
|
847
|
+
}
|
|
848
|
+
action(fn) {
|
|
849
|
+
const listener = (args) => {
|
|
850
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
851
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
852
|
+
if (this._storeOptionsAsProperties) {
|
|
853
|
+
actionArgs[expectedArgsCount] = this;
|
|
854
|
+
} else {
|
|
855
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
856
|
+
}
|
|
857
|
+
actionArgs.push(this);
|
|
858
|
+
return fn.apply(this, actionArgs);
|
|
859
|
+
};
|
|
860
|
+
this._actionHandler = listener;
|
|
861
|
+
return this;
|
|
862
|
+
}
|
|
863
|
+
createOption(flags, description) {
|
|
864
|
+
return new Option(flags, description);
|
|
865
|
+
}
|
|
866
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
867
|
+
try {
|
|
868
|
+
return target.parseArg(value, previous);
|
|
869
|
+
} catch (err) {
|
|
870
|
+
if (err.code === "commander.invalidArgument") {
|
|
871
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
872
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
873
|
+
}
|
|
874
|
+
throw err;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
_registerOption(option) {
|
|
878
|
+
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
879
|
+
if (matchingOption) {
|
|
880
|
+
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
881
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
882
|
+
- already used by option '${matchingOption.flags}'`);
|
|
883
|
+
}
|
|
884
|
+
this.options.push(option);
|
|
885
|
+
}
|
|
886
|
+
_registerCommand(command) {
|
|
887
|
+
const knownBy = (cmd) => {
|
|
888
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
889
|
+
};
|
|
890
|
+
const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
|
|
891
|
+
if (alreadyUsed) {
|
|
892
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
893
|
+
const newCmd = knownBy(command).join("|");
|
|
894
|
+
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
895
|
+
}
|
|
896
|
+
this.commands.push(command);
|
|
897
|
+
}
|
|
898
|
+
addOption(option) {
|
|
899
|
+
this._registerOption(option);
|
|
900
|
+
const oname = option.name();
|
|
901
|
+
const name = option.attributeName();
|
|
902
|
+
if (option.negate) {
|
|
903
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
904
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
905
|
+
this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
|
|
906
|
+
}
|
|
907
|
+
} else if (option.defaultValue !== undefined) {
|
|
908
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
909
|
+
}
|
|
910
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
911
|
+
if (val == null && option.presetArg !== undefined) {
|
|
912
|
+
val = option.presetArg;
|
|
913
|
+
}
|
|
914
|
+
const oldValue = this.getOptionValue(name);
|
|
915
|
+
if (val !== null && option.parseArg) {
|
|
916
|
+
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
917
|
+
} else if (val !== null && option.variadic) {
|
|
918
|
+
val = option._concatValue(val, oldValue);
|
|
919
|
+
}
|
|
920
|
+
if (val == null) {
|
|
921
|
+
if (option.negate) {
|
|
922
|
+
val = false;
|
|
923
|
+
} else if (option.isBoolean() || option.optional) {
|
|
924
|
+
val = true;
|
|
925
|
+
} else {
|
|
926
|
+
val = "";
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
930
|
+
};
|
|
931
|
+
this.on("option:" + oname, (val) => {
|
|
932
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
933
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
934
|
+
});
|
|
935
|
+
if (option.envVar) {
|
|
936
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
937
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
938
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
return this;
|
|
942
|
+
}
|
|
943
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
944
|
+
if (typeof flags === "object" && flags instanceof Option) {
|
|
945
|
+
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
946
|
+
}
|
|
947
|
+
const option = this.createOption(flags, description);
|
|
948
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
949
|
+
if (typeof fn === "function") {
|
|
950
|
+
option.default(defaultValue).argParser(fn);
|
|
951
|
+
} else if (fn instanceof RegExp) {
|
|
952
|
+
const regex = fn;
|
|
953
|
+
fn = (val, def) => {
|
|
954
|
+
const m = regex.exec(val);
|
|
955
|
+
return m ? m[0] : def;
|
|
956
|
+
};
|
|
957
|
+
option.default(defaultValue).argParser(fn);
|
|
958
|
+
} else {
|
|
959
|
+
option.default(fn);
|
|
960
|
+
}
|
|
961
|
+
return this.addOption(option);
|
|
962
|
+
}
|
|
963
|
+
option(flags, description, parseArg, defaultValue) {
|
|
964
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
965
|
+
}
|
|
966
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
967
|
+
return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
|
|
968
|
+
}
|
|
969
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
970
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
971
|
+
return this;
|
|
972
|
+
}
|
|
973
|
+
allowUnknownOption(allowUnknown = true) {
|
|
974
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
975
|
+
return this;
|
|
976
|
+
}
|
|
977
|
+
allowExcessArguments(allowExcess = true) {
|
|
978
|
+
this._allowExcessArguments = !!allowExcess;
|
|
979
|
+
return this;
|
|
980
|
+
}
|
|
981
|
+
enablePositionalOptions(positional = true) {
|
|
982
|
+
this._enablePositionalOptions = !!positional;
|
|
983
|
+
return this;
|
|
984
|
+
}
|
|
985
|
+
passThroughOptions(passThrough = true) {
|
|
986
|
+
this._passThroughOptions = !!passThrough;
|
|
987
|
+
this._checkForBrokenPassThrough();
|
|
988
|
+
return this;
|
|
989
|
+
}
|
|
990
|
+
_checkForBrokenPassThrough() {
|
|
991
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
992
|
+
throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
996
|
+
if (this.options.length) {
|
|
997
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
998
|
+
}
|
|
999
|
+
if (Object.keys(this._optionValues).length) {
|
|
1000
|
+
throw new Error("call .storeOptionsAsProperties() before setting option values");
|
|
1001
|
+
}
|
|
1002
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
1003
|
+
return this;
|
|
1004
|
+
}
|
|
1005
|
+
getOptionValue(key) {
|
|
1006
|
+
if (this._storeOptionsAsProperties) {
|
|
1007
|
+
return this[key];
|
|
1008
|
+
}
|
|
1009
|
+
return this._optionValues[key];
|
|
1010
|
+
}
|
|
1011
|
+
setOptionValue(key, value) {
|
|
1012
|
+
return this.setOptionValueWithSource(key, value, undefined);
|
|
1013
|
+
}
|
|
1014
|
+
setOptionValueWithSource(key, value, source) {
|
|
1015
|
+
if (this._storeOptionsAsProperties) {
|
|
1016
|
+
this[key] = value;
|
|
1017
|
+
} else {
|
|
1018
|
+
this._optionValues[key] = value;
|
|
1019
|
+
}
|
|
1020
|
+
this._optionValueSources[key] = source;
|
|
1021
|
+
return this;
|
|
1022
|
+
}
|
|
1023
|
+
getOptionValueSource(key) {
|
|
1024
|
+
return this._optionValueSources[key];
|
|
1025
|
+
}
|
|
1026
|
+
getOptionValueSourceWithGlobals(key) {
|
|
1027
|
+
let source;
|
|
1028
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1029
|
+
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
1030
|
+
source = cmd.getOptionValueSource(key);
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
return source;
|
|
1034
|
+
}
|
|
1035
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
1036
|
+
if (argv !== undefined && !Array.isArray(argv)) {
|
|
1037
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
1038
|
+
}
|
|
1039
|
+
parseOptions = parseOptions || {};
|
|
1040
|
+
if (argv === undefined && parseOptions.from === undefined) {
|
|
1041
|
+
if (process2.versions?.electron) {
|
|
1042
|
+
parseOptions.from = "electron";
|
|
1043
|
+
}
|
|
1044
|
+
const execArgv = process2.execArgv ?? [];
|
|
1045
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
1046
|
+
parseOptions.from = "eval";
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
if (argv === undefined) {
|
|
1050
|
+
argv = process2.argv;
|
|
1051
|
+
}
|
|
1052
|
+
this.rawArgs = argv.slice();
|
|
1053
|
+
let userArgs;
|
|
1054
|
+
switch (parseOptions.from) {
|
|
1055
|
+
case undefined:
|
|
1056
|
+
case "node":
|
|
1057
|
+
this._scriptPath = argv[1];
|
|
1058
|
+
userArgs = argv.slice(2);
|
|
1059
|
+
break;
|
|
1060
|
+
case "electron":
|
|
1061
|
+
if (process2.defaultApp) {
|
|
1062
|
+
this._scriptPath = argv[1];
|
|
1063
|
+
userArgs = argv.slice(2);
|
|
1064
|
+
} else {
|
|
1065
|
+
userArgs = argv.slice(1);
|
|
1066
|
+
}
|
|
1067
|
+
break;
|
|
1068
|
+
case "user":
|
|
1069
|
+
userArgs = argv.slice(0);
|
|
1070
|
+
break;
|
|
1071
|
+
case "eval":
|
|
1072
|
+
userArgs = argv.slice(1);
|
|
1073
|
+
break;
|
|
1074
|
+
default:
|
|
1075
|
+
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
1076
|
+
}
|
|
1077
|
+
if (!this._name && this._scriptPath)
|
|
1078
|
+
this.nameFromFilename(this._scriptPath);
|
|
1079
|
+
this._name = this._name || "program";
|
|
1080
|
+
return userArgs;
|
|
1081
|
+
}
|
|
1082
|
+
parse(argv, parseOptions) {
|
|
1083
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1084
|
+
this._parseCommand([], userArgs);
|
|
1085
|
+
return this;
|
|
1086
|
+
}
|
|
1087
|
+
async parseAsync(argv, parseOptions) {
|
|
1088
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1089
|
+
await this._parseCommand([], userArgs);
|
|
1090
|
+
return this;
|
|
1091
|
+
}
|
|
1092
|
+
_executeSubCommand(subcommand, args) {
|
|
1093
|
+
args = args.slice();
|
|
1094
|
+
let launchWithNode = false;
|
|
1095
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1096
|
+
function findFile(baseDir, baseName) {
|
|
1097
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
1098
|
+
if (fs.existsSync(localBin))
|
|
1099
|
+
return localBin;
|
|
1100
|
+
if (sourceExt.includes(path.extname(baseName)))
|
|
1101
|
+
return;
|
|
1102
|
+
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
1103
|
+
if (foundExt)
|
|
1104
|
+
return `${localBin}${foundExt}`;
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
this._checkForMissingMandatoryOptions();
|
|
1108
|
+
this._checkForConflictingOptions();
|
|
1109
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
1110
|
+
let executableDir = this._executableDir || "";
|
|
1111
|
+
if (this._scriptPath) {
|
|
1112
|
+
let resolvedScriptPath;
|
|
1113
|
+
try {
|
|
1114
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1115
|
+
} catch (err) {
|
|
1116
|
+
resolvedScriptPath = this._scriptPath;
|
|
1117
|
+
}
|
|
1118
|
+
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
1119
|
+
}
|
|
1120
|
+
if (executableDir) {
|
|
1121
|
+
let localFile = findFile(executableDir, executableFile);
|
|
1122
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1123
|
+
const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
1124
|
+
if (legacyName !== this._name) {
|
|
1125
|
+
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
executableFile = localFile || executableFile;
|
|
1129
|
+
}
|
|
1130
|
+
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
1131
|
+
let proc;
|
|
1132
|
+
if (process2.platform !== "win32") {
|
|
1133
|
+
if (launchWithNode) {
|
|
1134
|
+
args.unshift(executableFile);
|
|
1135
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1136
|
+
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
1137
|
+
} else {
|
|
1138
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1139
|
+
}
|
|
1140
|
+
} else {
|
|
1141
|
+
args.unshift(executableFile);
|
|
1142
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1143
|
+
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
1144
|
+
}
|
|
1145
|
+
if (!proc.killed) {
|
|
1146
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
1147
|
+
signals.forEach((signal) => {
|
|
1148
|
+
process2.on(signal, () => {
|
|
1149
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
1150
|
+
proc.kill(signal);
|
|
1151
|
+
}
|
|
1152
|
+
});
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
const exitCallback = this._exitCallback;
|
|
1156
|
+
proc.on("close", (code) => {
|
|
1157
|
+
code = code ?? 1;
|
|
1158
|
+
if (!exitCallback) {
|
|
1159
|
+
process2.exit(code);
|
|
1160
|
+
} else {
|
|
1161
|
+
exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
proc.on("error", (err) => {
|
|
1165
|
+
if (err.code === "ENOENT") {
|
|
1166
|
+
const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
1167
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
1168
|
+
- if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1169
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1170
|
+
- ${executableDirMessage}`;
|
|
1171
|
+
throw new Error(executableMissing);
|
|
1172
|
+
} else if (err.code === "EACCES") {
|
|
1173
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
1174
|
+
}
|
|
1175
|
+
if (!exitCallback) {
|
|
1176
|
+
process2.exit(1);
|
|
1177
|
+
} else {
|
|
1178
|
+
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
1179
|
+
wrappedError.nestedError = err;
|
|
1180
|
+
exitCallback(wrappedError);
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
this.runningCommand = proc;
|
|
1184
|
+
}
|
|
1185
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
1186
|
+
const subCommand = this._findCommand(commandName);
|
|
1187
|
+
if (!subCommand)
|
|
1188
|
+
this.help({ error: true });
|
|
1189
|
+
let promiseChain;
|
|
1190
|
+
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
|
|
1191
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1192
|
+
if (subCommand._executableHandler) {
|
|
1193
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
1194
|
+
} else {
|
|
1195
|
+
return subCommand._parseCommand(operands, unknown);
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
return promiseChain;
|
|
1199
|
+
}
|
|
1200
|
+
_dispatchHelpCommand(subcommandName) {
|
|
1201
|
+
if (!subcommandName) {
|
|
1202
|
+
this.help();
|
|
1203
|
+
}
|
|
1204
|
+
const subCommand = this._findCommand(subcommandName);
|
|
1205
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
1206
|
+
subCommand.help();
|
|
1207
|
+
}
|
|
1208
|
+
return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
|
|
1209
|
+
}
|
|
1210
|
+
_checkNumberOfArguments() {
|
|
1211
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
1212
|
+
if (arg.required && this.args[i] == null) {
|
|
1213
|
+
this.missingArgument(arg.name());
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
1220
|
+
this._excessArguments(this.args);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
_processArguments() {
|
|
1224
|
+
const myParseArg = (argument, value, previous) => {
|
|
1225
|
+
let parsedValue = value;
|
|
1226
|
+
if (value !== null && argument.parseArg) {
|
|
1227
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
1228
|
+
parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
|
|
1229
|
+
}
|
|
1230
|
+
return parsedValue;
|
|
1231
|
+
};
|
|
1232
|
+
this._checkNumberOfArguments();
|
|
1233
|
+
const processedArgs = [];
|
|
1234
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
1235
|
+
let value = declaredArg.defaultValue;
|
|
1236
|
+
if (declaredArg.variadic) {
|
|
1237
|
+
if (index < this.args.length) {
|
|
1238
|
+
value = this.args.slice(index);
|
|
1239
|
+
if (declaredArg.parseArg) {
|
|
1240
|
+
value = value.reduce((processed, v) => {
|
|
1241
|
+
return myParseArg(declaredArg, v, processed);
|
|
1242
|
+
}, declaredArg.defaultValue);
|
|
1243
|
+
}
|
|
1244
|
+
} else if (value === undefined) {
|
|
1245
|
+
value = [];
|
|
1246
|
+
}
|
|
1247
|
+
} else if (index < this.args.length) {
|
|
1248
|
+
value = this.args[index];
|
|
1249
|
+
if (declaredArg.parseArg) {
|
|
1250
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
processedArgs[index] = value;
|
|
1254
|
+
});
|
|
1255
|
+
this.processedArgs = processedArgs;
|
|
1256
|
+
}
|
|
1257
|
+
_chainOrCall(promise, fn) {
|
|
1258
|
+
if (promise && promise.then && typeof promise.then === "function") {
|
|
1259
|
+
return promise.then(() => fn());
|
|
1260
|
+
}
|
|
1261
|
+
return fn();
|
|
1262
|
+
}
|
|
1263
|
+
_chainOrCallHooks(promise, event) {
|
|
1264
|
+
let result = promise;
|
|
1265
|
+
const hooks = [];
|
|
1266
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
|
|
1267
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
1268
|
+
hooks.push({ hookedCommand, callback });
|
|
1269
|
+
});
|
|
1270
|
+
});
|
|
1271
|
+
if (event === "postAction") {
|
|
1272
|
+
hooks.reverse();
|
|
1273
|
+
}
|
|
1274
|
+
hooks.forEach((hookDetail) => {
|
|
1275
|
+
result = this._chainOrCall(result, () => {
|
|
1276
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
1277
|
+
});
|
|
1278
|
+
});
|
|
1279
|
+
return result;
|
|
1280
|
+
}
|
|
1281
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
1282
|
+
let result = promise;
|
|
1283
|
+
if (this._lifeCycleHooks[event] !== undefined) {
|
|
1284
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
1285
|
+
result = this._chainOrCall(result, () => {
|
|
1286
|
+
return hook(this, subCommand);
|
|
1287
|
+
});
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
return result;
|
|
1291
|
+
}
|
|
1292
|
+
_parseCommand(operands, unknown) {
|
|
1293
|
+
const parsed = this.parseOptions(unknown);
|
|
1294
|
+
this._parseOptionsEnv();
|
|
1295
|
+
this._parseOptionsImplied();
|
|
1296
|
+
operands = operands.concat(parsed.operands);
|
|
1297
|
+
unknown = parsed.unknown;
|
|
1298
|
+
this.args = operands.concat(unknown);
|
|
1299
|
+
if (operands && this._findCommand(operands[0])) {
|
|
1300
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
1301
|
+
}
|
|
1302
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
1303
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
1304
|
+
}
|
|
1305
|
+
if (this._defaultCommandName) {
|
|
1306
|
+
this._outputHelpIfRequested(unknown);
|
|
1307
|
+
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
1308
|
+
}
|
|
1309
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
1310
|
+
this.help({ error: true });
|
|
1311
|
+
}
|
|
1312
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
1313
|
+
this._checkForMissingMandatoryOptions();
|
|
1314
|
+
this._checkForConflictingOptions();
|
|
1315
|
+
const checkForUnknownOptions = () => {
|
|
1316
|
+
if (parsed.unknown.length > 0) {
|
|
1317
|
+
this.unknownOption(parsed.unknown[0]);
|
|
1318
|
+
}
|
|
1319
|
+
};
|
|
1320
|
+
const commandEvent = `command:${this.name()}`;
|
|
1321
|
+
if (this._actionHandler) {
|
|
1322
|
+
checkForUnknownOptions();
|
|
1323
|
+
this._processArguments();
|
|
1324
|
+
let promiseChain;
|
|
1325
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
1326
|
+
promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
|
|
1327
|
+
if (this.parent) {
|
|
1328
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1329
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
1333
|
+
return promiseChain;
|
|
1334
|
+
}
|
|
1335
|
+
if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
1336
|
+
checkForUnknownOptions();
|
|
1337
|
+
this._processArguments();
|
|
1338
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1339
|
+
} else if (operands.length) {
|
|
1340
|
+
if (this._findCommand("*")) {
|
|
1341
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
1342
|
+
}
|
|
1343
|
+
if (this.listenerCount("command:*")) {
|
|
1344
|
+
this.emit("command:*", operands, unknown);
|
|
1345
|
+
} else if (this.commands.length) {
|
|
1346
|
+
this.unknownCommand();
|
|
1347
|
+
} else {
|
|
1348
|
+
checkForUnknownOptions();
|
|
1349
|
+
this._processArguments();
|
|
1350
|
+
}
|
|
1351
|
+
} else if (this.commands.length) {
|
|
1352
|
+
checkForUnknownOptions();
|
|
1353
|
+
this.help({ error: true });
|
|
1354
|
+
} else {
|
|
1355
|
+
checkForUnknownOptions();
|
|
1356
|
+
this._processArguments();
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
_findCommand(name) {
|
|
1360
|
+
if (!name)
|
|
1361
|
+
return;
|
|
1362
|
+
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
1363
|
+
}
|
|
1364
|
+
_findOption(arg) {
|
|
1365
|
+
return this.options.find((option) => option.is(arg));
|
|
1366
|
+
}
|
|
1367
|
+
_checkForMissingMandatoryOptions() {
|
|
1368
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1369
|
+
cmd.options.forEach((anOption) => {
|
|
1370
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
|
|
1371
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
_checkForConflictingLocalOptions() {
|
|
1377
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
1378
|
+
const optionKey = option.attributeName();
|
|
1379
|
+
if (this.getOptionValue(optionKey) === undefined) {
|
|
1380
|
+
return false;
|
|
1381
|
+
}
|
|
1382
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
1383
|
+
});
|
|
1384
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
1385
|
+
optionsWithConflicting.forEach((option) => {
|
|
1386
|
+
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
1387
|
+
if (conflictingAndDefined) {
|
|
1388
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
1389
|
+
}
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
_checkForConflictingOptions() {
|
|
1393
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1394
|
+
cmd._checkForConflictingLocalOptions();
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
parseOptions(argv) {
|
|
1398
|
+
const operands = [];
|
|
1399
|
+
const unknown = [];
|
|
1400
|
+
let dest = operands;
|
|
1401
|
+
const args = argv.slice();
|
|
1402
|
+
function maybeOption(arg) {
|
|
1403
|
+
return arg.length > 1 && arg[0] === "-";
|
|
1404
|
+
}
|
|
1405
|
+
let activeVariadicOption = null;
|
|
1406
|
+
while (args.length) {
|
|
1407
|
+
const arg = args.shift();
|
|
1408
|
+
if (arg === "--") {
|
|
1409
|
+
if (dest === unknown)
|
|
1410
|
+
dest.push(arg);
|
|
1411
|
+
dest.push(...args);
|
|
1412
|
+
break;
|
|
1413
|
+
}
|
|
1414
|
+
if (activeVariadicOption && !maybeOption(arg)) {
|
|
1415
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1416
|
+
continue;
|
|
1417
|
+
}
|
|
1418
|
+
activeVariadicOption = null;
|
|
1419
|
+
if (maybeOption(arg)) {
|
|
1420
|
+
const option = this._findOption(arg);
|
|
1421
|
+
if (option) {
|
|
1422
|
+
if (option.required) {
|
|
1423
|
+
const value = args.shift();
|
|
1424
|
+
if (value === undefined)
|
|
1425
|
+
this.optionMissingArgument(option);
|
|
1426
|
+
this.emit(`option:${option.name()}`, value);
|
|
1427
|
+
} else if (option.optional) {
|
|
1428
|
+
let value = null;
|
|
1429
|
+
if (args.length > 0 && !maybeOption(args[0])) {
|
|
1430
|
+
value = args.shift();
|
|
1431
|
+
}
|
|
1432
|
+
this.emit(`option:${option.name()}`, value);
|
|
1433
|
+
} else {
|
|
1434
|
+
this.emit(`option:${option.name()}`);
|
|
1435
|
+
}
|
|
1436
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
1437
|
+
continue;
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1441
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
1442
|
+
if (option) {
|
|
1443
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
1444
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1445
|
+
} else {
|
|
1446
|
+
this.emit(`option:${option.name()}`);
|
|
1447
|
+
args.unshift(`-${arg.slice(2)}`);
|
|
1448
|
+
}
|
|
1449
|
+
continue;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
1453
|
+
const index = arg.indexOf("=");
|
|
1454
|
+
const option = this._findOption(arg.slice(0, index));
|
|
1455
|
+
if (option && (option.required || option.optional)) {
|
|
1456
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1457
|
+
continue;
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
if (maybeOption(arg)) {
|
|
1461
|
+
dest = unknown;
|
|
1462
|
+
}
|
|
1463
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1464
|
+
if (this._findCommand(arg)) {
|
|
1465
|
+
operands.push(arg);
|
|
1466
|
+
if (args.length > 0)
|
|
1467
|
+
unknown.push(...args);
|
|
1468
|
+
break;
|
|
1469
|
+
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
1470
|
+
operands.push(arg);
|
|
1471
|
+
if (args.length > 0)
|
|
1472
|
+
operands.push(...args);
|
|
1473
|
+
break;
|
|
1474
|
+
} else if (this._defaultCommandName) {
|
|
1475
|
+
unknown.push(arg);
|
|
1476
|
+
if (args.length > 0)
|
|
1477
|
+
unknown.push(...args);
|
|
1478
|
+
break;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
if (this._passThroughOptions) {
|
|
1482
|
+
dest.push(arg);
|
|
1483
|
+
if (args.length > 0)
|
|
1484
|
+
dest.push(...args);
|
|
1485
|
+
break;
|
|
1486
|
+
}
|
|
1487
|
+
dest.push(arg);
|
|
1488
|
+
}
|
|
1489
|
+
return { operands, unknown };
|
|
1490
|
+
}
|
|
1491
|
+
opts() {
|
|
1492
|
+
if (this._storeOptionsAsProperties) {
|
|
1493
|
+
const result = {};
|
|
1494
|
+
const len = this.options.length;
|
|
1495
|
+
for (let i = 0;i < len; i++) {
|
|
1496
|
+
const key = this.options[i].attributeName();
|
|
1497
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
1498
|
+
}
|
|
1499
|
+
return result;
|
|
1500
|
+
}
|
|
1501
|
+
return this._optionValues;
|
|
1502
|
+
}
|
|
1503
|
+
optsWithGlobals() {
|
|
1504
|
+
return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
1505
|
+
}
|
|
1506
|
+
error(message, errorOptions) {
|
|
1507
|
+
this._outputConfiguration.outputError(`${message}
|
|
1508
|
+
`, this._outputConfiguration.writeErr);
|
|
1509
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
1510
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
1511
|
+
`);
|
|
1512
|
+
} else if (this._showHelpAfterError) {
|
|
1513
|
+
this._outputConfiguration.writeErr(`
|
|
1514
|
+
`);
|
|
1515
|
+
this.outputHelp({ error: true });
|
|
1516
|
+
}
|
|
1517
|
+
const config = errorOptions || {};
|
|
1518
|
+
const exitCode = config.exitCode || 1;
|
|
1519
|
+
const code = config.code || "commander.error";
|
|
1520
|
+
this._exit(exitCode, code, message);
|
|
1521
|
+
}
|
|
1522
|
+
_parseOptionsEnv() {
|
|
1523
|
+
this.options.forEach((option) => {
|
|
1524
|
+
if (option.envVar && option.envVar in process2.env) {
|
|
1525
|
+
const optionKey = option.attributeName();
|
|
1526
|
+
if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
1527
|
+
if (option.required || option.optional) {
|
|
1528
|
+
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
1529
|
+
} else {
|
|
1530
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
_parseOptionsImplied() {
|
|
1537
|
+
const dualHelper = new DualOptions(this.options);
|
|
1538
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
1539
|
+
return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
1540
|
+
};
|
|
1541
|
+
this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
1542
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
1543
|
+
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
1544
|
+
});
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
missingArgument(name) {
|
|
1548
|
+
const message = `error: missing required argument '${name}'`;
|
|
1549
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
1550
|
+
}
|
|
1551
|
+
optionMissingArgument(option) {
|
|
1552
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
1553
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
1554
|
+
}
|
|
1555
|
+
missingMandatoryOptionValue(option) {
|
|
1556
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
1557
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
1558
|
+
}
|
|
1559
|
+
_conflictingOption(option, conflictingOption) {
|
|
1560
|
+
const findBestOptionFromValue = (option2) => {
|
|
1561
|
+
const optionKey = option2.attributeName();
|
|
1562
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
1563
|
+
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
1564
|
+
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
1565
|
+
if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
|
|
1566
|
+
return negativeOption;
|
|
1567
|
+
}
|
|
1568
|
+
return positiveOption || option2;
|
|
1569
|
+
};
|
|
1570
|
+
const getErrorMessage = (option2) => {
|
|
1571
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
1572
|
+
const optionKey = bestOption.attributeName();
|
|
1573
|
+
const source = this.getOptionValueSource(optionKey);
|
|
1574
|
+
if (source === "env") {
|
|
1575
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
1576
|
+
}
|
|
1577
|
+
return `option '${bestOption.flags}'`;
|
|
1578
|
+
};
|
|
1579
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
1580
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
1581
|
+
}
|
|
1582
|
+
unknownOption(flag) {
|
|
1583
|
+
if (this._allowUnknownOption)
|
|
1584
|
+
return;
|
|
1585
|
+
let suggestion = "";
|
|
1586
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
1587
|
+
let candidateFlags = [];
|
|
1588
|
+
let command = this;
|
|
1589
|
+
do {
|
|
1590
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
1591
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
1592
|
+
command = command.parent;
|
|
1593
|
+
} while (command && !command._enablePositionalOptions);
|
|
1594
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
1595
|
+
}
|
|
1596
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
1597
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
1598
|
+
}
|
|
1599
|
+
_excessArguments(receivedArgs) {
|
|
1600
|
+
if (this._allowExcessArguments)
|
|
1601
|
+
return;
|
|
1602
|
+
const expected = this.registeredArguments.length;
|
|
1603
|
+
const s = expected === 1 ? "" : "s";
|
|
1604
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
1605
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
1606
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
1607
|
+
}
|
|
1608
|
+
unknownCommand() {
|
|
1609
|
+
const unknownName = this.args[0];
|
|
1610
|
+
let suggestion = "";
|
|
1611
|
+
if (this._showSuggestionAfterError) {
|
|
1612
|
+
const candidateNames = [];
|
|
1613
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
1614
|
+
candidateNames.push(command.name());
|
|
1615
|
+
if (command.alias())
|
|
1616
|
+
candidateNames.push(command.alias());
|
|
1617
|
+
});
|
|
1618
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
1619
|
+
}
|
|
1620
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
1621
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
1622
|
+
}
|
|
1623
|
+
version(str, flags, description) {
|
|
1624
|
+
if (str === undefined)
|
|
1625
|
+
return this._version;
|
|
1626
|
+
this._version = str;
|
|
1627
|
+
flags = flags || "-V, --version";
|
|
1628
|
+
description = description || "output the version number";
|
|
1629
|
+
const versionOption = this.createOption(flags, description);
|
|
1630
|
+
this._versionOptionName = versionOption.attributeName();
|
|
1631
|
+
this._registerOption(versionOption);
|
|
1632
|
+
this.on("option:" + versionOption.name(), () => {
|
|
1633
|
+
this._outputConfiguration.writeOut(`${str}
|
|
1634
|
+
`);
|
|
1635
|
+
this._exit(0, "commander.version", str);
|
|
1636
|
+
});
|
|
1637
|
+
return this;
|
|
1638
|
+
}
|
|
1639
|
+
description(str, argsDescription) {
|
|
1640
|
+
if (str === undefined && argsDescription === undefined)
|
|
1641
|
+
return this._description;
|
|
1642
|
+
this._description = str;
|
|
1643
|
+
if (argsDescription) {
|
|
1644
|
+
this._argsDescription = argsDescription;
|
|
1645
|
+
}
|
|
1646
|
+
return this;
|
|
1647
|
+
}
|
|
1648
|
+
summary(str) {
|
|
1649
|
+
if (str === undefined)
|
|
1650
|
+
return this._summary;
|
|
1651
|
+
this._summary = str;
|
|
1652
|
+
return this;
|
|
1653
|
+
}
|
|
1654
|
+
alias(alias) {
|
|
1655
|
+
if (alias === undefined)
|
|
1656
|
+
return this._aliases[0];
|
|
1657
|
+
let command = this;
|
|
1658
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
1659
|
+
command = this.commands[this.commands.length - 1];
|
|
1660
|
+
}
|
|
1661
|
+
if (alias === command._name)
|
|
1662
|
+
throw new Error("Command alias can't be the same as its name");
|
|
1663
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
1664
|
+
if (matchingCommand) {
|
|
1665
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
1666
|
+
throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
|
|
1667
|
+
}
|
|
1668
|
+
command._aliases.push(alias);
|
|
1669
|
+
return this;
|
|
1670
|
+
}
|
|
1671
|
+
aliases(aliases) {
|
|
1672
|
+
if (aliases === undefined)
|
|
1673
|
+
return this._aliases;
|
|
1674
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
1675
|
+
return this;
|
|
1676
|
+
}
|
|
1677
|
+
usage(str) {
|
|
1678
|
+
if (str === undefined) {
|
|
1679
|
+
if (this._usage)
|
|
1680
|
+
return this._usage;
|
|
1681
|
+
const args = this.registeredArguments.map((arg) => {
|
|
1682
|
+
return humanReadableArgName(arg);
|
|
1683
|
+
});
|
|
1684
|
+
return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
|
|
1685
|
+
}
|
|
1686
|
+
this._usage = str;
|
|
1687
|
+
return this;
|
|
1688
|
+
}
|
|
1689
|
+
name(str) {
|
|
1690
|
+
if (str === undefined)
|
|
1691
|
+
return this._name;
|
|
1692
|
+
this._name = str;
|
|
1693
|
+
return this;
|
|
1694
|
+
}
|
|
1695
|
+
nameFromFilename(filename) {
|
|
1696
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
1697
|
+
return this;
|
|
1698
|
+
}
|
|
1699
|
+
executableDir(path2) {
|
|
1700
|
+
if (path2 === undefined)
|
|
1701
|
+
return this._executableDir;
|
|
1702
|
+
this._executableDir = path2;
|
|
1703
|
+
return this;
|
|
1704
|
+
}
|
|
1705
|
+
helpInformation(contextOptions) {
|
|
1706
|
+
const helper = this.createHelp();
|
|
1707
|
+
if (helper.helpWidth === undefined) {
|
|
1708
|
+
helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
|
|
1709
|
+
}
|
|
1710
|
+
return helper.formatHelp(this, helper);
|
|
1711
|
+
}
|
|
1712
|
+
_getHelpContext(contextOptions) {
|
|
1713
|
+
contextOptions = contextOptions || {};
|
|
1714
|
+
const context = { error: !!contextOptions.error };
|
|
1715
|
+
let write;
|
|
1716
|
+
if (context.error) {
|
|
1717
|
+
write = (arg) => this._outputConfiguration.writeErr(arg);
|
|
1718
|
+
} else {
|
|
1719
|
+
write = (arg) => this._outputConfiguration.writeOut(arg);
|
|
1720
|
+
}
|
|
1721
|
+
context.write = contextOptions.write || write;
|
|
1722
|
+
context.command = this;
|
|
1723
|
+
return context;
|
|
1724
|
+
}
|
|
1725
|
+
outputHelp(contextOptions) {
|
|
1726
|
+
let deprecatedCallback;
|
|
1727
|
+
if (typeof contextOptions === "function") {
|
|
1728
|
+
deprecatedCallback = contextOptions;
|
|
1729
|
+
contextOptions = undefined;
|
|
1730
|
+
}
|
|
1731
|
+
const context = this._getHelpContext(contextOptions);
|
|
1732
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", context));
|
|
1733
|
+
this.emit("beforeHelp", context);
|
|
1734
|
+
let helpInformation = this.helpInformation(context);
|
|
1735
|
+
if (deprecatedCallback) {
|
|
1736
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
1737
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
1738
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
context.write(helpInformation);
|
|
1742
|
+
if (this._getHelpOption()?.long) {
|
|
1743
|
+
this.emit(this._getHelpOption().long);
|
|
1744
|
+
}
|
|
1745
|
+
this.emit("afterHelp", context);
|
|
1746
|
+
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", context));
|
|
1747
|
+
}
|
|
1748
|
+
helpOption(flags, description) {
|
|
1749
|
+
if (typeof flags === "boolean") {
|
|
1750
|
+
if (flags) {
|
|
1751
|
+
this._helpOption = this._helpOption ?? undefined;
|
|
1752
|
+
} else {
|
|
1753
|
+
this._helpOption = null;
|
|
1754
|
+
}
|
|
1755
|
+
return this;
|
|
1756
|
+
}
|
|
1757
|
+
flags = flags ?? "-h, --help";
|
|
1758
|
+
description = description ?? "display help for command";
|
|
1759
|
+
this._helpOption = this.createOption(flags, description);
|
|
1760
|
+
return this;
|
|
1761
|
+
}
|
|
1762
|
+
_getHelpOption() {
|
|
1763
|
+
if (this._helpOption === undefined) {
|
|
1764
|
+
this.helpOption(undefined, undefined);
|
|
1765
|
+
}
|
|
1766
|
+
return this._helpOption;
|
|
1767
|
+
}
|
|
1768
|
+
addHelpOption(option) {
|
|
1769
|
+
this._helpOption = option;
|
|
1770
|
+
return this;
|
|
1771
|
+
}
|
|
1772
|
+
help(contextOptions) {
|
|
1773
|
+
this.outputHelp(contextOptions);
|
|
1774
|
+
let exitCode = process2.exitCode || 0;
|
|
1775
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
1776
|
+
exitCode = 1;
|
|
1777
|
+
}
|
|
1778
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
1779
|
+
}
|
|
1780
|
+
addHelpText(position, text) {
|
|
1781
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
1782
|
+
if (!allowedValues.includes(position)) {
|
|
1783
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
1784
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1785
|
+
}
|
|
1786
|
+
const helpEvent = `${position}Help`;
|
|
1787
|
+
this.on(helpEvent, (context) => {
|
|
1788
|
+
let helpStr;
|
|
1789
|
+
if (typeof text === "function") {
|
|
1790
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
1791
|
+
} else {
|
|
1792
|
+
helpStr = text;
|
|
1793
|
+
}
|
|
1794
|
+
if (helpStr) {
|
|
1795
|
+
context.write(`${helpStr}
|
|
1796
|
+
`);
|
|
1797
|
+
}
|
|
1798
|
+
});
|
|
1799
|
+
return this;
|
|
1800
|
+
}
|
|
1801
|
+
_outputHelpIfRequested(args) {
|
|
1802
|
+
const helpOption = this._getHelpOption();
|
|
1803
|
+
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
1804
|
+
if (helpRequested) {
|
|
1805
|
+
this.outputHelp();
|
|
1806
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
function incrementNodeInspectorPort(args) {
|
|
1811
|
+
return args.map((arg) => {
|
|
1812
|
+
if (!arg.startsWith("--inspect")) {
|
|
1813
|
+
return arg;
|
|
1814
|
+
}
|
|
1815
|
+
let debugOption;
|
|
1816
|
+
let debugHost = "127.0.0.1";
|
|
1817
|
+
let debugPort = "9229";
|
|
1818
|
+
let match;
|
|
1819
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
1820
|
+
debugOption = match[1];
|
|
1821
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
1822
|
+
debugOption = match[1];
|
|
1823
|
+
if (/^\d+$/.test(match[3])) {
|
|
1824
|
+
debugPort = match[3];
|
|
1825
|
+
} else {
|
|
1826
|
+
debugHost = match[3];
|
|
1827
|
+
}
|
|
1828
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
1829
|
+
debugOption = match[1];
|
|
1830
|
+
debugHost = match[3];
|
|
1831
|
+
debugPort = match[4];
|
|
1832
|
+
}
|
|
1833
|
+
if (debugOption && debugPort !== "0") {
|
|
1834
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
1835
|
+
}
|
|
1836
|
+
return arg;
|
|
1837
|
+
});
|
|
1838
|
+
}
|
|
1839
|
+
exports.Command = Command;
|
|
1840
|
+
});
|
|
1841
|
+
|
|
1842
|
+
// node_modules/commander/index.js
|
|
1843
|
+
var require_commander = __commonJS((exports) => {
|
|
1844
|
+
var { Argument } = require_argument();
|
|
1845
|
+
var { Command } = require_command();
|
|
1846
|
+
var { CommanderError, InvalidArgumentError } = require_error();
|
|
1847
|
+
var { Help } = require_help();
|
|
1848
|
+
var { Option } = require_option();
|
|
1849
|
+
exports.program = new Command;
|
|
1850
|
+
exports.createCommand = (name) => new Command(name);
|
|
1851
|
+
exports.createOption = (flags, description) => new Option(flags, description);
|
|
1852
|
+
exports.createArgument = (name, description) => new Argument(name, description);
|
|
1853
|
+
exports.Command = Command;
|
|
1854
|
+
exports.Option = Option;
|
|
1855
|
+
exports.Argument = Argument;
|
|
1856
|
+
exports.Help = Help;
|
|
1857
|
+
exports.CommanderError = CommanderError;
|
|
1858
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
1859
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
1860
|
+
});
|
|
1861
|
+
|
|
1862
|
+
// node_modules/commander/esm.mjs
|
|
1863
|
+
var import__ = __toESM(require_commander(), 1);
|
|
1864
|
+
var {
|
|
1865
|
+
program,
|
|
1866
|
+
createCommand,
|
|
1867
|
+
createArgument,
|
|
1868
|
+
createOption,
|
|
1869
|
+
CommanderError,
|
|
1870
|
+
InvalidArgumentError,
|
|
1871
|
+
InvalidOptionArgumentError,
|
|
1872
|
+
Command,
|
|
1873
|
+
Argument,
|
|
1874
|
+
Option,
|
|
1875
|
+
Help
|
|
1876
|
+
} = import__.default;
|
|
1877
|
+
|
|
1878
|
+
// src/commands/create.ts
|
|
1879
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readdirSync, renameSync, rmSync, writeFileSync as writeFileSync3, readFileSync as readFileSync2 } from "fs";
|
|
1880
|
+
import { resolve as resolve2, join as join2 } from "path";
|
|
1881
|
+
|
|
1882
|
+
// src/utils.ts
|
|
1883
|
+
import { spawn, spawnSync } from "child_process";
|
|
1884
|
+
import { existsSync as existsSync2, writeFileSync as writeFileSync2, unlinkSync } from "fs";
|
|
1885
|
+
import { basename, resolve } from "path";
|
|
1886
|
+
|
|
1887
|
+
// src/config.ts
|
|
1888
|
+
import { homedir } from "os";
|
|
1889
|
+
import { join } from "path";
|
|
1890
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
1891
|
+
var ZEBU_HOME = join(homedir(), ".zdev");
|
|
1892
|
+
var CONFIG_PATH = join(ZEBU_HOME, "config.json");
|
|
1893
|
+
var WORKTREES_DIR = join(ZEBU_HOME, "worktrees");
|
|
1894
|
+
var SEEDS_DIR = join(ZEBU_HOME, "seeds");
|
|
1895
|
+
var DEFAULT_CONFIG = {
|
|
1896
|
+
nextFrontendPort: 5173,
|
|
1897
|
+
nextConvexPort: 3210,
|
|
1898
|
+
copyPatterns: [
|
|
1899
|
+
".env.local",
|
|
1900
|
+
".env.development",
|
|
1901
|
+
".env.development.local"
|
|
1902
|
+
],
|
|
1903
|
+
dockerHostIp: "172.17.0.1",
|
|
1904
|
+
devDomain: "",
|
|
1905
|
+
traefikConfigDir: "/infra/traefik/dynamic",
|
|
1906
|
+
allocations: {}
|
|
1907
|
+
};
|
|
1908
|
+
function ensurezdevDirs() {
|
|
1909
|
+
if (!existsSync(ZEBU_HOME)) {
|
|
1910
|
+
mkdirSync(ZEBU_HOME, { recursive: true });
|
|
1911
|
+
}
|
|
1912
|
+
if (!existsSync(WORKTREES_DIR)) {
|
|
1913
|
+
mkdirSync(WORKTREES_DIR, { recursive: true });
|
|
1914
|
+
}
|
|
1915
|
+
if (!existsSync(SEEDS_DIR)) {
|
|
1916
|
+
mkdirSync(SEEDS_DIR, { recursive: true });
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
function loadConfig() {
|
|
1920
|
+
ensurezdevDirs();
|
|
1921
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
1922
|
+
saveConfig(DEFAULT_CONFIG);
|
|
1923
|
+
return DEFAULT_CONFIG;
|
|
1924
|
+
}
|
|
1925
|
+
try {
|
|
1926
|
+
const data = readFileSync(CONFIG_PATH, "utf-8");
|
|
1927
|
+
return { ...DEFAULT_CONFIG, ...JSON.parse(data) };
|
|
1928
|
+
} catch {
|
|
1929
|
+
return DEFAULT_CONFIG;
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
function saveConfig(config) {
|
|
1933
|
+
ensurezdevDirs();
|
|
1934
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
1935
|
+
}
|
|
1936
|
+
function allocatePorts(config, includeConvex = true) {
|
|
1937
|
+
const frontend = config.nextFrontendPort;
|
|
1938
|
+
config.nextFrontendPort = frontend + 1;
|
|
1939
|
+
let convex = 0;
|
|
1940
|
+
if (includeConvex) {
|
|
1941
|
+
convex = config.nextConvexPort;
|
|
1942
|
+
config.nextConvexPort = convex + 1;
|
|
1943
|
+
}
|
|
1944
|
+
return { frontend, convex };
|
|
1945
|
+
}
|
|
1946
|
+
function getWorktreePath(name) {
|
|
1947
|
+
return join(WORKTREES_DIR, name);
|
|
1948
|
+
}
|
|
1949
|
+
function getSeedPath(projectName) {
|
|
1950
|
+
return join(SEEDS_DIR, `${projectName}.zip`);
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
// src/utils.ts
|
|
1954
|
+
function run(command, args, options) {
|
|
1955
|
+
const result = spawnSync(command, args, {
|
|
1956
|
+
encoding: "utf-8",
|
|
1957
|
+
...options
|
|
1958
|
+
});
|
|
1959
|
+
return {
|
|
1960
|
+
success: result.status === 0,
|
|
1961
|
+
stdout: result.stdout || "",
|
|
1962
|
+
stderr: result.stderr || "",
|
|
1963
|
+
code: result.status
|
|
1964
|
+
};
|
|
1965
|
+
}
|
|
1966
|
+
function runBackground(command, args, options) {
|
|
1967
|
+
const child = spawn(command, args, {
|
|
1968
|
+
detached: true,
|
|
1969
|
+
stdio: "ignore",
|
|
1970
|
+
...options
|
|
1971
|
+
});
|
|
1972
|
+
child.unref();
|
|
1973
|
+
return child.pid;
|
|
1974
|
+
}
|
|
1975
|
+
function isGitRepo(path) {
|
|
1976
|
+
return existsSync2(resolve(path, ".git"));
|
|
1977
|
+
}
|
|
1978
|
+
function getRepoName(path) {
|
|
1979
|
+
const result = run("git", ["remote", "get-url", "origin"], { cwd: path });
|
|
1980
|
+
if (result.success) {
|
|
1981
|
+
const url = result.stdout.trim();
|
|
1982
|
+
const match = url.match(/\/([^\/]+?)(\.git)?$/);
|
|
1983
|
+
if (match)
|
|
1984
|
+
return match[1];
|
|
1985
|
+
}
|
|
1986
|
+
return basename(resolve(path));
|
|
1987
|
+
}
|
|
1988
|
+
function gitFetch(repoPath) {
|
|
1989
|
+
const result = run("git", ["fetch", "origin"], { cwd: repoPath });
|
|
1990
|
+
return result.success;
|
|
1991
|
+
}
|
|
1992
|
+
function createWorktree(repoPath, worktreePath, branch, baseBranch = "origin/main") {
|
|
1993
|
+
const result = run("git", ["worktree", "add", worktreePath, "-b", branch, baseBranch], { cwd: repoPath });
|
|
1994
|
+
if (!result.success) {
|
|
1995
|
+
return { success: false, error: result.stderr };
|
|
1996
|
+
}
|
|
1997
|
+
return { success: true };
|
|
1998
|
+
}
|
|
1999
|
+
function removeWorktree(repoPath, worktreePath) {
|
|
2000
|
+
const result = run("git", ["worktree", "remove", worktreePath, "--force"], {
|
|
2001
|
+
cwd: repoPath
|
|
2002
|
+
});
|
|
2003
|
+
if (!result.success) {
|
|
2004
|
+
return { success: false, error: result.stderr };
|
|
2005
|
+
}
|
|
2006
|
+
run("git", ["worktree", "prune"], { cwd: repoPath });
|
|
2007
|
+
return { success: true };
|
|
2008
|
+
}
|
|
2009
|
+
function traefikAddRoute(name, port) {
|
|
2010
|
+
const config = loadConfig();
|
|
2011
|
+
const configPath = `${config.traefikConfigDir}/${name}.yml`;
|
|
2012
|
+
const subdomain = name;
|
|
2013
|
+
const traefikConfig = `# zdev auto-generated config for ${name}
|
|
2014
|
+
http:
|
|
2015
|
+
routers:
|
|
2016
|
+
${name}:
|
|
2017
|
+
rule: "Host(\`${subdomain}.${config.devDomain}\`)"
|
|
2018
|
+
entrypoints:
|
|
2019
|
+
- websecure
|
|
2020
|
+
service: ${name}
|
|
2021
|
+
tls:
|
|
2022
|
+
certResolver: myresolver
|
|
2023
|
+
|
|
2024
|
+
services:
|
|
2025
|
+
${name}:
|
|
2026
|
+
loadBalancer:
|
|
2027
|
+
servers:
|
|
2028
|
+
- url: "http://${config.dockerHostIp}:${port}"
|
|
2029
|
+
`;
|
|
2030
|
+
try {
|
|
2031
|
+
writeFileSync2(configPath, traefikConfig);
|
|
2032
|
+
return true;
|
|
2033
|
+
} catch {
|
|
2034
|
+
return false;
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
function traefikRemoveRoute(name) {
|
|
2038
|
+
const zdevConfig = loadConfig();
|
|
2039
|
+
const configPath = `${zdevConfig.traefikConfigDir}/${name}.yml`;
|
|
2040
|
+
try {
|
|
2041
|
+
if (existsSync2(configPath)) {
|
|
2042
|
+
unlinkSync(configPath);
|
|
2043
|
+
}
|
|
2044
|
+
return true;
|
|
2045
|
+
} catch {
|
|
2046
|
+
return false;
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
function getTraefikStatus() {
|
|
2050
|
+
const config = loadConfig();
|
|
2051
|
+
if (!config.devDomain) {
|
|
2052
|
+
return { running: false, devDomain: undefined };
|
|
2053
|
+
}
|
|
2054
|
+
const configDirExists = existsSync2(config.traefikConfigDir);
|
|
2055
|
+
return {
|
|
2056
|
+
running: configDirExists,
|
|
2057
|
+
baseUrl: configDirExists ? `https://*.${config.devDomain}` : undefined,
|
|
2058
|
+
devDomain: config.devDomain
|
|
2059
|
+
};
|
|
2060
|
+
}
|
|
2061
|
+
function killProcess(pid) {
|
|
2062
|
+
try {
|
|
2063
|
+
process.kill(pid, "SIGTERM");
|
|
2064
|
+
return true;
|
|
2065
|
+
} catch {
|
|
2066
|
+
return false;
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
function isProcessRunning(pid) {
|
|
2070
|
+
try {
|
|
2071
|
+
process.kill(pid, 0);
|
|
2072
|
+
return true;
|
|
2073
|
+
} catch {
|
|
2074
|
+
return false;
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
// src/commands/create.ts
|
|
2079
|
+
var ZEBU_INDEX_PAGE = `import { createFileRoute } from '@tanstack/react-router'
|
|
2080
|
+
|
|
2081
|
+
export const Route = createFileRoute('/')({
|
|
2082
|
+
component: Home,
|
|
2083
|
+
})
|
|
2084
|
+
|
|
2085
|
+
function Home() {
|
|
2086
|
+
return (
|
|
2087
|
+
<div
|
|
2088
|
+
style={{
|
|
2089
|
+
minHeight: '100vh',
|
|
2090
|
+
background: 'linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%)',
|
|
2091
|
+
display: 'flex',
|
|
2092
|
+
flexDirection: 'column',
|
|
2093
|
+
alignItems: 'center',
|
|
2094
|
+
justifyContent: 'center',
|
|
2095
|
+
fontFamily: 'system-ui, -apple-system, sans-serif',
|
|
2096
|
+
color: '#e8e8e8',
|
|
2097
|
+
padding: '2rem',
|
|
2098
|
+
position: 'relative',
|
|
2099
|
+
overflow: 'hidden',
|
|
2100
|
+
}}
|
|
2101
|
+
>
|
|
2102
|
+
{/* Glowing orbs */}
|
|
2103
|
+
<div style={{
|
|
2104
|
+
position: 'absolute',
|
|
2105
|
+
top: '10%',
|
|
2106
|
+
left: '15%',
|
|
2107
|
+
width: '300px',
|
|
2108
|
+
height: '300px',
|
|
2109
|
+
background: 'radial-gradient(circle, rgba(99, 102, 241, 0.3) 0%, transparent 70%)',
|
|
2110
|
+
borderRadius: '50%',
|
|
2111
|
+
filter: 'blur(40px)',
|
|
2112
|
+
}} />
|
|
2113
|
+
<div style={{
|
|
2114
|
+
position: 'absolute',
|
|
2115
|
+
bottom: '20%',
|
|
2116
|
+
right: '10%',
|
|
2117
|
+
width: '400px',
|
|
2118
|
+
height: '400px',
|
|
2119
|
+
background: 'radial-gradient(circle, rgba(16, 185, 129, 0.25) 0%, transparent 70%)',
|
|
2120
|
+
borderRadius: '50%',
|
|
2121
|
+
filter: 'blur(50px)',
|
|
2122
|
+
}} />
|
|
2123
|
+
|
|
2124
|
+
<div style={{ fontSize: '7rem', marginBottom: '1.5rem', zIndex: 1 }}>
|
|
2125
|
+
\uD83D\uDC02
|
|
2126
|
+
</div>
|
|
2127
|
+
<h1
|
|
2128
|
+
style={{
|
|
2129
|
+
fontSize: '3.5rem',
|
|
2130
|
+
fontWeight: 800,
|
|
2131
|
+
margin: 0,
|
|
2132
|
+
background: 'linear-gradient(90deg, #818cf8, #34d399)',
|
|
2133
|
+
WebkitBackgroundClip: 'text',
|
|
2134
|
+
WebkitTextFillColor: 'transparent',
|
|
2135
|
+
backgroundClip: 'text',
|
|
2136
|
+
zIndex: 1,
|
|
2137
|
+
}}
|
|
2138
|
+
>
|
|
2139
|
+
Ready to build
|
|
2140
|
+
</h1>
|
|
2141
|
+
<p
|
|
2142
|
+
style={{
|
|
2143
|
+
fontSize: '1.25rem',
|
|
2144
|
+
color: 'rgba(255,255,255,0.6)',
|
|
2145
|
+
marginTop: '1.5rem',
|
|
2146
|
+
textAlign: 'center',
|
|
2147
|
+
zIndex: 1,
|
|
2148
|
+
maxWidth: '500px',
|
|
2149
|
+
lineHeight: 1.6,
|
|
2150
|
+
}}
|
|
2151
|
+
>
|
|
2152
|
+
Your TanStack Start app is ready.
|
|
2153
|
+
<br />
|
|
2154
|
+
Edit <code style={{
|
|
2155
|
+
color: '#818cf8',
|
|
2156
|
+
background: 'rgba(129, 140, 248, 0.1)',
|
|
2157
|
+
padding: '0.2rem 0.6rem',
|
|
2158
|
+
borderRadius: '6px',
|
|
2159
|
+
border: '1px solid rgba(129, 140, 248, 0.2)',
|
|
2160
|
+
}}>src/routes/index.tsx</code> to get started.
|
|
2161
|
+
</p>
|
|
2162
|
+
</div>
|
|
2163
|
+
)
|
|
2164
|
+
}
|
|
2165
|
+
`;
|
|
2166
|
+
var CONVEX_PROVIDER = `import { ConvexProvider, ConvexReactClient } from "convex/react";
|
|
2167
|
+
import { ReactNode } from "react";
|
|
2168
|
+
|
|
2169
|
+
const convex = new ConvexReactClient(import.meta.env.VITE_CONVEX_URL as string);
|
|
2170
|
+
|
|
2171
|
+
export function ConvexClientProvider({ children }: { children: ReactNode }) {
|
|
2172
|
+
return <ConvexProvider client={convex}>{children}</ConvexProvider>;
|
|
2173
|
+
}
|
|
2174
|
+
`;
|
|
2175
|
+
var ROUTER = `import { createRouter } from '@tanstack/react-router'
|
|
2176
|
+
import { routeTree } from './routeTree.gen'
|
|
2177
|
+
|
|
2178
|
+
export function getRouter() {
|
|
2179
|
+
const router = createRouter({
|
|
2180
|
+
routeTree,
|
|
2181
|
+
defaultPreload: 'intent',
|
|
2182
|
+
scrollRestoration: true,
|
|
2183
|
+
})
|
|
2184
|
+
return router
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
declare module '@tanstack/react-router' {
|
|
2188
|
+
interface Register {
|
|
2189
|
+
router: ReturnType<typeof getRouter>
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
`;
|
|
2193
|
+
var ROOT_ROUTE = `/// <reference types="vite/client" />
|
|
2194
|
+
import {
|
|
2195
|
+
HeadContent,
|
|
2196
|
+
Outlet,
|
|
2197
|
+
Scripts,
|
|
2198
|
+
createRootRoute,
|
|
2199
|
+
} from '@tanstack/react-router'
|
|
2200
|
+
import * as React from 'react'
|
|
2201
|
+
import { Agentation } from 'agentation'
|
|
2202
|
+
|
|
2203
|
+
export const Route = createRootRoute({
|
|
2204
|
+
head: () => ({
|
|
2205
|
+
meta: [
|
|
2206
|
+
{ charSet: 'utf-8' },
|
|
2207
|
+
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
|
2208
|
+
],
|
|
2209
|
+
}),
|
|
2210
|
+
component: RootDocument,
|
|
2211
|
+
})
|
|
2212
|
+
|
|
2213
|
+
function RootDocument() {
|
|
2214
|
+
return (
|
|
2215
|
+
<html>
|
|
2216
|
+
<head>
|
|
2217
|
+
<HeadContent />
|
|
2218
|
+
</head>
|
|
2219
|
+
<body>
|
|
2220
|
+
<Outlet />
|
|
2221
|
+
{import.meta.env.DEV && <Agentation />}
|
|
2222
|
+
<Scripts />
|
|
2223
|
+
</body>
|
|
2224
|
+
</html>
|
|
2225
|
+
)
|
|
2226
|
+
}
|
|
2227
|
+
`;
|
|
2228
|
+
var SETUP_SCRIPT = `#!/bin/bash
|
|
2229
|
+
# .zdev/setup.sh - Runs after worktree creation
|
|
2230
|
+
# Edit this to customize your setup (change package manager, add commands, etc.)
|
|
2231
|
+
|
|
2232
|
+
set -e
|
|
2233
|
+
|
|
2234
|
+
# Install dependencies
|
|
2235
|
+
bun install
|
|
2236
|
+
|
|
2237
|
+
# Add any other setup commands below:
|
|
2238
|
+
# bunx prisma generate
|
|
2239
|
+
# cp ../.env.local .
|
|
2240
|
+
`;
|
|
2241
|
+
async function create(projectName, options = {}) {
|
|
2242
|
+
const targetPath = resolve2(projectName);
|
|
2243
|
+
if (existsSync3(targetPath)) {
|
|
2244
|
+
console.error(`❌ Directory already exists: ${targetPath}`);
|
|
2245
|
+
process.exit(1);
|
|
2246
|
+
}
|
|
2247
|
+
console.log(`\uD83D\uDC02 Creating new project: ${projectName}`);
|
|
2248
|
+
console.log(` Convex: ${options.convex ? "yes" : "no"}`);
|
|
2249
|
+
console.log(` Structure: ${options.flat ? "flat" : "monorepo"}`);
|
|
2250
|
+
console.log(`
|
|
2251
|
+
\uD83D\uDCE5 Cloning TanStack Start template...`);
|
|
2252
|
+
const cloneResult = run("npx", [
|
|
2253
|
+
"-y",
|
|
2254
|
+
"gitpick",
|
|
2255
|
+
"TanStack/router/tree/main/examples/react/start-basic",
|
|
2256
|
+
projectName
|
|
2257
|
+
]);
|
|
2258
|
+
if (!cloneResult.success) {
|
|
2259
|
+
console.error(`❌ Failed to clone template: ${cloneResult.stderr}`);
|
|
2260
|
+
process.exit(1);
|
|
2261
|
+
}
|
|
2262
|
+
console.log(` Template cloned`);
|
|
2263
|
+
let webPath;
|
|
2264
|
+
if (options.flat) {
|
|
2265
|
+
webPath = targetPath;
|
|
2266
|
+
} else {
|
|
2267
|
+
console.log(`
|
|
2268
|
+
\uD83D\uDCC1 Setting up monorepo structure...`);
|
|
2269
|
+
const webDir = join2(targetPath, "web");
|
|
2270
|
+
const tempDir = join2(targetPath, "_temp_web");
|
|
2271
|
+
mkdirSync2(tempDir, { recursive: true });
|
|
2272
|
+
const files = readdirSync(targetPath);
|
|
2273
|
+
for (const file of files) {
|
|
2274
|
+
if (file !== "_temp_web") {
|
|
2275
|
+
renameSync(join2(targetPath, file), join2(tempDir, file));
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
renameSync(tempDir, webDir);
|
|
2279
|
+
webPath = webDir;
|
|
2280
|
+
const rootPackageJson = {
|
|
2281
|
+
name: projectName,
|
|
2282
|
+
private: true,
|
|
2283
|
+
workspaces: ["web"],
|
|
2284
|
+
scripts: {
|
|
2285
|
+
dev: "cd web && bun dev",
|
|
2286
|
+
build: "cd web && bun run build"
|
|
2287
|
+
}
|
|
2288
|
+
};
|
|
2289
|
+
writeFileSync3(join2(targetPath, "package.json"), JSON.stringify(rootPackageJson, null, 2));
|
|
2290
|
+
console.log(` Created web/ subdirectory`);
|
|
2291
|
+
}
|
|
2292
|
+
console.log(`
|
|
2293
|
+
\uD83E\uDDF9 Cleaning up demo files...`);
|
|
2294
|
+
const srcDir = join2(webPath, "src");
|
|
2295
|
+
const routesDir = join2(srcDir, "routes");
|
|
2296
|
+
if (existsSync3(routesDir)) {
|
|
2297
|
+
rmSync(routesDir, { recursive: true, force: true });
|
|
2298
|
+
mkdirSync2(routesDir, { recursive: true });
|
|
2299
|
+
}
|
|
2300
|
+
const componentsDir = join2(srcDir, "components");
|
|
2301
|
+
const utilsDir = join2(srcDir, "utils");
|
|
2302
|
+
const stylesDir = join2(srcDir, "styles");
|
|
2303
|
+
if (existsSync3(componentsDir)) {
|
|
2304
|
+
rmSync(componentsDir, { recursive: true, force: true });
|
|
2305
|
+
}
|
|
2306
|
+
if (existsSync3(utilsDir)) {
|
|
2307
|
+
rmSync(utilsDir, { recursive: true, force: true });
|
|
2308
|
+
}
|
|
2309
|
+
if (existsSync3(stylesDir)) {
|
|
2310
|
+
rmSync(stylesDir, { recursive: true, force: true });
|
|
2311
|
+
}
|
|
2312
|
+
const routeTreePath = join2(srcDir, "routeTree.gen.ts");
|
|
2313
|
+
if (existsSync3(routeTreePath)) {
|
|
2314
|
+
rmSync(routeTreePath);
|
|
2315
|
+
}
|
|
2316
|
+
const appDir = join2(webPath, "app");
|
|
2317
|
+
if (existsSync3(appDir)) {
|
|
2318
|
+
rmSync(appDir, { recursive: true, force: true });
|
|
2319
|
+
}
|
|
2320
|
+
writeFileSync3(join2(srcDir, "router.tsx"), ROUTER);
|
|
2321
|
+
writeFileSync3(join2(routesDir, "__root.tsx"), ROOT_ROUTE);
|
|
2322
|
+
writeFileSync3(join2(routesDir, "index.tsx"), ZEBU_INDEX_PAGE);
|
|
2323
|
+
console.log(` Cleaned demo files, added index route`);
|
|
2324
|
+
const pkgPath = join2(webPath, "package.json");
|
|
2325
|
+
if (existsSync3(pkgPath)) {
|
|
2326
|
+
const pkg = JSON.parse(readFileSync2(pkgPath, "utf-8"));
|
|
2327
|
+
pkg.name = options.flat ? projectName : `${projectName}-web`;
|
|
2328
|
+
pkg.dependencies = pkg.dependencies || {};
|
|
2329
|
+
pkg.dependencies["agentation"] = "latest";
|
|
2330
|
+
writeFileSync3(pkgPath, JSON.stringify(pkg, null, 2));
|
|
2331
|
+
}
|
|
2332
|
+
if (options.convex) {
|
|
2333
|
+
console.log(`
|
|
2334
|
+
\uD83D\uDD27 Setting up Convex...`);
|
|
2335
|
+
const addResult = run("bun", ["add", "convex", "convex-react"], { cwd: webPath });
|
|
2336
|
+
if (!addResult.success) {
|
|
2337
|
+
console.error(` Failed to add Convex deps: ${addResult.stderr}`);
|
|
2338
|
+
} else {
|
|
2339
|
+
console.log(` Added convex dependencies`);
|
|
2340
|
+
}
|
|
2341
|
+
const initResult = run("bunx", ["convex", "init"], { cwd: webPath });
|
|
2342
|
+
if (!initResult.success) {
|
|
2343
|
+
console.log(` Note: Run 'bunx convex dev' to complete Convex setup`);
|
|
2344
|
+
} else {
|
|
2345
|
+
console.log(` Initialized Convex`);
|
|
2346
|
+
}
|
|
2347
|
+
const componentsDir2 = join2(webPath, "app", "components");
|
|
2348
|
+
mkdirSync2(componentsDir2, { recursive: true });
|
|
2349
|
+
writeFileSync3(join2(componentsDir2, "ConvexClientProvider.tsx"), CONVEX_PROVIDER);
|
|
2350
|
+
console.log(` Created ConvexClientProvider`);
|
|
2351
|
+
writeFileSync3(join2(webPath, ".env.local.example"), `VITE_CONVEX_URL=your_convex_url_here
|
|
2352
|
+
`);
|
|
2353
|
+
console.log(` Created .env.local.example`);
|
|
2354
|
+
console.log(`
|
|
2355
|
+
⚠️ To complete Convex setup:`);
|
|
2356
|
+
console.log(` 1. cd ${options.flat ? projectName : projectName + "/web"}`);
|
|
2357
|
+
console.log(` 2. bunx convex dev (select/create project)`);
|
|
2358
|
+
console.log(` 3. Wrap your app with <ConvexClientProvider> in app/root.tsx`);
|
|
2359
|
+
}
|
|
2360
|
+
console.log(`
|
|
2361
|
+
\uD83D\uDCDC Creating setup script...`);
|
|
2362
|
+
const zdevDir = join2(targetPath, ".zdev");
|
|
2363
|
+
mkdirSync2(zdevDir, { recursive: true });
|
|
2364
|
+
const setupScriptPath = join2(zdevDir, "setup.sh");
|
|
2365
|
+
writeFileSync3(setupScriptPath, SETUP_SCRIPT, { mode: 493 });
|
|
2366
|
+
console.log(` Created .zdev/setup.sh`);
|
|
2367
|
+
console.log(`
|
|
2368
|
+
\uD83D\uDCE6 Installing dependencies...`);
|
|
2369
|
+
const installResult = run("bun", ["install"], { cwd: webPath });
|
|
2370
|
+
if (!installResult.success) {
|
|
2371
|
+
console.error(` Failed to install: ${installResult.stderr}`);
|
|
2372
|
+
} else {
|
|
2373
|
+
console.log(` Dependencies installed`);
|
|
2374
|
+
}
|
|
2375
|
+
console.log(`
|
|
2376
|
+
\uD83D\uDCDA Initializing git...`);
|
|
2377
|
+
run("git", ["init"], { cwd: targetPath });
|
|
2378
|
+
run("git", ["add", "."], { cwd: targetPath });
|
|
2379
|
+
run("git", ["commit", "-m", "Initial commit from zdev create"], { cwd: targetPath });
|
|
2380
|
+
console.log(` Git initialized`);
|
|
2381
|
+
console.log(`
|
|
2382
|
+
${"─".repeat(50)}`);
|
|
2383
|
+
console.log(`✅ Project "${projectName}" created!
|
|
2384
|
+
`);
|
|
2385
|
+
console.log(`\uD83D\uDCC1 Location: ${targetPath}`);
|
|
2386
|
+
console.log(`
|
|
2387
|
+
\uD83D\uDCDD Next steps:`);
|
|
2388
|
+
console.log(` cd ${projectName}`);
|
|
2389
|
+
if (!options.flat) {
|
|
2390
|
+
console.log(` cd web`);
|
|
2391
|
+
}
|
|
2392
|
+
if (options.convex) {
|
|
2393
|
+
console.log(` bunx convex dev # Setup Convex project`);
|
|
2394
|
+
}
|
|
2395
|
+
console.log(` bun dev # Start dev server`);
|
|
2396
|
+
console.log(`${"─".repeat(50)}`);
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
// src/commands/init.ts
|
|
2400
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync3, writeFileSync as writeFileSync4, readFileSync as readFileSync3 } from "fs";
|
|
2401
|
+
import { resolve as resolve3 } from "path";
|
|
2402
|
+
async function init(projectPath = ".", options = {}) {
|
|
2403
|
+
const fullPath = resolve3(projectPath);
|
|
2404
|
+
if (!existsSync4(fullPath)) {
|
|
2405
|
+
console.error(`❌ Path does not exist: ${fullPath}`);
|
|
2406
|
+
process.exit(1);
|
|
2407
|
+
}
|
|
2408
|
+
if (!isGitRepo(fullPath)) {
|
|
2409
|
+
console.error(`❌ Not a git repository: ${fullPath}`);
|
|
2410
|
+
process.exit(1);
|
|
2411
|
+
}
|
|
2412
|
+
const repoName = getRepoName(fullPath);
|
|
2413
|
+
console.log(`\uD83D\uDC02 Initializing zdev for: ${repoName}`);
|
|
2414
|
+
const zdevDir = resolve3(fullPath, ".zdev");
|
|
2415
|
+
if (!existsSync4(zdevDir)) {
|
|
2416
|
+
mkdirSync3(zdevDir, { recursive: true });
|
|
2417
|
+
console.log(` Created ${zdevDir}`);
|
|
2418
|
+
}
|
|
2419
|
+
const projectConfig = {
|
|
2420
|
+
name: repoName,
|
|
2421
|
+
path: fullPath,
|
|
2422
|
+
initialized: new Date().toISOString()
|
|
2423
|
+
};
|
|
2424
|
+
const configPath = resolve3(zdevDir, "project.json");
|
|
2425
|
+
writeFileSync4(configPath, JSON.stringify(projectConfig, null, 2));
|
|
2426
|
+
console.log(` Created project config`);
|
|
2427
|
+
const gitignorePath = resolve3(fullPath, ".gitignore");
|
|
2428
|
+
if (existsSync4(gitignorePath)) {
|
|
2429
|
+
const content = readFileSync3(gitignorePath, "utf-8");
|
|
2430
|
+
if (!content.includes(".zdev")) {
|
|
2431
|
+
writeFileSync4(gitignorePath, content + `
|
|
2432
|
+
.zdev/
|
|
2433
|
+
`);
|
|
2434
|
+
console.log(` Added .zdev/ to .gitignore`);
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
if (options.seed) {
|
|
2438
|
+
console.log(`
|
|
2439
|
+
\uD83D\uDCE6 Creating seed data...`);
|
|
2440
|
+
const convexDir = resolve3(fullPath, "convex");
|
|
2441
|
+
if (!existsSync4(convexDir)) {
|
|
2442
|
+
console.log(` No convex/ directory found, skipping seed`);
|
|
2443
|
+
} else {
|
|
2444
|
+
const seedPath = getSeedPath(repoName);
|
|
2445
|
+
const result = run("bunx", ["convex", "export", "--path", seedPath], {
|
|
2446
|
+
cwd: fullPath
|
|
2447
|
+
});
|
|
2448
|
+
if (result.success) {
|
|
2449
|
+
console.log(` Seed saved to: ${seedPath}`);
|
|
2450
|
+
} else {
|
|
2451
|
+
console.error(` Failed to create seed: ${result.stderr}`);
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
console.log(`
|
|
2456
|
+
✅ zdev initialized for ${repoName}`);
|
|
2457
|
+
console.log(`
|
|
2458
|
+
Next steps:`);
|
|
2459
|
+
console.log(` zdev start <feature-name> Start working on a feature`);
|
|
2460
|
+
console.log(` zdev list List active worktrees`);
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
// src/commands/start.ts
|
|
2464
|
+
import { existsSync as existsSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync5 } from "fs";
|
|
2465
|
+
import { resolve as resolve4, basename as basename3, join as join3 } from "path";
|
|
2466
|
+
function detectWebDir(worktreePath) {
|
|
2467
|
+
const commonDirs = ["web", "frontend", "app", "client", "packages/web", "apps/web"];
|
|
2468
|
+
for (const dir of commonDirs) {
|
|
2469
|
+
const packagePath = join3(worktreePath, dir, "package.json");
|
|
2470
|
+
if (existsSync5(packagePath)) {
|
|
2471
|
+
return dir;
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
if (existsSync5(join3(worktreePath, "package.json"))) {
|
|
2475
|
+
return ".";
|
|
2476
|
+
}
|
|
2477
|
+
return "web";
|
|
2478
|
+
}
|
|
2479
|
+
async function start(featureName, projectPath = ".", options = {}) {
|
|
2480
|
+
const fullPath = resolve4(projectPath);
|
|
2481
|
+
if (!existsSync5(fullPath)) {
|
|
2482
|
+
console.error(`❌ Path does not exist: ${fullPath}`);
|
|
2483
|
+
process.exit(1);
|
|
2484
|
+
}
|
|
2485
|
+
if (!isGitRepo(fullPath)) {
|
|
2486
|
+
console.error(`❌ Not a git repository: ${fullPath}`);
|
|
2487
|
+
process.exit(1);
|
|
2488
|
+
}
|
|
2489
|
+
const repoName = getRepoName(fullPath);
|
|
2490
|
+
const worktreeName = `${repoName}-${featureName}`;
|
|
2491
|
+
const worktreePath = getWorktreePath(worktreeName);
|
|
2492
|
+
const branchName = `feature/${featureName}`;
|
|
2493
|
+
const baseBranch = options.baseBranch || "origin/main";
|
|
2494
|
+
console.log(`\uD83D\uDC02 Starting feature: ${featureName}`);
|
|
2495
|
+
console.log(` Project: ${repoName}`);
|
|
2496
|
+
console.log(` Branch: ${branchName}`);
|
|
2497
|
+
const config = loadConfig();
|
|
2498
|
+
if (config.allocations[worktreeName]) {
|
|
2499
|
+
console.error(`
|
|
2500
|
+
❌ Feature "${featureName}" already exists for ${repoName}`);
|
|
2501
|
+
console.log(` Run: zdev stop ${featureName} --project ${fullPath}`);
|
|
2502
|
+
process.exit(1);
|
|
2503
|
+
}
|
|
2504
|
+
console.log(`
|
|
2505
|
+
\uD83D\uDCE5 Fetching latest from origin...`);
|
|
2506
|
+
if (!gitFetch(fullPath)) {
|
|
2507
|
+
console.error(` Failed to fetch, continuing anyway...`);
|
|
2508
|
+
}
|
|
2509
|
+
console.log(`
|
|
2510
|
+
\uD83C\uDF33 Creating worktree...`);
|
|
2511
|
+
if (existsSync5(worktreePath)) {
|
|
2512
|
+
console.error(` Worktree path already exists: ${worktreePath}`);
|
|
2513
|
+
process.exit(1);
|
|
2514
|
+
}
|
|
2515
|
+
const worktreeResult = createWorktree(fullPath, worktreePath, branchName, baseBranch);
|
|
2516
|
+
if (!worktreeResult.success) {
|
|
2517
|
+
console.error(` Failed to create worktree: ${worktreeResult.error}`);
|
|
2518
|
+
process.exit(1);
|
|
2519
|
+
}
|
|
2520
|
+
console.log(` Created: ${worktreePath}`);
|
|
2521
|
+
const webDir = options.webDir || detectWebDir(worktreePath);
|
|
2522
|
+
const webPath = webDir === "." ? worktreePath : join3(worktreePath, webDir);
|
|
2523
|
+
console.log(`
|
|
2524
|
+
\uD83D\uDCC1 Web directory: ${webDir === "." ? "(root)" : webDir}`);
|
|
2525
|
+
if (config.copyPatterns && config.copyPatterns.length > 0) {
|
|
2526
|
+
console.log(`
|
|
2527
|
+
\uD83D\uDCCB Copying config files...`);
|
|
2528
|
+
const mainWebPath = webDir === "." ? fullPath : join3(fullPath, webDir);
|
|
2529
|
+
for (const pattern of config.copyPatterns) {
|
|
2530
|
+
const srcPath = join3(mainWebPath, pattern);
|
|
2531
|
+
const destPath = join3(webPath, pattern);
|
|
2532
|
+
if (existsSync5(srcPath) && !existsSync5(destPath)) {
|
|
2533
|
+
try {
|
|
2534
|
+
const content = readFileSync4(srcPath);
|
|
2535
|
+
writeFileSync5(destPath, content);
|
|
2536
|
+
console.log(` Copied ${pattern}`);
|
|
2537
|
+
} catch (e) {
|
|
2538
|
+
console.log(` Could not copy ${pattern}`);
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2543
|
+
const setupScriptPath = join3(worktreePath, ".zdev", "setup.sh");
|
|
2544
|
+
if (existsSync5(setupScriptPath)) {
|
|
2545
|
+
console.log(`
|
|
2546
|
+
\uD83D\uDCE6 Running setup script...`);
|
|
2547
|
+
const setupResult = run("bash", [setupScriptPath], { cwd: webPath });
|
|
2548
|
+
if (!setupResult.success) {
|
|
2549
|
+
console.error(` Setup script failed: ${setupResult.stderr}`);
|
|
2550
|
+
} else {
|
|
2551
|
+
console.log(` Setup complete`);
|
|
2552
|
+
}
|
|
2553
|
+
} else {
|
|
2554
|
+
console.log(`
|
|
2555
|
+
⚠️ No .zdev/setup.sh found, skipping setup`);
|
|
2556
|
+
console.log(` Create one in your project to automate dependency installation`);
|
|
2557
|
+
}
|
|
2558
|
+
const hasConvex = existsSync5(join3(webPath, "convex")) || existsSync5(join3(worktreePath, "convex"));
|
|
2559
|
+
const seedPath = getSeedPath(repoName);
|
|
2560
|
+
if (options.seed && hasConvex && existsSync5(seedPath)) {
|
|
2561
|
+
console.log(`
|
|
2562
|
+
\uD83C\uDF31 Importing seed data...`);
|
|
2563
|
+
const seedResult = run("bunx", ["convex", "import", seedPath], {
|
|
2564
|
+
cwd: webPath
|
|
2565
|
+
});
|
|
2566
|
+
if (seedResult.success) {
|
|
2567
|
+
console.log(` Seed data imported`);
|
|
2568
|
+
} else {
|
|
2569
|
+
console.error(` Failed to import seed: ${seedResult.stderr}`);
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
const ports = options.port ? { frontend: options.port, convex: hasConvex ? options.port + 100 : 0 } : allocatePorts(config, hasConvex);
|
|
2573
|
+
console.log(`
|
|
2574
|
+
\uD83D\uDD0C Allocated ports:`);
|
|
2575
|
+
console.log(` Frontend: ${ports.frontend}`);
|
|
2576
|
+
if (hasConvex) {
|
|
2577
|
+
console.log(` Convex: ${ports.convex}`);
|
|
2578
|
+
}
|
|
2579
|
+
let convexPid;
|
|
2580
|
+
if (hasConvex) {
|
|
2581
|
+
console.log(`
|
|
2582
|
+
\uD83D\uDE80 Starting Convex dev server...`);
|
|
2583
|
+
convexPid = runBackground("bunx", ["convex", "dev", "--tail-logs", "disable"], { cwd: webPath });
|
|
2584
|
+
console.log(` Convex PID: ${convexPid}`);
|
|
2585
|
+
await new Promise((resolve5) => setTimeout(resolve5, 2000));
|
|
2586
|
+
}
|
|
2587
|
+
const viteConfigTsPath = join3(webPath, "vite.config.ts");
|
|
2588
|
+
const viteConfigJsPath = join3(webPath, "vite.config.js");
|
|
2589
|
+
const viteConfigPath = existsSync5(viteConfigTsPath) ? viteConfigTsPath : existsSync5(viteConfigJsPath) ? viteConfigJsPath : null;
|
|
2590
|
+
if (viteConfigPath) {
|
|
2591
|
+
try {
|
|
2592
|
+
let viteConfig = readFileSync4(viteConfigPath, "utf-8");
|
|
2593
|
+
if (!viteConfig.includes("allowedHosts")) {
|
|
2594
|
+
let patched = false;
|
|
2595
|
+
if (viteConfig.includes("server:") || viteConfig.includes("server :")) {
|
|
2596
|
+
viteConfig = viteConfig.replace(/server\s*:\s*\{/, `server: {
|
|
2597
|
+
allowedHosts: true,`);
|
|
2598
|
+
patched = true;
|
|
2599
|
+
} else if (viteConfig.includes("defineConfig({")) {
|
|
2600
|
+
viteConfig = viteConfig.replace(/defineConfig\(\{/, `defineConfig({
|
|
2601
|
+
server: {
|
|
2602
|
+
allowedHosts: true,
|
|
2603
|
+
},`);
|
|
2604
|
+
patched = true;
|
|
2605
|
+
}
|
|
2606
|
+
if (patched) {
|
|
2607
|
+
writeFileSync5(viteConfigPath, viteConfig);
|
|
2608
|
+
console.log(` Patched ${basename3(viteConfigPath)} for external access`);
|
|
2609
|
+
run("git", ["update-index", "--skip-worktree", basename3(viteConfigPath)], { cwd: webPath });
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
} catch (e) {
|
|
2613
|
+
console.log(` Could not patch vite config (non-critical)`);
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
console.log(`
|
|
2617
|
+
\uD83C\uDF10 Starting frontend dev server...`);
|
|
2618
|
+
const frontendPid = runBackground("bun", ["dev", "--port", String(ports.frontend), "--host", "0.0.0.0"], { cwd: webPath });
|
|
2619
|
+
console.log(` Frontend PID: ${frontendPid}`);
|
|
2620
|
+
let routePath = "";
|
|
2621
|
+
let publicUrl = "";
|
|
2622
|
+
if (!options.local) {
|
|
2623
|
+
const traefikStatus = getTraefikStatus();
|
|
2624
|
+
if (traefikStatus.running && traefikStatus.devDomain) {
|
|
2625
|
+
routePath = worktreeName;
|
|
2626
|
+
console.log(`
|
|
2627
|
+
\uD83D\uDD17 Setting up Traefik route...`);
|
|
2628
|
+
await new Promise((resolve5) => setTimeout(resolve5, 2000));
|
|
2629
|
+
if (traefikAddRoute(worktreeName, ports.frontend)) {
|
|
2630
|
+
publicUrl = `https://${worktreeName}.${traefikStatus.devDomain}`;
|
|
2631
|
+
console.log(` Public URL: ${publicUrl}`);
|
|
2632
|
+
} else {
|
|
2633
|
+
console.error(` Failed to setup Traefik route`);
|
|
2634
|
+
}
|
|
2635
|
+
} else {
|
|
2636
|
+
console.log(`
|
|
2637
|
+
⚠️ Traefik not configured or devDomain not set, skipping public URL`);
|
|
2638
|
+
console.log(` Run: zdev config --set devDomain=dev.yourdomain.com`);
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
const allocation = {
|
|
2642
|
+
project: repoName,
|
|
2643
|
+
projectPath: fullPath,
|
|
2644
|
+
branch: branchName,
|
|
2645
|
+
webDir,
|
|
2646
|
+
frontendPort: ports.frontend,
|
|
2647
|
+
convexPort: ports.convex,
|
|
2648
|
+
funnelPath: routePath,
|
|
2649
|
+
pids: {
|
|
2650
|
+
frontend: frontendPid,
|
|
2651
|
+
convex: convexPid
|
|
2652
|
+
},
|
|
2653
|
+
started: new Date().toISOString()
|
|
2654
|
+
};
|
|
2655
|
+
config.allocations[worktreeName] = allocation;
|
|
2656
|
+
saveConfig(config);
|
|
2657
|
+
console.log(`
|
|
2658
|
+
${"─".repeat(50)}`);
|
|
2659
|
+
console.log(`✅ Feature "${featureName}" is ready!
|
|
2660
|
+
`);
|
|
2661
|
+
console.log(`\uD83D\uDCC1 Worktree: ${worktreePath}`);
|
|
2662
|
+
console.log(`\uD83C\uDF10 Local: http://localhost:${ports.frontend}`);
|
|
2663
|
+
if (publicUrl) {
|
|
2664
|
+
console.log(`\uD83D\uDD17 Public: ${publicUrl}`);
|
|
2665
|
+
}
|
|
2666
|
+
console.log(`
|
|
2667
|
+
\uD83D\uDCDD Commands:`);
|
|
2668
|
+
console.log(` cd ${worktreePath}`);
|
|
2669
|
+
console.log(` zdev stop ${featureName} --project ${fullPath}`);
|
|
2670
|
+
console.log(`${"─".repeat(50)}`);
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
// src/commands/stop.ts
|
|
2674
|
+
import { resolve as resolve5 } from "path";
|
|
2675
|
+
async function stop(featureName, options = {}) {
|
|
2676
|
+
const config = loadConfig();
|
|
2677
|
+
let worktreeName;
|
|
2678
|
+
let allocation;
|
|
2679
|
+
if (options.project) {
|
|
2680
|
+
const projectPath = resolve5(options.project);
|
|
2681
|
+
const repoName = isGitRepo(projectPath) ? getRepoName(projectPath) : options.project;
|
|
2682
|
+
worktreeName = `${repoName}-${featureName}`;
|
|
2683
|
+
allocation = config.allocations[worktreeName];
|
|
2684
|
+
} else {
|
|
2685
|
+
for (const [name, alloc] of Object.entries(config.allocations)) {
|
|
2686
|
+
if (name.endsWith(`-${featureName}`)) {
|
|
2687
|
+
worktreeName = name;
|
|
2688
|
+
allocation = alloc;
|
|
2689
|
+
break;
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
if (!worktreeName || !allocation) {
|
|
2694
|
+
console.error(`❌ Feature "${featureName}" not found`);
|
|
2695
|
+
console.log(`
|
|
2696
|
+
Run 'zdev list' to see active features`);
|
|
2697
|
+
process.exit(1);
|
|
2698
|
+
}
|
|
2699
|
+
console.log(`\uD83D\uDC02 Stopping feature: ${featureName}`);
|
|
2700
|
+
console.log(` Project: ${allocation.project}`);
|
|
2701
|
+
if (allocation.pids.frontend && isProcessRunning(allocation.pids.frontend)) {
|
|
2702
|
+
console.log(`
|
|
2703
|
+
\uD83D\uDED1 Stopping frontend (PID: ${allocation.pids.frontend})...`);
|
|
2704
|
+
if (killProcess(allocation.pids.frontend)) {
|
|
2705
|
+
console.log(` Frontend stopped`);
|
|
2706
|
+
} else {
|
|
2707
|
+
console.error(` Failed to stop frontend`);
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
if (allocation.pids.convex && isProcessRunning(allocation.pids.convex)) {
|
|
2711
|
+
console.log(`
|
|
2712
|
+
\uD83D\uDED1 Stopping Convex (PID: ${allocation.pids.convex})...`);
|
|
2713
|
+
if (killProcess(allocation.pids.convex)) {
|
|
2714
|
+
console.log(` Convex stopped`);
|
|
2715
|
+
} else {
|
|
2716
|
+
console.error(` Failed to stop Convex`);
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
if (allocation.funnelPath) {
|
|
2720
|
+
console.log(`
|
|
2721
|
+
\uD83D\uDD17 Removing Traefik route...`);
|
|
2722
|
+
if (traefikRemoveRoute(allocation.funnelPath)) {
|
|
2723
|
+
console.log(` Route removed`);
|
|
2724
|
+
} else {
|
|
2725
|
+
console.error(` Failed to remove route (may already be removed)`);
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
delete config.allocations[worktreeName];
|
|
2729
|
+
saveConfig(config);
|
|
2730
|
+
const worktreePath = getWorktreePath(worktreeName);
|
|
2731
|
+
if (options.keep) {
|
|
2732
|
+
console.log(`
|
|
2733
|
+
✅ Feature "${featureName}" stopped (worktree kept)`);
|
|
2734
|
+
console.log(` Worktree: ${worktreePath}`);
|
|
2735
|
+
console.log(`
|
|
2736
|
+
To remove worktree: zdev clean ${featureName}`);
|
|
2737
|
+
} else {
|
|
2738
|
+
console.log(`
|
|
2739
|
+
✅ Feature "${featureName}" stopped`);
|
|
2740
|
+
console.log(`
|
|
2741
|
+
Worktree still exists at: ${worktreePath}`);
|
|
2742
|
+
console.log(` To remove: zdev clean ${featureName} --project ${allocation.projectPath}`);
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
|
|
2746
|
+
// src/commands/list.ts
|
|
2747
|
+
import { existsSync as existsSync6 } from "fs";
|
|
2748
|
+
async function list(options = {}) {
|
|
2749
|
+
const config = loadConfig();
|
|
2750
|
+
const allocations = Object.entries(config.allocations);
|
|
2751
|
+
if (options.json) {
|
|
2752
|
+
console.log(JSON.stringify(config, null, 2));
|
|
2753
|
+
return;
|
|
2754
|
+
}
|
|
2755
|
+
console.log(`\uD83D\uDC02 zdev Status
|
|
2756
|
+
`);
|
|
2757
|
+
console.log(`\uD83D\uDCC1 Home: ${ZEBU_HOME}`);
|
|
2758
|
+
console.log(`\uD83D\uDCC1 Worktrees: ${WORKTREES_DIR}`);
|
|
2759
|
+
const traefikStatus = getTraefikStatus();
|
|
2760
|
+
if (traefikStatus.running) {
|
|
2761
|
+
console.log(`\uD83D\uDD17 Traefik: running (*.${traefikStatus.devDomain || "dev.example.com"})`);
|
|
2762
|
+
} else {
|
|
2763
|
+
console.log(`\uD83D\uDD17 Traefik: not running`);
|
|
2764
|
+
}
|
|
2765
|
+
console.log(`
|
|
2766
|
+
${"─".repeat(60)}`);
|
|
2767
|
+
if (allocations.length === 0) {
|
|
2768
|
+
console.log(`
|
|
2769
|
+
No active features.
|
|
2770
|
+
`);
|
|
2771
|
+
console.log(`Start one with: zdev start <feature-name> --project <path>`);
|
|
2772
|
+
return;
|
|
2773
|
+
}
|
|
2774
|
+
console.log(`
|
|
2775
|
+
\uD83D\uDCCB Active Features (${allocations.length}):
|
|
2776
|
+
`);
|
|
2777
|
+
for (const [name, alloc] of allocations) {
|
|
2778
|
+
const worktreePath = getWorktreePath(name);
|
|
2779
|
+
const worktreeExists = existsSync6(worktreePath);
|
|
2780
|
+
const frontendRunning = alloc.pids.frontend ? isProcessRunning(alloc.pids.frontend) : false;
|
|
2781
|
+
const convexRunning = alloc.pids.convex ? isProcessRunning(alloc.pids.convex) : false;
|
|
2782
|
+
const statusEmoji = frontendRunning && convexRunning ? "\uD83D\uDFE2" : frontendRunning || convexRunning ? "\uD83D\uDFE1" : "\uD83D\uDD34";
|
|
2783
|
+
console.log(`${statusEmoji} ${name}`);
|
|
2784
|
+
console.log(` Project: ${alloc.project}`);
|
|
2785
|
+
console.log(` Branch: ${alloc.branch}`);
|
|
2786
|
+
console.log(` Path: ${worktreePath} ${worktreeExists ? "" : "(missing)"}`);
|
|
2787
|
+
console.log(` Local: http://localhost:${alloc.frontendPort}`);
|
|
2788
|
+
if (alloc.funnelPath && traefikStatus.devDomain) {
|
|
2789
|
+
console.log(` Public: https://${alloc.funnelPath}.${traefikStatus.devDomain}`);
|
|
2790
|
+
}
|
|
2791
|
+
console.log(` Frontend: ${frontendRunning ? `running (PID: ${alloc.pids.frontend})` : "stopped"}`);
|
|
2792
|
+
console.log(` Convex: ${convexRunning ? `running (PID: ${alloc.pids.convex})` : "stopped"}`);
|
|
2793
|
+
console.log(` Started: ${new Date(alloc.started).toLocaleString()}`);
|
|
2794
|
+
console.log();
|
|
2795
|
+
}
|
|
2796
|
+
console.log(`${"─".repeat(60)}`);
|
|
2797
|
+
console.log(`
|
|
2798
|
+
Commands:`);
|
|
2799
|
+
console.log(` zdev stop <feature> Stop servers for a feature`);
|
|
2800
|
+
console.log(` zdev clean <feature> Remove worktree after merge`);
|
|
2801
|
+
}
|
|
2802
|
+
|
|
2803
|
+
// src/commands/clean.ts
|
|
2804
|
+
import { existsSync as existsSync7, rmSync as rmSync2 } from "fs";
|
|
2805
|
+
import { resolve as resolve6 } from "path";
|
|
2806
|
+
async function clean(featureName, options = {}) {
|
|
2807
|
+
const config = loadConfig();
|
|
2808
|
+
let worktreeName;
|
|
2809
|
+
let allocation;
|
|
2810
|
+
let projectPath;
|
|
2811
|
+
if (options.project) {
|
|
2812
|
+
projectPath = resolve6(options.project);
|
|
2813
|
+
const repoName = isGitRepo(projectPath) ? getRepoName(projectPath) : options.project;
|
|
2814
|
+
worktreeName = `${repoName}-${featureName}`;
|
|
2815
|
+
allocation = config.allocations[worktreeName];
|
|
2816
|
+
} else {
|
|
2817
|
+
for (const [name, alloc] of Object.entries(config.allocations)) {
|
|
2818
|
+
if (name.endsWith(`-${featureName}`)) {
|
|
2819
|
+
worktreeName = name;
|
|
2820
|
+
allocation = alloc;
|
|
2821
|
+
projectPath = alloc.projectPath;
|
|
2822
|
+
break;
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
if (!worktreeName) {
|
|
2826
|
+
const entries = Object.keys(config.allocations);
|
|
2827
|
+
console.error(`❌ Feature "${featureName}" not found in active allocations`);
|
|
2828
|
+
if (entries.length > 0) {
|
|
2829
|
+
console.log(`
|
|
2830
|
+
Active features:`);
|
|
2831
|
+
entries.forEach((e) => console.log(` - ${e}`));
|
|
2832
|
+
}
|
|
2833
|
+
process.exit(1);
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
const worktreePath = getWorktreePath(worktreeName);
|
|
2837
|
+
console.log(`\uD83D\uDC02 Cleaning feature: ${featureName}`);
|
|
2838
|
+
if (allocation) {
|
|
2839
|
+
if (allocation.pids.frontend && isProcessRunning(allocation.pids.frontend)) {
|
|
2840
|
+
console.log(`
|
|
2841
|
+
\uD83D\uDED1 Stopping frontend...`);
|
|
2842
|
+
killProcess(allocation.pids.frontend);
|
|
2843
|
+
}
|
|
2844
|
+
if (allocation.pids.convex && isProcessRunning(allocation.pids.convex)) {
|
|
2845
|
+
console.log(`\uD83D\uDED1 Stopping Convex...`);
|
|
2846
|
+
killProcess(allocation.pids.convex);
|
|
2847
|
+
}
|
|
2848
|
+
if (allocation.funnelPath) {
|
|
2849
|
+
console.log(`\uD83D\uDD17 Removing Traefik route...`);
|
|
2850
|
+
traefikRemoveRoute(allocation.funnelPath);
|
|
2851
|
+
}
|
|
2852
|
+
projectPath = allocation.projectPath;
|
|
2853
|
+
}
|
|
2854
|
+
if (existsSync7(worktreePath)) {
|
|
2855
|
+
console.log(`
|
|
2856
|
+
\uD83D\uDDD1️ Removing worktree...`);
|
|
2857
|
+
if (projectPath && isGitRepo(projectPath)) {
|
|
2858
|
+
const result = removeWorktree(projectPath, worktreePath);
|
|
2859
|
+
if (!result.success) {
|
|
2860
|
+
if (options.force) {
|
|
2861
|
+
console.log(` Git worktree remove failed, force removing directory...`);
|
|
2862
|
+
rmSync2(worktreePath, { recursive: true, force: true });
|
|
2863
|
+
} else {
|
|
2864
|
+
console.error(` Failed to remove worktree: ${result.error}`);
|
|
2865
|
+
console.log(` Use --force to force remove`);
|
|
2866
|
+
process.exit(1);
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
} else if (options.force) {
|
|
2870
|
+
rmSync2(worktreePath, { recursive: true, force: true });
|
|
2871
|
+
} else {
|
|
2872
|
+
console.error(` Cannot remove worktree: project path unknown`);
|
|
2873
|
+
console.log(` Use --force to force remove, or specify --project`);
|
|
2874
|
+
process.exit(1);
|
|
2875
|
+
}
|
|
2876
|
+
console.log(` Worktree removed`);
|
|
2877
|
+
} else {
|
|
2878
|
+
console.log(`
|
|
2879
|
+
Worktree already removed`);
|
|
2880
|
+
}
|
|
2881
|
+
if (worktreeName && config.allocations[worktreeName]) {
|
|
2882
|
+
delete config.allocations[worktreeName];
|
|
2883
|
+
saveConfig(config);
|
|
2884
|
+
}
|
|
2885
|
+
console.log(`
|
|
2886
|
+
✅ Feature "${featureName}" cleaned up`);
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2889
|
+
// src/commands/seed.ts
|
|
2890
|
+
import { existsSync as existsSync8 } from "fs";
|
|
2891
|
+
import { resolve as resolve7 } from "path";
|
|
2892
|
+
async function seedExport(projectPath = ".", options = {}) {
|
|
2893
|
+
const fullPath = resolve7(projectPath);
|
|
2894
|
+
if (!existsSync8(fullPath)) {
|
|
2895
|
+
console.error(`❌ Path does not exist: ${fullPath}`);
|
|
2896
|
+
process.exit(1);
|
|
2897
|
+
}
|
|
2898
|
+
if (!isGitRepo(fullPath)) {
|
|
2899
|
+
console.error(`❌ Not a git repository: ${fullPath}`);
|
|
2900
|
+
process.exit(1);
|
|
2901
|
+
}
|
|
2902
|
+
const repoName = getRepoName(fullPath);
|
|
2903
|
+
const seedPath = getSeedPath(repoName);
|
|
2904
|
+
console.log(`\uD83D\uDC02 Exporting seed data for: ${repoName}`);
|
|
2905
|
+
ensurezdevDirs();
|
|
2906
|
+
const result = run("bunx", ["convex", "export", "--path", seedPath], {
|
|
2907
|
+
cwd: fullPath
|
|
2908
|
+
});
|
|
2909
|
+
if (result.success) {
|
|
2910
|
+
console.log(`
|
|
2911
|
+
✅ Seed exported to: ${seedPath}`);
|
|
2912
|
+
} else {
|
|
2913
|
+
console.error(`
|
|
2914
|
+
❌ Failed to export seed:`);
|
|
2915
|
+
console.error(result.stderr);
|
|
2916
|
+
process.exit(1);
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
async function seedImport(projectPath = ".", options = {}) {
|
|
2920
|
+
const fullPath = resolve7(projectPath);
|
|
2921
|
+
if (!existsSync8(fullPath)) {
|
|
2922
|
+
console.error(`❌ Path does not exist: ${fullPath}`);
|
|
2923
|
+
process.exit(1);
|
|
2924
|
+
}
|
|
2925
|
+
let repoName;
|
|
2926
|
+
const projectConfigPath = resolve7(fullPath, ".zdev", "project.json");
|
|
2927
|
+
if (existsSync8(projectConfigPath)) {
|
|
2928
|
+
try {
|
|
2929
|
+
const config = JSON.parse(await Bun.file(projectConfigPath).text());
|
|
2930
|
+
repoName = config.name;
|
|
2931
|
+
} catch {
|
|
2932
|
+
repoName = getRepoName(fullPath);
|
|
2933
|
+
}
|
|
2934
|
+
} else if (isGitRepo(fullPath)) {
|
|
2935
|
+
repoName = getRepoName(fullPath);
|
|
2936
|
+
} else {
|
|
2937
|
+
console.error(`❌ Cannot determine project name`);
|
|
2938
|
+
process.exit(1);
|
|
2939
|
+
}
|
|
2940
|
+
const seedPath = getSeedPath(repoName);
|
|
2941
|
+
if (!existsSync8(seedPath)) {
|
|
2942
|
+
console.error(`❌ No seed found for ${repoName}`);
|
|
2943
|
+
console.log(` Expected: ${seedPath}`);
|
|
2944
|
+
console.log(`
|
|
2945
|
+
Create one with: zdev seed export --project <main-repo-path>`);
|
|
2946
|
+
process.exit(1);
|
|
2947
|
+
}
|
|
2948
|
+
console.log(`\uD83D\uDC02 Importing seed data for: ${repoName}`);
|
|
2949
|
+
console.log(` From: ${seedPath}`);
|
|
2950
|
+
const result = run("bunx", ["convex", "import", "--replace", seedPath], {
|
|
2951
|
+
cwd: fullPath
|
|
2952
|
+
});
|
|
2953
|
+
if (result.success) {
|
|
2954
|
+
console.log(`
|
|
2955
|
+
✅ Seed imported successfully`);
|
|
2956
|
+
} else {
|
|
2957
|
+
console.error(`
|
|
2958
|
+
❌ Failed to import seed:`);
|
|
2959
|
+
console.error(result.stderr);
|
|
2960
|
+
process.exit(1);
|
|
2961
|
+
}
|
|
2962
|
+
}
|
|
2963
|
+
|
|
2964
|
+
// src/commands/config.ts
|
|
2965
|
+
async function configCmd(options = {}) {
|
|
2966
|
+
const config = loadConfig();
|
|
2967
|
+
if (options.set) {
|
|
2968
|
+
const [key, ...valueParts] = options.set.split("=");
|
|
2969
|
+
const value = valueParts.join("=");
|
|
2970
|
+
if (!value) {
|
|
2971
|
+
console.error(`Usage: zdev config --set key=value`);
|
|
2972
|
+
console.log(`
|
|
2973
|
+
Configurable keys:`);
|
|
2974
|
+
console.log(` devDomain Dev domain for public URLs`);
|
|
2975
|
+
console.log(` dockerHostIp Docker host IP for Traefik`);
|
|
2976
|
+
console.log(` traefikConfigDir Traefik dynamic config directory`);
|
|
2977
|
+
return;
|
|
2978
|
+
}
|
|
2979
|
+
if (key === "devDomain") {
|
|
2980
|
+
config.devDomain = value;
|
|
2981
|
+
saveConfig(config);
|
|
2982
|
+
console.log(`✅ Set devDomain = ${value}`);
|
|
2983
|
+
} else if (key === "dockerHostIp") {
|
|
2984
|
+
config.dockerHostIp = value;
|
|
2985
|
+
saveConfig(config);
|
|
2986
|
+
console.log(`✅ Set dockerHostIp = ${value}`);
|
|
2987
|
+
} else if (key === "traefikConfigDir") {
|
|
2988
|
+
config.traefikConfigDir = value;
|
|
2989
|
+
saveConfig(config);
|
|
2990
|
+
console.log(`✅ Set traefikConfigDir = ${value}`);
|
|
2991
|
+
} else {
|
|
2992
|
+
console.error(`Unknown config key: ${key}`);
|
|
2993
|
+
}
|
|
2994
|
+
return;
|
|
2995
|
+
}
|
|
2996
|
+
if (options.list || !options.add && !options.remove) {
|
|
2997
|
+
console.log(`\uD83D\uDC02 zdev Configuration
|
|
2998
|
+
`);
|
|
2999
|
+
console.log(`\uD83D\uDCC1 Config file: ${CONFIG_PATH}`);
|
|
3000
|
+
console.log(`
|
|
3001
|
+
\uD83C\uDF10 Traefik / Public URLs:`);
|
|
3002
|
+
console.log(` Dev domain: ${config.devDomain}`);
|
|
3003
|
+
console.log(` Docker host IP: ${config.dockerHostIp}`);
|
|
3004
|
+
console.log(` Config dir: ${config.traefikConfigDir}`);
|
|
3005
|
+
console.log(`
|
|
3006
|
+
\uD83D\uDCCB Copy patterns (files auto-copied to worktrees):`);
|
|
3007
|
+
if (config.copyPatterns && config.copyPatterns.length > 0) {
|
|
3008
|
+
for (const pattern of config.copyPatterns) {
|
|
3009
|
+
console.log(` - ${pattern}`);
|
|
3010
|
+
}
|
|
3011
|
+
} else {
|
|
3012
|
+
console.log(` (none)`);
|
|
3013
|
+
}
|
|
3014
|
+
console.log(`
|
|
3015
|
+
\uD83D\uDD0C Port allocation:`);
|
|
3016
|
+
console.log(` Next frontend port: ${config.nextFrontendPort}`);
|
|
3017
|
+
console.log(` Next Convex port: ${config.nextConvexPort}`);
|
|
3018
|
+
console.log(`
|
|
3019
|
+
Commands:`);
|
|
3020
|
+
console.log(` zdev config --set devDomain=dev.example.com`);
|
|
3021
|
+
console.log(` zdev config --add ".env.local"`);
|
|
3022
|
+
console.log(` zdev config --remove ".env.local"`);
|
|
3023
|
+
return;
|
|
3024
|
+
}
|
|
3025
|
+
if (options.add) {
|
|
3026
|
+
if (!config.copyPatterns) {
|
|
3027
|
+
config.copyPatterns = [];
|
|
3028
|
+
}
|
|
3029
|
+
if (config.copyPatterns.includes(options.add)) {
|
|
3030
|
+
console.log(`Pattern "${options.add}" already exists`);
|
|
3031
|
+
} else {
|
|
3032
|
+
config.copyPatterns.push(options.add);
|
|
3033
|
+
saveConfig(config);
|
|
3034
|
+
console.log(`✅ Added copy pattern: ${options.add}`);
|
|
3035
|
+
}
|
|
3036
|
+
return;
|
|
3037
|
+
}
|
|
3038
|
+
if (options.remove) {
|
|
3039
|
+
if (!config.copyPatterns) {
|
|
3040
|
+
console.log(`Pattern "${options.remove}" not found`);
|
|
3041
|
+
return;
|
|
3042
|
+
}
|
|
3043
|
+
const index = config.copyPatterns.indexOf(options.remove);
|
|
3044
|
+
if (index === -1) {
|
|
3045
|
+
console.log(`Pattern "${options.remove}" not found`);
|
|
3046
|
+
} else {
|
|
3047
|
+
config.copyPatterns.splice(index, 1);
|
|
3048
|
+
saveConfig(config);
|
|
3049
|
+
console.log(`✅ Removed copy pattern: ${options.remove}`);
|
|
3050
|
+
}
|
|
3051
|
+
return;
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
|
|
3055
|
+
// src/index.ts
|
|
3056
|
+
var program2 = new Command;
|
|
3057
|
+
program2.name("zdev").description("\uD83D\uDC02 zdev - Multi-agent worktree development environment").version("0.1.0");
|
|
3058
|
+
program2.command("create <name>").description("Create a new TanStack Start project").option("--convex", "Add Convex backend integration").option("--flat", "Flat structure (no monorepo)").action(async (name, options) => {
|
|
3059
|
+
await create(name, {
|
|
3060
|
+
convex: options.convex,
|
|
3061
|
+
flat: options.flat
|
|
3062
|
+
});
|
|
3063
|
+
});
|
|
3064
|
+
program2.command("init [path]").description("Initialize zdev for a project").option("-s, --seed", "Create initial seed data from current Convex state").action(async (path, options) => {
|
|
3065
|
+
await init(path, options);
|
|
3066
|
+
});
|
|
3067
|
+
program2.command("start <feature>").description("Start working on a feature (creates worktree, starts servers)").option("-p, --project <path>", "Project path (default: current directory)", ".").option("--port <number>", "Frontend port (auto-allocated if not specified)", parseInt).option("--local", "Local only - skip public URL setup via Traefik").option("-s, --seed", "Import seed data into the new worktree").option("-b, --base-branch <branch>", "Base branch to create from", "origin/main").option("-w, --web-dir <dir>", "Subdirectory containing package.json (auto-detected if not specified)").action(async (feature, options) => {
|
|
3068
|
+
await start(feature, options.project, {
|
|
3069
|
+
port: options.port,
|
|
3070
|
+
local: options.local,
|
|
3071
|
+
seed: options.seed,
|
|
3072
|
+
baseBranch: options.baseBranch,
|
|
3073
|
+
webDir: options.webDir
|
|
3074
|
+
});
|
|
3075
|
+
});
|
|
3076
|
+
program2.command("stop <feature>").description("Stop servers for a feature").option("-p, --project <path>", "Project path (to disambiguate features)").option("-k, --keep", "Keep worktree, just stop servers").action(async (feature, options) => {
|
|
3077
|
+
await stop(feature, options);
|
|
3078
|
+
});
|
|
3079
|
+
program2.command("list").description("List active features and their status").option("--json", "Output as JSON").action(async (options) => {
|
|
3080
|
+
await list(options);
|
|
3081
|
+
});
|
|
3082
|
+
program2.command("clean <feature>").description("Remove a feature worktree (use after PR is merged)").option("-p, --project <path>", "Project path").option("-f, --force", "Force remove even if git worktree fails").action(async (feature, options) => {
|
|
3083
|
+
await clean(feature, options);
|
|
3084
|
+
});
|
|
3085
|
+
var seedCmd = program2.command("seed").description("Manage seed data for projects");
|
|
3086
|
+
seedCmd.command("export [path]").description("Export current Convex data as seed").action(async (path) => {
|
|
3087
|
+
await seedExport(path);
|
|
3088
|
+
});
|
|
3089
|
+
seedCmd.command("import [path]").description("Import seed data into current worktree").action(async (path) => {
|
|
3090
|
+
await seedImport(path);
|
|
3091
|
+
});
|
|
3092
|
+
program2.command("config").description("View and manage zdev configuration").option("-a, --add <pattern>", "Add a file pattern to auto-copy").option("-r, --remove <pattern>", "Remove a file pattern").option("-s, --set <key=value>", "Set a config value (devDomain, dockerHostIp, traefikConfigDir)").option("-l, --list", "List current configuration").action(async (options) => {
|
|
3093
|
+
await configCmd(options);
|
|
3094
|
+
});
|
|
3095
|
+
program2.command("status").description("Show zdev status (alias for list)").action(async () => {
|
|
3096
|
+
await list({});
|
|
3097
|
+
});
|
|
3098
|
+
program2.parse();
|