@evitcastudio/kit 1.0.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/CONTRIBUTING.md +0 -0
- package/LICENSE +21 -0
- package/README.md +40 -0
- package/bin/cli.ts +71 -0
- package/bin/index.ts +11 -0
- package/bin/resource-builder.ts +196 -0
- package/bin/types/shared-types.ts +10 -0
- package/bun-build.ts +56 -0
- package/bun.lockb +0 -0
- package/bunfig.toml +4 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +78 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1610 -0
- package/docs/classes/index.Kit.html +23 -0
- package/docs/index.html +15 -0
- package/docs/modules/index.html +1 -0
- package/docs/modules/types_shared-types.html +1 -0
- package/docs/modules.html +1 -0
- package/docs/types/types_shared-types.EmitterEvent.html +4 -0
- package/docs/types/types_shared-types.Listener.html +1 -0
- package/lib/bundle/cli/cli.js +2659 -0
- package/lib/event-system.d.ts +12 -0
- package/lib/event-system.d.ts.map +1 -0
- package/lib/event-system.js +25 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +1 -0
- package/lib/kit.d.ts +54 -0
- package/lib/kit.d.ts.map +1 -0
- package/lib/kit.js +91 -0
- package/lib/types/shared-types.d.ts +18 -0
- package/lib/types/shared-types.d.ts.map +1 -0
- package/lib/types/shared-types.js +1 -0
- package/package.json +53 -0
- package/src/event-system.ts +29 -0
- package/src/index.ts +1 -0
- package/src/kit.ts +106 -0
- package/src/types/shared-types.ts +19 -0
- package/tests/kit-cli.test.ts +75 -0
- package/tests/kit.test.ts +33 -0
- package/tsconfig.json +37 -0
|
@@ -0,0 +1,2659 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/*!
|
|
4
|
+
* @evitcastudio/kit@1.0.0 git+https://github.com/EvitcaStudio/Kit.git
|
|
5
|
+
* Compiled Wed, 25 Dec 2024 13:13:26 UTC
|
|
6
|
+
* Copyright (c) 2024 Jared Bates, Evitca Studio, "doubleactii"
|
|
7
|
+
*
|
|
8
|
+
* @evitcastudio/kit is licensed under the MIT License.
|
|
9
|
+
* http://www.opensource.org/licenses/mit-license
|
|
10
|
+
*/
|
|
11
|
+
import { createRequire } from "node:module";
|
|
12
|
+
var __create = Object.create;
|
|
13
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
14
|
+
var __defProp = Object.defineProperty;
|
|
15
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
18
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
19
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
20
|
+
for (let key of __getOwnPropNames(mod))
|
|
21
|
+
if (!__hasOwnProp.call(to, key))
|
|
22
|
+
__defProp(to, key, {
|
|
23
|
+
get: () => mod[key],
|
|
24
|
+
enumerable: true
|
|
25
|
+
});
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
29
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
30
|
+
|
|
31
|
+
// node_modules/commander/lib/error.js
|
|
32
|
+
var require_error = __commonJS((exports) => {
|
|
33
|
+
class CommanderError extends Error {
|
|
34
|
+
constructor(exitCode, code, message) {
|
|
35
|
+
super(message);
|
|
36
|
+
Error.captureStackTrace(this, this.constructor);
|
|
37
|
+
this.name = this.constructor.name;
|
|
38
|
+
this.code = code;
|
|
39
|
+
this.exitCode = exitCode;
|
|
40
|
+
this.nestedError = undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
class InvalidArgumentError extends CommanderError {
|
|
45
|
+
constructor(message) {
|
|
46
|
+
super(1, "commander.invalidArgument", message);
|
|
47
|
+
Error.captureStackTrace(this, this.constructor);
|
|
48
|
+
this.name = this.constructor.name;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.CommanderError = CommanderError;
|
|
52
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// node_modules/commander/lib/argument.js
|
|
56
|
+
var require_argument = __commonJS((exports) => {
|
|
57
|
+
var { InvalidArgumentError } = require_error();
|
|
58
|
+
|
|
59
|
+
class Argument {
|
|
60
|
+
constructor(name, description) {
|
|
61
|
+
this.description = description || "";
|
|
62
|
+
this.variadic = false;
|
|
63
|
+
this.parseArg = undefined;
|
|
64
|
+
this.defaultValue = undefined;
|
|
65
|
+
this.defaultValueDescription = undefined;
|
|
66
|
+
this.argChoices = undefined;
|
|
67
|
+
switch (name[0]) {
|
|
68
|
+
case "<":
|
|
69
|
+
this.required = true;
|
|
70
|
+
this._name = name.slice(1, -1);
|
|
71
|
+
break;
|
|
72
|
+
case "[":
|
|
73
|
+
this.required = false;
|
|
74
|
+
this._name = name.slice(1, -1);
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
this.required = true;
|
|
78
|
+
this._name = name;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
if (this._name.length > 3 && this._name.slice(-3) === "...") {
|
|
82
|
+
this.variadic = true;
|
|
83
|
+
this._name = this._name.slice(0, -3);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
name() {
|
|
87
|
+
return this._name;
|
|
88
|
+
}
|
|
89
|
+
_concatValue(value, previous) {
|
|
90
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
91
|
+
return [value];
|
|
92
|
+
}
|
|
93
|
+
return previous.concat(value);
|
|
94
|
+
}
|
|
95
|
+
default(value, description) {
|
|
96
|
+
this.defaultValue = value;
|
|
97
|
+
this.defaultValueDescription = description;
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
argParser(fn) {
|
|
101
|
+
this.parseArg = fn;
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
choices(values) {
|
|
105
|
+
this.argChoices = values.slice();
|
|
106
|
+
this.parseArg = (arg, previous) => {
|
|
107
|
+
if (!this.argChoices.includes(arg)) {
|
|
108
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
109
|
+
}
|
|
110
|
+
if (this.variadic) {
|
|
111
|
+
return this._concatValue(arg, previous);
|
|
112
|
+
}
|
|
113
|
+
return arg;
|
|
114
|
+
};
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
argRequired() {
|
|
118
|
+
this.required = true;
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
argOptional() {
|
|
122
|
+
this.required = false;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function humanReadableArgName(arg) {
|
|
127
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
128
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
129
|
+
}
|
|
130
|
+
exports.Argument = Argument;
|
|
131
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// node_modules/commander/lib/help.js
|
|
135
|
+
var require_help = __commonJS((exports) => {
|
|
136
|
+
var { humanReadableArgName } = require_argument();
|
|
137
|
+
|
|
138
|
+
class Help {
|
|
139
|
+
constructor() {
|
|
140
|
+
this.helpWidth = undefined;
|
|
141
|
+
this.sortSubcommands = false;
|
|
142
|
+
this.sortOptions = false;
|
|
143
|
+
this.showGlobalOptions = false;
|
|
144
|
+
}
|
|
145
|
+
visibleCommands(cmd) {
|
|
146
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
147
|
+
const helpCommand = cmd._getHelpCommand();
|
|
148
|
+
if (helpCommand && !helpCommand._hidden) {
|
|
149
|
+
visibleCommands.push(helpCommand);
|
|
150
|
+
}
|
|
151
|
+
if (this.sortSubcommands) {
|
|
152
|
+
visibleCommands.sort((a, b) => {
|
|
153
|
+
return a.name().localeCompare(b.name());
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return visibleCommands;
|
|
157
|
+
}
|
|
158
|
+
compareOptions(a, b) {
|
|
159
|
+
const getSortKey = (option) => {
|
|
160
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
161
|
+
};
|
|
162
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
163
|
+
}
|
|
164
|
+
visibleOptions(cmd) {
|
|
165
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
166
|
+
const helpOption = cmd._getHelpOption();
|
|
167
|
+
if (helpOption && !helpOption.hidden) {
|
|
168
|
+
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
169
|
+
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
170
|
+
if (!removeShort && !removeLong) {
|
|
171
|
+
visibleOptions.push(helpOption);
|
|
172
|
+
} else if (helpOption.long && !removeLong) {
|
|
173
|
+
visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
|
|
174
|
+
} else if (helpOption.short && !removeShort) {
|
|
175
|
+
visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (this.sortOptions) {
|
|
179
|
+
visibleOptions.sort(this.compareOptions);
|
|
180
|
+
}
|
|
181
|
+
return visibleOptions;
|
|
182
|
+
}
|
|
183
|
+
visibleGlobalOptions(cmd) {
|
|
184
|
+
if (!this.showGlobalOptions)
|
|
185
|
+
return [];
|
|
186
|
+
const globalOptions = [];
|
|
187
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
188
|
+
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
|
|
189
|
+
globalOptions.push(...visibleOptions);
|
|
190
|
+
}
|
|
191
|
+
if (this.sortOptions) {
|
|
192
|
+
globalOptions.sort(this.compareOptions);
|
|
193
|
+
}
|
|
194
|
+
return globalOptions;
|
|
195
|
+
}
|
|
196
|
+
visibleArguments(cmd) {
|
|
197
|
+
if (cmd._argsDescription) {
|
|
198
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
199
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
203
|
+
return cmd.registeredArguments;
|
|
204
|
+
}
|
|
205
|
+
return [];
|
|
206
|
+
}
|
|
207
|
+
subcommandTerm(cmd) {
|
|
208
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
209
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
210
|
+
}
|
|
211
|
+
optionTerm(option) {
|
|
212
|
+
return option.flags;
|
|
213
|
+
}
|
|
214
|
+
argumentTerm(argument) {
|
|
215
|
+
return argument.name();
|
|
216
|
+
}
|
|
217
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
218
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
219
|
+
return Math.max(max, helper.subcommandTerm(command).length);
|
|
220
|
+
}, 0);
|
|
221
|
+
}
|
|
222
|
+
longestOptionTermLength(cmd, helper) {
|
|
223
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
224
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
225
|
+
}, 0);
|
|
226
|
+
}
|
|
227
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
228
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
229
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
230
|
+
}, 0);
|
|
231
|
+
}
|
|
232
|
+
longestArgumentTermLength(cmd, helper) {
|
|
233
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
234
|
+
return Math.max(max, helper.argumentTerm(argument).length);
|
|
235
|
+
}, 0);
|
|
236
|
+
}
|
|
237
|
+
commandUsage(cmd) {
|
|
238
|
+
let cmdName = cmd._name;
|
|
239
|
+
if (cmd._aliases[0]) {
|
|
240
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
241
|
+
}
|
|
242
|
+
let ancestorCmdNames = "";
|
|
243
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
244
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
245
|
+
}
|
|
246
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
247
|
+
}
|
|
248
|
+
commandDescription(cmd) {
|
|
249
|
+
return cmd.description();
|
|
250
|
+
}
|
|
251
|
+
subcommandDescription(cmd) {
|
|
252
|
+
return cmd.summary() || cmd.description();
|
|
253
|
+
}
|
|
254
|
+
optionDescription(option) {
|
|
255
|
+
const extraInfo = [];
|
|
256
|
+
if (option.argChoices) {
|
|
257
|
+
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
258
|
+
}
|
|
259
|
+
if (option.defaultValue !== undefined) {
|
|
260
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
261
|
+
if (showDefault) {
|
|
262
|
+
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (option.presetArg !== undefined && option.optional) {
|
|
266
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
267
|
+
}
|
|
268
|
+
if (option.envVar !== undefined) {
|
|
269
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
270
|
+
}
|
|
271
|
+
if (extraInfo.length > 0) {
|
|
272
|
+
return `${option.description} (${extraInfo.join(", ")})`;
|
|
273
|
+
}
|
|
274
|
+
return option.description;
|
|
275
|
+
}
|
|
276
|
+
argumentDescription(argument) {
|
|
277
|
+
const extraInfo = [];
|
|
278
|
+
if (argument.argChoices) {
|
|
279
|
+
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
280
|
+
}
|
|
281
|
+
if (argument.defaultValue !== undefined) {
|
|
282
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
283
|
+
}
|
|
284
|
+
if (extraInfo.length > 0) {
|
|
285
|
+
const extraDescripton = `(${extraInfo.join(", ")})`;
|
|
286
|
+
if (argument.description) {
|
|
287
|
+
return `${argument.description} ${extraDescripton}`;
|
|
288
|
+
}
|
|
289
|
+
return extraDescripton;
|
|
290
|
+
}
|
|
291
|
+
return argument.description;
|
|
292
|
+
}
|
|
293
|
+
formatHelp(cmd, helper) {
|
|
294
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
295
|
+
const helpWidth = helper.helpWidth || 80;
|
|
296
|
+
const itemIndentWidth = 2;
|
|
297
|
+
const itemSeparatorWidth = 2;
|
|
298
|
+
function formatItem(term, description) {
|
|
299
|
+
if (description) {
|
|
300
|
+
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
301
|
+
return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
|
|
302
|
+
}
|
|
303
|
+
return term;
|
|
304
|
+
}
|
|
305
|
+
function formatList(textArray) {
|
|
306
|
+
return textArray.join(`
|
|
307
|
+
`).replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
308
|
+
}
|
|
309
|
+
let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
|
|
310
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
311
|
+
if (commandDescription.length > 0) {
|
|
312
|
+
output = output.concat([
|
|
313
|
+
helper.wrap(commandDescription, helpWidth, 0),
|
|
314
|
+
""
|
|
315
|
+
]);
|
|
316
|
+
}
|
|
317
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
318
|
+
return formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument));
|
|
319
|
+
});
|
|
320
|
+
if (argumentList.length > 0) {
|
|
321
|
+
output = output.concat(["Arguments:", formatList(argumentList), ""]);
|
|
322
|
+
}
|
|
323
|
+
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
324
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
325
|
+
});
|
|
326
|
+
if (optionList.length > 0) {
|
|
327
|
+
output = output.concat(["Options:", formatList(optionList), ""]);
|
|
328
|
+
}
|
|
329
|
+
if (this.showGlobalOptions) {
|
|
330
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
331
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
332
|
+
});
|
|
333
|
+
if (globalOptionList.length > 0) {
|
|
334
|
+
output = output.concat([
|
|
335
|
+
"Global Options:",
|
|
336
|
+
formatList(globalOptionList),
|
|
337
|
+
""
|
|
338
|
+
]);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
342
|
+
return formatItem(helper.subcommandTerm(cmd2), helper.subcommandDescription(cmd2));
|
|
343
|
+
});
|
|
344
|
+
if (commandList.length > 0) {
|
|
345
|
+
output = output.concat(["Commands:", formatList(commandList), ""]);
|
|
346
|
+
}
|
|
347
|
+
return output.join(`
|
|
348
|
+
`);
|
|
349
|
+
}
|
|
350
|
+
padWidth(cmd, helper) {
|
|
351
|
+
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
352
|
+
}
|
|
353
|
+
wrap(str, width, indent, minColumnWidth = 40) {
|
|
354
|
+
const indents = " \\f\\t\\v - \uFEFF";
|
|
355
|
+
const manualIndent = new RegExp(`[\\n][${indents}]+`);
|
|
356
|
+
if (str.match(manualIndent))
|
|
357
|
+
return str;
|
|
358
|
+
const columnWidth = width - indent;
|
|
359
|
+
if (columnWidth < minColumnWidth)
|
|
360
|
+
return str;
|
|
361
|
+
const leadingStr = str.slice(0, indent);
|
|
362
|
+
const columnText = str.slice(indent).replace(`\r
|
|
363
|
+
`, `
|
|
364
|
+
`);
|
|
365
|
+
const indentString = " ".repeat(indent);
|
|
366
|
+
const zeroWidthSpace = "";
|
|
367
|
+
const breaks = `\\s${zeroWidthSpace}`;
|
|
368
|
+
const regex = new RegExp(`
|
|
369
|
+
|.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`, "g");
|
|
370
|
+
const lines = columnText.match(regex) || [];
|
|
371
|
+
return leadingStr + lines.map((line, i) => {
|
|
372
|
+
if (line === `
|
|
373
|
+
`)
|
|
374
|
+
return "";
|
|
375
|
+
return (i > 0 ? indentString : "") + line.trimEnd();
|
|
376
|
+
}).join(`
|
|
377
|
+
`);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
exports.Help = Help;
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// node_modules/commander/lib/option.js
|
|
384
|
+
var require_option = __commonJS((exports) => {
|
|
385
|
+
var { InvalidArgumentError } = require_error();
|
|
386
|
+
|
|
387
|
+
class Option {
|
|
388
|
+
constructor(flags, description) {
|
|
389
|
+
this.flags = flags;
|
|
390
|
+
this.description = description || "";
|
|
391
|
+
this.required = flags.includes("<");
|
|
392
|
+
this.optional = flags.includes("[");
|
|
393
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
394
|
+
this.mandatory = false;
|
|
395
|
+
const optionFlags = splitOptionFlags(flags);
|
|
396
|
+
this.short = optionFlags.shortFlag;
|
|
397
|
+
this.long = optionFlags.longFlag;
|
|
398
|
+
this.negate = false;
|
|
399
|
+
if (this.long) {
|
|
400
|
+
this.negate = this.long.startsWith("--no-");
|
|
401
|
+
}
|
|
402
|
+
this.defaultValue = undefined;
|
|
403
|
+
this.defaultValueDescription = undefined;
|
|
404
|
+
this.presetArg = undefined;
|
|
405
|
+
this.envVar = undefined;
|
|
406
|
+
this.parseArg = undefined;
|
|
407
|
+
this.hidden = false;
|
|
408
|
+
this.argChoices = undefined;
|
|
409
|
+
this.conflictsWith = [];
|
|
410
|
+
this.implied = undefined;
|
|
411
|
+
}
|
|
412
|
+
default(value, description) {
|
|
413
|
+
this.defaultValue = value;
|
|
414
|
+
this.defaultValueDescription = description;
|
|
415
|
+
return this;
|
|
416
|
+
}
|
|
417
|
+
preset(arg) {
|
|
418
|
+
this.presetArg = arg;
|
|
419
|
+
return this;
|
|
420
|
+
}
|
|
421
|
+
conflicts(names) {
|
|
422
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
423
|
+
return this;
|
|
424
|
+
}
|
|
425
|
+
implies(impliedOptionValues) {
|
|
426
|
+
let newImplied = impliedOptionValues;
|
|
427
|
+
if (typeof impliedOptionValues === "string") {
|
|
428
|
+
newImplied = { [impliedOptionValues]: true };
|
|
429
|
+
}
|
|
430
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
431
|
+
return this;
|
|
432
|
+
}
|
|
433
|
+
env(name) {
|
|
434
|
+
this.envVar = name;
|
|
435
|
+
return this;
|
|
436
|
+
}
|
|
437
|
+
argParser(fn) {
|
|
438
|
+
this.parseArg = fn;
|
|
439
|
+
return this;
|
|
440
|
+
}
|
|
441
|
+
makeOptionMandatory(mandatory = true) {
|
|
442
|
+
this.mandatory = !!mandatory;
|
|
443
|
+
return this;
|
|
444
|
+
}
|
|
445
|
+
hideHelp(hide = true) {
|
|
446
|
+
this.hidden = !!hide;
|
|
447
|
+
return this;
|
|
448
|
+
}
|
|
449
|
+
_concatValue(value, previous) {
|
|
450
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
451
|
+
return [value];
|
|
452
|
+
}
|
|
453
|
+
return previous.concat(value);
|
|
454
|
+
}
|
|
455
|
+
choices(values) {
|
|
456
|
+
this.argChoices = values.slice();
|
|
457
|
+
this.parseArg = (arg, previous) => {
|
|
458
|
+
if (!this.argChoices.includes(arg)) {
|
|
459
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
460
|
+
}
|
|
461
|
+
if (this.variadic) {
|
|
462
|
+
return this._concatValue(arg, previous);
|
|
463
|
+
}
|
|
464
|
+
return arg;
|
|
465
|
+
};
|
|
466
|
+
return this;
|
|
467
|
+
}
|
|
468
|
+
name() {
|
|
469
|
+
if (this.long) {
|
|
470
|
+
return this.long.replace(/^--/, "");
|
|
471
|
+
}
|
|
472
|
+
return this.short.replace(/^-/, "");
|
|
473
|
+
}
|
|
474
|
+
attributeName() {
|
|
475
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
476
|
+
}
|
|
477
|
+
is(arg) {
|
|
478
|
+
return this.short === arg || this.long === arg;
|
|
479
|
+
}
|
|
480
|
+
isBoolean() {
|
|
481
|
+
return !this.required && !this.optional && !this.negate;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
class DualOptions {
|
|
486
|
+
constructor(options) {
|
|
487
|
+
this.positiveOptions = new Map;
|
|
488
|
+
this.negativeOptions = new Map;
|
|
489
|
+
this.dualOptions = new Set;
|
|
490
|
+
options.forEach((option) => {
|
|
491
|
+
if (option.negate) {
|
|
492
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
493
|
+
} else {
|
|
494
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
this.negativeOptions.forEach((value, key) => {
|
|
498
|
+
if (this.positiveOptions.has(key)) {
|
|
499
|
+
this.dualOptions.add(key);
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
valueFromOption(value, option) {
|
|
504
|
+
const optionKey = option.attributeName();
|
|
505
|
+
if (!this.dualOptions.has(optionKey))
|
|
506
|
+
return true;
|
|
507
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
508
|
+
const negativeValue = preset !== undefined ? preset : false;
|
|
509
|
+
return option.negate === (negativeValue === value);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
function camelcase(str) {
|
|
513
|
+
return str.split("-").reduce((str2, word) => {
|
|
514
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
function splitOptionFlags(flags) {
|
|
518
|
+
let shortFlag;
|
|
519
|
+
let longFlag;
|
|
520
|
+
const flagParts = flags.split(/[ |,]+/);
|
|
521
|
+
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
522
|
+
shortFlag = flagParts.shift();
|
|
523
|
+
longFlag = flagParts.shift();
|
|
524
|
+
if (!shortFlag && /^-[^-]$/.test(longFlag)) {
|
|
525
|
+
shortFlag = longFlag;
|
|
526
|
+
longFlag = undefined;
|
|
527
|
+
}
|
|
528
|
+
return { shortFlag, longFlag };
|
|
529
|
+
}
|
|
530
|
+
exports.Option = Option;
|
|
531
|
+
exports.DualOptions = DualOptions;
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
// node_modules/commander/lib/suggestSimilar.js
|
|
535
|
+
var require_suggestSimilar = __commonJS((exports) => {
|
|
536
|
+
var maxDistance = 3;
|
|
537
|
+
function editDistance(a, b) {
|
|
538
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
539
|
+
return Math.max(a.length, b.length);
|
|
540
|
+
const d = [];
|
|
541
|
+
for (let i = 0;i <= a.length; i++) {
|
|
542
|
+
d[i] = [i];
|
|
543
|
+
}
|
|
544
|
+
for (let j = 0;j <= b.length; j++) {
|
|
545
|
+
d[0][j] = j;
|
|
546
|
+
}
|
|
547
|
+
for (let j = 1;j <= b.length; j++) {
|
|
548
|
+
for (let i = 1;i <= a.length; i++) {
|
|
549
|
+
let cost = 1;
|
|
550
|
+
if (a[i - 1] === b[j - 1]) {
|
|
551
|
+
cost = 0;
|
|
552
|
+
} else {
|
|
553
|
+
cost = 1;
|
|
554
|
+
}
|
|
555
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
556
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
557
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return d[a.length][b.length];
|
|
562
|
+
}
|
|
563
|
+
function suggestSimilar(word, candidates) {
|
|
564
|
+
if (!candidates || candidates.length === 0)
|
|
565
|
+
return "";
|
|
566
|
+
candidates = Array.from(new Set(candidates));
|
|
567
|
+
const searchingOptions = word.startsWith("--");
|
|
568
|
+
if (searchingOptions) {
|
|
569
|
+
word = word.slice(2);
|
|
570
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
571
|
+
}
|
|
572
|
+
let similar = [];
|
|
573
|
+
let bestDistance = maxDistance;
|
|
574
|
+
const minSimilarity = 0.4;
|
|
575
|
+
candidates.forEach((candidate) => {
|
|
576
|
+
if (candidate.length <= 1)
|
|
577
|
+
return;
|
|
578
|
+
const distance = editDistance(word, candidate);
|
|
579
|
+
const length = Math.max(word.length, candidate.length);
|
|
580
|
+
const similarity = (length - distance) / length;
|
|
581
|
+
if (similarity > minSimilarity) {
|
|
582
|
+
if (distance < bestDistance) {
|
|
583
|
+
bestDistance = distance;
|
|
584
|
+
similar = [candidate];
|
|
585
|
+
} else if (distance === bestDistance) {
|
|
586
|
+
similar.push(candidate);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
591
|
+
if (searchingOptions) {
|
|
592
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
593
|
+
}
|
|
594
|
+
if (similar.length > 1) {
|
|
595
|
+
return `
|
|
596
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
597
|
+
}
|
|
598
|
+
if (similar.length === 1) {
|
|
599
|
+
return `
|
|
600
|
+
(Did you mean ${similar[0]}?)`;
|
|
601
|
+
}
|
|
602
|
+
return "";
|
|
603
|
+
}
|
|
604
|
+
exports.suggestSimilar = suggestSimilar;
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
// node_modules/commander/lib/command.js
|
|
608
|
+
var require_command = __commonJS((exports) => {
|
|
609
|
+
var EventEmitter = __require("node:events").EventEmitter;
|
|
610
|
+
var childProcess = __require("node:child_process");
|
|
611
|
+
var path = __require("node:path");
|
|
612
|
+
var fs = __require("node:fs");
|
|
613
|
+
var process2 = __require("node:process");
|
|
614
|
+
var { Argument, humanReadableArgName } = require_argument();
|
|
615
|
+
var { CommanderError } = require_error();
|
|
616
|
+
var { Help } = require_help();
|
|
617
|
+
var { Option, DualOptions } = require_option();
|
|
618
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
619
|
+
|
|
620
|
+
class Command extends EventEmitter {
|
|
621
|
+
constructor(name) {
|
|
622
|
+
super();
|
|
623
|
+
this.commands = [];
|
|
624
|
+
this.options = [];
|
|
625
|
+
this.parent = null;
|
|
626
|
+
this._allowUnknownOption = false;
|
|
627
|
+
this._allowExcessArguments = true;
|
|
628
|
+
this.registeredArguments = [];
|
|
629
|
+
this._args = this.registeredArguments;
|
|
630
|
+
this.args = [];
|
|
631
|
+
this.rawArgs = [];
|
|
632
|
+
this.processedArgs = [];
|
|
633
|
+
this._scriptPath = null;
|
|
634
|
+
this._name = name || "";
|
|
635
|
+
this._optionValues = {};
|
|
636
|
+
this._optionValueSources = {};
|
|
637
|
+
this._storeOptionsAsProperties = false;
|
|
638
|
+
this._actionHandler = null;
|
|
639
|
+
this._executableHandler = false;
|
|
640
|
+
this._executableFile = null;
|
|
641
|
+
this._executableDir = null;
|
|
642
|
+
this._defaultCommandName = null;
|
|
643
|
+
this._exitCallback = null;
|
|
644
|
+
this._aliases = [];
|
|
645
|
+
this._combineFlagAndOptionalValue = true;
|
|
646
|
+
this._description = "";
|
|
647
|
+
this._summary = "";
|
|
648
|
+
this._argsDescription = undefined;
|
|
649
|
+
this._enablePositionalOptions = false;
|
|
650
|
+
this._passThroughOptions = false;
|
|
651
|
+
this._lifeCycleHooks = {};
|
|
652
|
+
this._showHelpAfterError = false;
|
|
653
|
+
this._showSuggestionAfterError = true;
|
|
654
|
+
this._outputConfiguration = {
|
|
655
|
+
writeOut: (str) => process2.stdout.write(str),
|
|
656
|
+
writeErr: (str) => process2.stderr.write(str),
|
|
657
|
+
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
|
|
658
|
+
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
|
|
659
|
+
outputError: (str, write) => write(str)
|
|
660
|
+
};
|
|
661
|
+
this._hidden = false;
|
|
662
|
+
this._helpOption = undefined;
|
|
663
|
+
this._addImplicitHelpCommand = undefined;
|
|
664
|
+
this._helpCommand = undefined;
|
|
665
|
+
this._helpConfiguration = {};
|
|
666
|
+
}
|
|
667
|
+
copyInheritedSettings(sourceCommand) {
|
|
668
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
669
|
+
this._helpOption = sourceCommand._helpOption;
|
|
670
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
671
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
672
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
673
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
674
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
675
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
676
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
677
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
678
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
679
|
+
return this;
|
|
680
|
+
}
|
|
681
|
+
_getCommandAndAncestors() {
|
|
682
|
+
const result = [];
|
|
683
|
+
for (let command = this;command; command = command.parent) {
|
|
684
|
+
result.push(command);
|
|
685
|
+
}
|
|
686
|
+
return result;
|
|
687
|
+
}
|
|
688
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
689
|
+
let desc = actionOptsOrExecDesc;
|
|
690
|
+
let opts = execOpts;
|
|
691
|
+
if (typeof desc === "object" && desc !== null) {
|
|
692
|
+
opts = desc;
|
|
693
|
+
desc = null;
|
|
694
|
+
}
|
|
695
|
+
opts = opts || {};
|
|
696
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
697
|
+
const cmd = this.createCommand(name);
|
|
698
|
+
if (desc) {
|
|
699
|
+
cmd.description(desc);
|
|
700
|
+
cmd._executableHandler = true;
|
|
701
|
+
}
|
|
702
|
+
if (opts.isDefault)
|
|
703
|
+
this._defaultCommandName = cmd._name;
|
|
704
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
705
|
+
cmd._executableFile = opts.executableFile || null;
|
|
706
|
+
if (args)
|
|
707
|
+
cmd.arguments(args);
|
|
708
|
+
this._registerCommand(cmd);
|
|
709
|
+
cmd.parent = this;
|
|
710
|
+
cmd.copyInheritedSettings(this);
|
|
711
|
+
if (desc)
|
|
712
|
+
return this;
|
|
713
|
+
return cmd;
|
|
714
|
+
}
|
|
715
|
+
createCommand(name) {
|
|
716
|
+
return new Command(name);
|
|
717
|
+
}
|
|
718
|
+
createHelp() {
|
|
719
|
+
return Object.assign(new Help, this.configureHelp());
|
|
720
|
+
}
|
|
721
|
+
configureHelp(configuration) {
|
|
722
|
+
if (configuration === undefined)
|
|
723
|
+
return this._helpConfiguration;
|
|
724
|
+
this._helpConfiguration = configuration;
|
|
725
|
+
return this;
|
|
726
|
+
}
|
|
727
|
+
configureOutput(configuration) {
|
|
728
|
+
if (configuration === undefined)
|
|
729
|
+
return this._outputConfiguration;
|
|
730
|
+
Object.assign(this._outputConfiguration, configuration);
|
|
731
|
+
return this;
|
|
732
|
+
}
|
|
733
|
+
showHelpAfterError(displayHelp = true) {
|
|
734
|
+
if (typeof displayHelp !== "string")
|
|
735
|
+
displayHelp = !!displayHelp;
|
|
736
|
+
this._showHelpAfterError = displayHelp;
|
|
737
|
+
return this;
|
|
738
|
+
}
|
|
739
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
740
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
741
|
+
return this;
|
|
742
|
+
}
|
|
743
|
+
addCommand(cmd, opts) {
|
|
744
|
+
if (!cmd._name) {
|
|
745
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
746
|
+
- specify the name in Command constructor or using .name()`);
|
|
747
|
+
}
|
|
748
|
+
opts = opts || {};
|
|
749
|
+
if (opts.isDefault)
|
|
750
|
+
this._defaultCommandName = cmd._name;
|
|
751
|
+
if (opts.noHelp || opts.hidden)
|
|
752
|
+
cmd._hidden = true;
|
|
753
|
+
this._registerCommand(cmd);
|
|
754
|
+
cmd.parent = this;
|
|
755
|
+
cmd._checkForBrokenPassThrough();
|
|
756
|
+
return this;
|
|
757
|
+
}
|
|
758
|
+
createArgument(name, description) {
|
|
759
|
+
return new Argument(name, description);
|
|
760
|
+
}
|
|
761
|
+
argument(name, description, fn, defaultValue) {
|
|
762
|
+
const argument = this.createArgument(name, description);
|
|
763
|
+
if (typeof fn === "function") {
|
|
764
|
+
argument.default(defaultValue).argParser(fn);
|
|
765
|
+
} else {
|
|
766
|
+
argument.default(fn);
|
|
767
|
+
}
|
|
768
|
+
this.addArgument(argument);
|
|
769
|
+
return this;
|
|
770
|
+
}
|
|
771
|
+
arguments(names) {
|
|
772
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
773
|
+
this.argument(detail);
|
|
774
|
+
});
|
|
775
|
+
return this;
|
|
776
|
+
}
|
|
777
|
+
addArgument(argument) {
|
|
778
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
779
|
+
if (previousArgument && previousArgument.variadic) {
|
|
780
|
+
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
781
|
+
}
|
|
782
|
+
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
783
|
+
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
784
|
+
}
|
|
785
|
+
this.registeredArguments.push(argument);
|
|
786
|
+
return this;
|
|
787
|
+
}
|
|
788
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
789
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
790
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
791
|
+
return this;
|
|
792
|
+
}
|
|
793
|
+
enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
794
|
+
const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
|
|
795
|
+
const helpDescription = description ?? "display help for command";
|
|
796
|
+
const helpCommand = this.createCommand(helpName);
|
|
797
|
+
helpCommand.helpOption(false);
|
|
798
|
+
if (helpArgs)
|
|
799
|
+
helpCommand.arguments(helpArgs);
|
|
800
|
+
if (helpDescription)
|
|
801
|
+
helpCommand.description(helpDescription);
|
|
802
|
+
this._addImplicitHelpCommand = true;
|
|
803
|
+
this._helpCommand = helpCommand;
|
|
804
|
+
return this;
|
|
805
|
+
}
|
|
806
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
807
|
+
if (typeof helpCommand !== "object") {
|
|
808
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
809
|
+
return this;
|
|
810
|
+
}
|
|
811
|
+
this._addImplicitHelpCommand = true;
|
|
812
|
+
this._helpCommand = helpCommand;
|
|
813
|
+
return this;
|
|
814
|
+
}
|
|
815
|
+
_getHelpCommand() {
|
|
816
|
+
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
817
|
+
if (hasImplicitHelpCommand) {
|
|
818
|
+
if (this._helpCommand === undefined) {
|
|
819
|
+
this.helpCommand(undefined, undefined);
|
|
820
|
+
}
|
|
821
|
+
return this._helpCommand;
|
|
822
|
+
}
|
|
823
|
+
return null;
|
|
824
|
+
}
|
|
825
|
+
hook(event, listener) {
|
|
826
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
827
|
+
if (!allowedValues.includes(event)) {
|
|
828
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
829
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
830
|
+
}
|
|
831
|
+
if (this._lifeCycleHooks[event]) {
|
|
832
|
+
this._lifeCycleHooks[event].push(listener);
|
|
833
|
+
} else {
|
|
834
|
+
this._lifeCycleHooks[event] = [listener];
|
|
835
|
+
}
|
|
836
|
+
return this;
|
|
837
|
+
}
|
|
838
|
+
exitOverride(fn) {
|
|
839
|
+
if (fn) {
|
|
840
|
+
this._exitCallback = fn;
|
|
841
|
+
} else {
|
|
842
|
+
this._exitCallback = (err) => {
|
|
843
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
844
|
+
throw err;
|
|
845
|
+
} else {
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
return this;
|
|
850
|
+
}
|
|
851
|
+
_exit(exitCode, code, message) {
|
|
852
|
+
if (this._exitCallback) {
|
|
853
|
+
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
854
|
+
}
|
|
855
|
+
process2.exit(exitCode);
|
|
856
|
+
}
|
|
857
|
+
action(fn) {
|
|
858
|
+
const listener = (args) => {
|
|
859
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
860
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
861
|
+
if (this._storeOptionsAsProperties) {
|
|
862
|
+
actionArgs[expectedArgsCount] = this;
|
|
863
|
+
} else {
|
|
864
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
865
|
+
}
|
|
866
|
+
actionArgs.push(this);
|
|
867
|
+
return fn.apply(this, actionArgs);
|
|
868
|
+
};
|
|
869
|
+
this._actionHandler = listener;
|
|
870
|
+
return this;
|
|
871
|
+
}
|
|
872
|
+
createOption(flags, description) {
|
|
873
|
+
return new Option(flags, description);
|
|
874
|
+
}
|
|
875
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
876
|
+
try {
|
|
877
|
+
return target.parseArg(value, previous);
|
|
878
|
+
} catch (err) {
|
|
879
|
+
if (err.code === "commander.invalidArgument") {
|
|
880
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
881
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
882
|
+
}
|
|
883
|
+
throw err;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
_registerOption(option) {
|
|
887
|
+
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
888
|
+
if (matchingOption) {
|
|
889
|
+
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
890
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
891
|
+
- already used by option '${matchingOption.flags}'`);
|
|
892
|
+
}
|
|
893
|
+
this.options.push(option);
|
|
894
|
+
}
|
|
895
|
+
_registerCommand(command) {
|
|
896
|
+
const knownBy = (cmd) => {
|
|
897
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
898
|
+
};
|
|
899
|
+
const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
|
|
900
|
+
if (alreadyUsed) {
|
|
901
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
902
|
+
const newCmd = knownBy(command).join("|");
|
|
903
|
+
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
904
|
+
}
|
|
905
|
+
this.commands.push(command);
|
|
906
|
+
}
|
|
907
|
+
addOption(option) {
|
|
908
|
+
this._registerOption(option);
|
|
909
|
+
const oname = option.name();
|
|
910
|
+
const name = option.attributeName();
|
|
911
|
+
if (option.negate) {
|
|
912
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
913
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
914
|
+
this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
|
|
915
|
+
}
|
|
916
|
+
} else if (option.defaultValue !== undefined) {
|
|
917
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
918
|
+
}
|
|
919
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
920
|
+
if (val == null && option.presetArg !== undefined) {
|
|
921
|
+
val = option.presetArg;
|
|
922
|
+
}
|
|
923
|
+
const oldValue = this.getOptionValue(name);
|
|
924
|
+
if (val !== null && option.parseArg) {
|
|
925
|
+
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
926
|
+
} else if (val !== null && option.variadic) {
|
|
927
|
+
val = option._concatValue(val, oldValue);
|
|
928
|
+
}
|
|
929
|
+
if (val == null) {
|
|
930
|
+
if (option.negate) {
|
|
931
|
+
val = false;
|
|
932
|
+
} else if (option.isBoolean() || option.optional) {
|
|
933
|
+
val = true;
|
|
934
|
+
} else {
|
|
935
|
+
val = "";
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
939
|
+
};
|
|
940
|
+
this.on("option:" + oname, (val) => {
|
|
941
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
942
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
943
|
+
});
|
|
944
|
+
if (option.envVar) {
|
|
945
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
946
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
947
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
return this;
|
|
951
|
+
}
|
|
952
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
953
|
+
if (typeof flags === "object" && flags instanceof Option) {
|
|
954
|
+
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
955
|
+
}
|
|
956
|
+
const option = this.createOption(flags, description);
|
|
957
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
958
|
+
if (typeof fn === "function") {
|
|
959
|
+
option.default(defaultValue).argParser(fn);
|
|
960
|
+
} else if (fn instanceof RegExp) {
|
|
961
|
+
const regex = fn;
|
|
962
|
+
fn = (val, def) => {
|
|
963
|
+
const m = regex.exec(val);
|
|
964
|
+
return m ? m[0] : def;
|
|
965
|
+
};
|
|
966
|
+
option.default(defaultValue).argParser(fn);
|
|
967
|
+
} else {
|
|
968
|
+
option.default(fn);
|
|
969
|
+
}
|
|
970
|
+
return this.addOption(option);
|
|
971
|
+
}
|
|
972
|
+
option(flags, description, parseArg, defaultValue) {
|
|
973
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
974
|
+
}
|
|
975
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
976
|
+
return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
|
|
977
|
+
}
|
|
978
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
979
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
980
|
+
return this;
|
|
981
|
+
}
|
|
982
|
+
allowUnknownOption(allowUnknown = true) {
|
|
983
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
984
|
+
return this;
|
|
985
|
+
}
|
|
986
|
+
allowExcessArguments(allowExcess = true) {
|
|
987
|
+
this._allowExcessArguments = !!allowExcess;
|
|
988
|
+
return this;
|
|
989
|
+
}
|
|
990
|
+
enablePositionalOptions(positional = true) {
|
|
991
|
+
this._enablePositionalOptions = !!positional;
|
|
992
|
+
return this;
|
|
993
|
+
}
|
|
994
|
+
passThroughOptions(passThrough = true) {
|
|
995
|
+
this._passThroughOptions = !!passThrough;
|
|
996
|
+
this._checkForBrokenPassThrough();
|
|
997
|
+
return this;
|
|
998
|
+
}
|
|
999
|
+
_checkForBrokenPassThrough() {
|
|
1000
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
1001
|
+
throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
1005
|
+
if (this.options.length) {
|
|
1006
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
1007
|
+
}
|
|
1008
|
+
if (Object.keys(this._optionValues).length) {
|
|
1009
|
+
throw new Error("call .storeOptionsAsProperties() before setting option values");
|
|
1010
|
+
}
|
|
1011
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
1012
|
+
return this;
|
|
1013
|
+
}
|
|
1014
|
+
getOptionValue(key) {
|
|
1015
|
+
if (this._storeOptionsAsProperties) {
|
|
1016
|
+
return this[key];
|
|
1017
|
+
}
|
|
1018
|
+
return this._optionValues[key];
|
|
1019
|
+
}
|
|
1020
|
+
setOptionValue(key, value) {
|
|
1021
|
+
return this.setOptionValueWithSource(key, value, undefined);
|
|
1022
|
+
}
|
|
1023
|
+
setOptionValueWithSource(key, value, source) {
|
|
1024
|
+
if (this._storeOptionsAsProperties) {
|
|
1025
|
+
this[key] = value;
|
|
1026
|
+
} else {
|
|
1027
|
+
this._optionValues[key] = value;
|
|
1028
|
+
}
|
|
1029
|
+
this._optionValueSources[key] = source;
|
|
1030
|
+
return this;
|
|
1031
|
+
}
|
|
1032
|
+
getOptionValueSource(key) {
|
|
1033
|
+
return this._optionValueSources[key];
|
|
1034
|
+
}
|
|
1035
|
+
getOptionValueSourceWithGlobals(key) {
|
|
1036
|
+
let source;
|
|
1037
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1038
|
+
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
1039
|
+
source = cmd.getOptionValueSource(key);
|
|
1040
|
+
}
|
|
1041
|
+
});
|
|
1042
|
+
return source;
|
|
1043
|
+
}
|
|
1044
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
1045
|
+
if (argv !== undefined && !Array.isArray(argv)) {
|
|
1046
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
1047
|
+
}
|
|
1048
|
+
parseOptions = parseOptions || {};
|
|
1049
|
+
if (argv === undefined && parseOptions.from === undefined) {
|
|
1050
|
+
if (process2.versions?.electron) {
|
|
1051
|
+
parseOptions.from = "electron";
|
|
1052
|
+
}
|
|
1053
|
+
const execArgv = process2.execArgv ?? [];
|
|
1054
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
1055
|
+
parseOptions.from = "eval";
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
if (argv === undefined) {
|
|
1059
|
+
argv = process2.argv;
|
|
1060
|
+
}
|
|
1061
|
+
this.rawArgs = argv.slice();
|
|
1062
|
+
let userArgs;
|
|
1063
|
+
switch (parseOptions.from) {
|
|
1064
|
+
case undefined:
|
|
1065
|
+
case "node":
|
|
1066
|
+
this._scriptPath = argv[1];
|
|
1067
|
+
userArgs = argv.slice(2);
|
|
1068
|
+
break;
|
|
1069
|
+
case "electron":
|
|
1070
|
+
if (process2.defaultApp) {
|
|
1071
|
+
this._scriptPath = argv[1];
|
|
1072
|
+
userArgs = argv.slice(2);
|
|
1073
|
+
} else {
|
|
1074
|
+
userArgs = argv.slice(1);
|
|
1075
|
+
}
|
|
1076
|
+
break;
|
|
1077
|
+
case "user":
|
|
1078
|
+
userArgs = argv.slice(0);
|
|
1079
|
+
break;
|
|
1080
|
+
case "eval":
|
|
1081
|
+
userArgs = argv.slice(1);
|
|
1082
|
+
break;
|
|
1083
|
+
default:
|
|
1084
|
+
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
1085
|
+
}
|
|
1086
|
+
if (!this._name && this._scriptPath)
|
|
1087
|
+
this.nameFromFilename(this._scriptPath);
|
|
1088
|
+
this._name = this._name || "program";
|
|
1089
|
+
return userArgs;
|
|
1090
|
+
}
|
|
1091
|
+
parse(argv, parseOptions) {
|
|
1092
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1093
|
+
this._parseCommand([], userArgs);
|
|
1094
|
+
return this;
|
|
1095
|
+
}
|
|
1096
|
+
async parseAsync(argv, parseOptions) {
|
|
1097
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1098
|
+
await this._parseCommand([], userArgs);
|
|
1099
|
+
return this;
|
|
1100
|
+
}
|
|
1101
|
+
_executeSubCommand(subcommand, args) {
|
|
1102
|
+
args = args.slice();
|
|
1103
|
+
let launchWithNode = false;
|
|
1104
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1105
|
+
function findFile(baseDir, baseName) {
|
|
1106
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
1107
|
+
if (fs.existsSync(localBin))
|
|
1108
|
+
return localBin;
|
|
1109
|
+
if (sourceExt.includes(path.extname(baseName)))
|
|
1110
|
+
return;
|
|
1111
|
+
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
1112
|
+
if (foundExt)
|
|
1113
|
+
return `${localBin}${foundExt}`;
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
this._checkForMissingMandatoryOptions();
|
|
1117
|
+
this._checkForConflictingOptions();
|
|
1118
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
1119
|
+
let executableDir = this._executableDir || "";
|
|
1120
|
+
if (this._scriptPath) {
|
|
1121
|
+
let resolvedScriptPath;
|
|
1122
|
+
try {
|
|
1123
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1124
|
+
} catch (err) {
|
|
1125
|
+
resolvedScriptPath = this._scriptPath;
|
|
1126
|
+
}
|
|
1127
|
+
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
1128
|
+
}
|
|
1129
|
+
if (executableDir) {
|
|
1130
|
+
let localFile = findFile(executableDir, executableFile);
|
|
1131
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1132
|
+
const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
1133
|
+
if (legacyName !== this._name) {
|
|
1134
|
+
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
executableFile = localFile || executableFile;
|
|
1138
|
+
}
|
|
1139
|
+
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
1140
|
+
let proc;
|
|
1141
|
+
if (process2.platform !== "win32") {
|
|
1142
|
+
if (launchWithNode) {
|
|
1143
|
+
args.unshift(executableFile);
|
|
1144
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1145
|
+
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
1146
|
+
} else {
|
|
1147
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1148
|
+
}
|
|
1149
|
+
} else {
|
|
1150
|
+
args.unshift(executableFile);
|
|
1151
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1152
|
+
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
1153
|
+
}
|
|
1154
|
+
if (!proc.killed) {
|
|
1155
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
1156
|
+
signals.forEach((signal) => {
|
|
1157
|
+
process2.on(signal, () => {
|
|
1158
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
1159
|
+
proc.kill(signal);
|
|
1160
|
+
}
|
|
1161
|
+
});
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
const exitCallback = this._exitCallback;
|
|
1165
|
+
proc.on("close", (code) => {
|
|
1166
|
+
code = code ?? 1;
|
|
1167
|
+
if (!exitCallback) {
|
|
1168
|
+
process2.exit(code);
|
|
1169
|
+
} else {
|
|
1170
|
+
exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1173
|
+
proc.on("error", (err) => {
|
|
1174
|
+
if (err.code === "ENOENT") {
|
|
1175
|
+
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";
|
|
1176
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
1177
|
+
- if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1178
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1179
|
+
- ${executableDirMessage}`;
|
|
1180
|
+
throw new Error(executableMissing);
|
|
1181
|
+
} else if (err.code === "EACCES") {
|
|
1182
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
1183
|
+
}
|
|
1184
|
+
if (!exitCallback) {
|
|
1185
|
+
process2.exit(1);
|
|
1186
|
+
} else {
|
|
1187
|
+
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
1188
|
+
wrappedError.nestedError = err;
|
|
1189
|
+
exitCallback(wrappedError);
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1192
|
+
this.runningCommand = proc;
|
|
1193
|
+
}
|
|
1194
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
1195
|
+
const subCommand = this._findCommand(commandName);
|
|
1196
|
+
if (!subCommand)
|
|
1197
|
+
this.help({ error: true });
|
|
1198
|
+
let promiseChain;
|
|
1199
|
+
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
|
|
1200
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1201
|
+
if (subCommand._executableHandler) {
|
|
1202
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
1203
|
+
} else {
|
|
1204
|
+
return subCommand._parseCommand(operands, unknown);
|
|
1205
|
+
}
|
|
1206
|
+
});
|
|
1207
|
+
return promiseChain;
|
|
1208
|
+
}
|
|
1209
|
+
_dispatchHelpCommand(subcommandName) {
|
|
1210
|
+
if (!subcommandName) {
|
|
1211
|
+
this.help();
|
|
1212
|
+
}
|
|
1213
|
+
const subCommand = this._findCommand(subcommandName);
|
|
1214
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
1215
|
+
subCommand.help();
|
|
1216
|
+
}
|
|
1217
|
+
return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
|
|
1218
|
+
}
|
|
1219
|
+
_checkNumberOfArguments() {
|
|
1220
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
1221
|
+
if (arg.required && this.args[i] == null) {
|
|
1222
|
+
this.missingArgument(arg.name());
|
|
1223
|
+
}
|
|
1224
|
+
});
|
|
1225
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
1229
|
+
this._excessArguments(this.args);
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
_processArguments() {
|
|
1233
|
+
const myParseArg = (argument, value, previous) => {
|
|
1234
|
+
let parsedValue = value;
|
|
1235
|
+
if (value !== null && argument.parseArg) {
|
|
1236
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
1237
|
+
parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
|
|
1238
|
+
}
|
|
1239
|
+
return parsedValue;
|
|
1240
|
+
};
|
|
1241
|
+
this._checkNumberOfArguments();
|
|
1242
|
+
const processedArgs = [];
|
|
1243
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
1244
|
+
let value = declaredArg.defaultValue;
|
|
1245
|
+
if (declaredArg.variadic) {
|
|
1246
|
+
if (index < this.args.length) {
|
|
1247
|
+
value = this.args.slice(index);
|
|
1248
|
+
if (declaredArg.parseArg) {
|
|
1249
|
+
value = value.reduce((processed, v) => {
|
|
1250
|
+
return myParseArg(declaredArg, v, processed);
|
|
1251
|
+
}, declaredArg.defaultValue);
|
|
1252
|
+
}
|
|
1253
|
+
} else if (value === undefined) {
|
|
1254
|
+
value = [];
|
|
1255
|
+
}
|
|
1256
|
+
} else if (index < this.args.length) {
|
|
1257
|
+
value = this.args[index];
|
|
1258
|
+
if (declaredArg.parseArg) {
|
|
1259
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
processedArgs[index] = value;
|
|
1263
|
+
});
|
|
1264
|
+
this.processedArgs = processedArgs;
|
|
1265
|
+
}
|
|
1266
|
+
_chainOrCall(promise, fn) {
|
|
1267
|
+
if (promise && promise.then && typeof promise.then === "function") {
|
|
1268
|
+
return promise.then(() => fn());
|
|
1269
|
+
}
|
|
1270
|
+
return fn();
|
|
1271
|
+
}
|
|
1272
|
+
_chainOrCallHooks(promise, event) {
|
|
1273
|
+
let result = promise;
|
|
1274
|
+
const hooks = [];
|
|
1275
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
|
|
1276
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
1277
|
+
hooks.push({ hookedCommand, callback });
|
|
1278
|
+
});
|
|
1279
|
+
});
|
|
1280
|
+
if (event === "postAction") {
|
|
1281
|
+
hooks.reverse();
|
|
1282
|
+
}
|
|
1283
|
+
hooks.forEach((hookDetail) => {
|
|
1284
|
+
result = this._chainOrCall(result, () => {
|
|
1285
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
1286
|
+
});
|
|
1287
|
+
});
|
|
1288
|
+
return result;
|
|
1289
|
+
}
|
|
1290
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
1291
|
+
let result = promise;
|
|
1292
|
+
if (this._lifeCycleHooks[event] !== undefined) {
|
|
1293
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
1294
|
+
result = this._chainOrCall(result, () => {
|
|
1295
|
+
return hook(this, subCommand);
|
|
1296
|
+
});
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
return result;
|
|
1300
|
+
}
|
|
1301
|
+
_parseCommand(operands, unknown) {
|
|
1302
|
+
const parsed = this.parseOptions(unknown);
|
|
1303
|
+
this._parseOptionsEnv();
|
|
1304
|
+
this._parseOptionsImplied();
|
|
1305
|
+
operands = operands.concat(parsed.operands);
|
|
1306
|
+
unknown = parsed.unknown;
|
|
1307
|
+
this.args = operands.concat(unknown);
|
|
1308
|
+
if (operands && this._findCommand(operands[0])) {
|
|
1309
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
1310
|
+
}
|
|
1311
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
1312
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
1313
|
+
}
|
|
1314
|
+
if (this._defaultCommandName) {
|
|
1315
|
+
this._outputHelpIfRequested(unknown);
|
|
1316
|
+
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
1317
|
+
}
|
|
1318
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
1319
|
+
this.help({ error: true });
|
|
1320
|
+
}
|
|
1321
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
1322
|
+
this._checkForMissingMandatoryOptions();
|
|
1323
|
+
this._checkForConflictingOptions();
|
|
1324
|
+
const checkForUnknownOptions = () => {
|
|
1325
|
+
if (parsed.unknown.length > 0) {
|
|
1326
|
+
this.unknownOption(parsed.unknown[0]);
|
|
1327
|
+
}
|
|
1328
|
+
};
|
|
1329
|
+
const commandEvent = `command:${this.name()}`;
|
|
1330
|
+
if (this._actionHandler) {
|
|
1331
|
+
checkForUnknownOptions();
|
|
1332
|
+
this._processArguments();
|
|
1333
|
+
let promiseChain;
|
|
1334
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
1335
|
+
promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
|
|
1336
|
+
if (this.parent) {
|
|
1337
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1338
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
1342
|
+
return promiseChain;
|
|
1343
|
+
}
|
|
1344
|
+
if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
1345
|
+
checkForUnknownOptions();
|
|
1346
|
+
this._processArguments();
|
|
1347
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1348
|
+
} else if (operands.length) {
|
|
1349
|
+
if (this._findCommand("*")) {
|
|
1350
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
1351
|
+
}
|
|
1352
|
+
if (this.listenerCount("command:*")) {
|
|
1353
|
+
this.emit("command:*", operands, unknown);
|
|
1354
|
+
} else if (this.commands.length) {
|
|
1355
|
+
this.unknownCommand();
|
|
1356
|
+
} else {
|
|
1357
|
+
checkForUnknownOptions();
|
|
1358
|
+
this._processArguments();
|
|
1359
|
+
}
|
|
1360
|
+
} else if (this.commands.length) {
|
|
1361
|
+
checkForUnknownOptions();
|
|
1362
|
+
this.help({ error: true });
|
|
1363
|
+
} else {
|
|
1364
|
+
checkForUnknownOptions();
|
|
1365
|
+
this._processArguments();
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
_findCommand(name) {
|
|
1369
|
+
if (!name)
|
|
1370
|
+
return;
|
|
1371
|
+
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
1372
|
+
}
|
|
1373
|
+
_findOption(arg) {
|
|
1374
|
+
return this.options.find((option) => option.is(arg));
|
|
1375
|
+
}
|
|
1376
|
+
_checkForMissingMandatoryOptions() {
|
|
1377
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1378
|
+
cmd.options.forEach((anOption) => {
|
|
1379
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
|
|
1380
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
1381
|
+
}
|
|
1382
|
+
});
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
_checkForConflictingLocalOptions() {
|
|
1386
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
1387
|
+
const optionKey = option.attributeName();
|
|
1388
|
+
if (this.getOptionValue(optionKey) === undefined) {
|
|
1389
|
+
return false;
|
|
1390
|
+
}
|
|
1391
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
1392
|
+
});
|
|
1393
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
1394
|
+
optionsWithConflicting.forEach((option) => {
|
|
1395
|
+
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
1396
|
+
if (conflictingAndDefined) {
|
|
1397
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
_checkForConflictingOptions() {
|
|
1402
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1403
|
+
cmd._checkForConflictingLocalOptions();
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
parseOptions(argv) {
|
|
1407
|
+
const operands = [];
|
|
1408
|
+
const unknown = [];
|
|
1409
|
+
let dest = operands;
|
|
1410
|
+
const args = argv.slice();
|
|
1411
|
+
function maybeOption(arg) {
|
|
1412
|
+
return arg.length > 1 && arg[0] === "-";
|
|
1413
|
+
}
|
|
1414
|
+
let activeVariadicOption = null;
|
|
1415
|
+
while (args.length) {
|
|
1416
|
+
const arg = args.shift();
|
|
1417
|
+
if (arg === "--") {
|
|
1418
|
+
if (dest === unknown)
|
|
1419
|
+
dest.push(arg);
|
|
1420
|
+
dest.push(...args);
|
|
1421
|
+
break;
|
|
1422
|
+
}
|
|
1423
|
+
if (activeVariadicOption && !maybeOption(arg)) {
|
|
1424
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1425
|
+
continue;
|
|
1426
|
+
}
|
|
1427
|
+
activeVariadicOption = null;
|
|
1428
|
+
if (maybeOption(arg)) {
|
|
1429
|
+
const option = this._findOption(arg);
|
|
1430
|
+
if (option) {
|
|
1431
|
+
if (option.required) {
|
|
1432
|
+
const value = args.shift();
|
|
1433
|
+
if (value === undefined)
|
|
1434
|
+
this.optionMissingArgument(option);
|
|
1435
|
+
this.emit(`option:${option.name()}`, value);
|
|
1436
|
+
} else if (option.optional) {
|
|
1437
|
+
let value = null;
|
|
1438
|
+
if (args.length > 0 && !maybeOption(args[0])) {
|
|
1439
|
+
value = args.shift();
|
|
1440
|
+
}
|
|
1441
|
+
this.emit(`option:${option.name()}`, value);
|
|
1442
|
+
} else {
|
|
1443
|
+
this.emit(`option:${option.name()}`);
|
|
1444
|
+
}
|
|
1445
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
1446
|
+
continue;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1450
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
1451
|
+
if (option) {
|
|
1452
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
1453
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1454
|
+
} else {
|
|
1455
|
+
this.emit(`option:${option.name()}`);
|
|
1456
|
+
args.unshift(`-${arg.slice(2)}`);
|
|
1457
|
+
}
|
|
1458
|
+
continue;
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
1462
|
+
const index = arg.indexOf("=");
|
|
1463
|
+
const option = this._findOption(arg.slice(0, index));
|
|
1464
|
+
if (option && (option.required || option.optional)) {
|
|
1465
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1466
|
+
continue;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
if (maybeOption(arg)) {
|
|
1470
|
+
dest = unknown;
|
|
1471
|
+
}
|
|
1472
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1473
|
+
if (this._findCommand(arg)) {
|
|
1474
|
+
operands.push(arg);
|
|
1475
|
+
if (args.length > 0)
|
|
1476
|
+
unknown.push(...args);
|
|
1477
|
+
break;
|
|
1478
|
+
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
1479
|
+
operands.push(arg);
|
|
1480
|
+
if (args.length > 0)
|
|
1481
|
+
operands.push(...args);
|
|
1482
|
+
break;
|
|
1483
|
+
} else if (this._defaultCommandName) {
|
|
1484
|
+
unknown.push(arg);
|
|
1485
|
+
if (args.length > 0)
|
|
1486
|
+
unknown.push(...args);
|
|
1487
|
+
break;
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
if (this._passThroughOptions) {
|
|
1491
|
+
dest.push(arg);
|
|
1492
|
+
if (args.length > 0)
|
|
1493
|
+
dest.push(...args);
|
|
1494
|
+
break;
|
|
1495
|
+
}
|
|
1496
|
+
dest.push(arg);
|
|
1497
|
+
}
|
|
1498
|
+
return { operands, unknown };
|
|
1499
|
+
}
|
|
1500
|
+
opts() {
|
|
1501
|
+
if (this._storeOptionsAsProperties) {
|
|
1502
|
+
const result = {};
|
|
1503
|
+
const len = this.options.length;
|
|
1504
|
+
for (let i = 0;i < len; i++) {
|
|
1505
|
+
const key = this.options[i].attributeName();
|
|
1506
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
1507
|
+
}
|
|
1508
|
+
return result;
|
|
1509
|
+
}
|
|
1510
|
+
return this._optionValues;
|
|
1511
|
+
}
|
|
1512
|
+
optsWithGlobals() {
|
|
1513
|
+
return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
1514
|
+
}
|
|
1515
|
+
error(message, errorOptions) {
|
|
1516
|
+
this._outputConfiguration.outputError(`${message}
|
|
1517
|
+
`, this._outputConfiguration.writeErr);
|
|
1518
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
1519
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
1520
|
+
`);
|
|
1521
|
+
} else if (this._showHelpAfterError) {
|
|
1522
|
+
this._outputConfiguration.writeErr(`
|
|
1523
|
+
`);
|
|
1524
|
+
this.outputHelp({ error: true });
|
|
1525
|
+
}
|
|
1526
|
+
const config = errorOptions || {};
|
|
1527
|
+
const exitCode = config.exitCode || 1;
|
|
1528
|
+
const code = config.code || "commander.error";
|
|
1529
|
+
this._exit(exitCode, code, message);
|
|
1530
|
+
}
|
|
1531
|
+
_parseOptionsEnv() {
|
|
1532
|
+
this.options.forEach((option) => {
|
|
1533
|
+
if (option.envVar && option.envVar in process2.env) {
|
|
1534
|
+
const optionKey = option.attributeName();
|
|
1535
|
+
if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
1536
|
+
if (option.required || option.optional) {
|
|
1537
|
+
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
1538
|
+
} else {
|
|
1539
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
_parseOptionsImplied() {
|
|
1546
|
+
const dualHelper = new DualOptions(this.options);
|
|
1547
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
1548
|
+
return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
1549
|
+
};
|
|
1550
|
+
this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
1551
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
1552
|
+
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
1553
|
+
});
|
|
1554
|
+
});
|
|
1555
|
+
}
|
|
1556
|
+
missingArgument(name) {
|
|
1557
|
+
const message = `error: missing required argument '${name}'`;
|
|
1558
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
1559
|
+
}
|
|
1560
|
+
optionMissingArgument(option) {
|
|
1561
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
1562
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
1563
|
+
}
|
|
1564
|
+
missingMandatoryOptionValue(option) {
|
|
1565
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
1566
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
1567
|
+
}
|
|
1568
|
+
_conflictingOption(option, conflictingOption) {
|
|
1569
|
+
const findBestOptionFromValue = (option2) => {
|
|
1570
|
+
const optionKey = option2.attributeName();
|
|
1571
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
1572
|
+
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
1573
|
+
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
1574
|
+
if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
|
|
1575
|
+
return negativeOption;
|
|
1576
|
+
}
|
|
1577
|
+
return positiveOption || option2;
|
|
1578
|
+
};
|
|
1579
|
+
const getErrorMessage = (option2) => {
|
|
1580
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
1581
|
+
const optionKey = bestOption.attributeName();
|
|
1582
|
+
const source = this.getOptionValueSource(optionKey);
|
|
1583
|
+
if (source === "env") {
|
|
1584
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
1585
|
+
}
|
|
1586
|
+
return `option '${bestOption.flags}'`;
|
|
1587
|
+
};
|
|
1588
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
1589
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
1590
|
+
}
|
|
1591
|
+
unknownOption(flag) {
|
|
1592
|
+
if (this._allowUnknownOption)
|
|
1593
|
+
return;
|
|
1594
|
+
let suggestion = "";
|
|
1595
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
1596
|
+
let candidateFlags = [];
|
|
1597
|
+
let command = this;
|
|
1598
|
+
do {
|
|
1599
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
1600
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
1601
|
+
command = command.parent;
|
|
1602
|
+
} while (command && !command._enablePositionalOptions);
|
|
1603
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
1604
|
+
}
|
|
1605
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
1606
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
1607
|
+
}
|
|
1608
|
+
_excessArguments(receivedArgs) {
|
|
1609
|
+
if (this._allowExcessArguments)
|
|
1610
|
+
return;
|
|
1611
|
+
const expected = this.registeredArguments.length;
|
|
1612
|
+
const s = expected === 1 ? "" : "s";
|
|
1613
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
1614
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
1615
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
1616
|
+
}
|
|
1617
|
+
unknownCommand() {
|
|
1618
|
+
const unknownName = this.args[0];
|
|
1619
|
+
let suggestion = "";
|
|
1620
|
+
if (this._showSuggestionAfterError) {
|
|
1621
|
+
const candidateNames = [];
|
|
1622
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
1623
|
+
candidateNames.push(command.name());
|
|
1624
|
+
if (command.alias())
|
|
1625
|
+
candidateNames.push(command.alias());
|
|
1626
|
+
});
|
|
1627
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
1628
|
+
}
|
|
1629
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
1630
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
1631
|
+
}
|
|
1632
|
+
version(str, flags, description) {
|
|
1633
|
+
if (str === undefined)
|
|
1634
|
+
return this._version;
|
|
1635
|
+
this._version = str;
|
|
1636
|
+
flags = flags || "-V, --version";
|
|
1637
|
+
description = description || "output the version number";
|
|
1638
|
+
const versionOption = this.createOption(flags, description);
|
|
1639
|
+
this._versionOptionName = versionOption.attributeName();
|
|
1640
|
+
this._registerOption(versionOption);
|
|
1641
|
+
this.on("option:" + versionOption.name(), () => {
|
|
1642
|
+
this._outputConfiguration.writeOut(`${str}
|
|
1643
|
+
`);
|
|
1644
|
+
this._exit(0, "commander.version", str);
|
|
1645
|
+
});
|
|
1646
|
+
return this;
|
|
1647
|
+
}
|
|
1648
|
+
description(str, argsDescription) {
|
|
1649
|
+
if (str === undefined && argsDescription === undefined)
|
|
1650
|
+
return this._description;
|
|
1651
|
+
this._description = str;
|
|
1652
|
+
if (argsDescription) {
|
|
1653
|
+
this._argsDescription = argsDescription;
|
|
1654
|
+
}
|
|
1655
|
+
return this;
|
|
1656
|
+
}
|
|
1657
|
+
summary(str) {
|
|
1658
|
+
if (str === undefined)
|
|
1659
|
+
return this._summary;
|
|
1660
|
+
this._summary = str;
|
|
1661
|
+
return this;
|
|
1662
|
+
}
|
|
1663
|
+
alias(alias) {
|
|
1664
|
+
if (alias === undefined)
|
|
1665
|
+
return this._aliases[0];
|
|
1666
|
+
let command = this;
|
|
1667
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
1668
|
+
command = this.commands[this.commands.length - 1];
|
|
1669
|
+
}
|
|
1670
|
+
if (alias === command._name)
|
|
1671
|
+
throw new Error("Command alias can't be the same as its name");
|
|
1672
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
1673
|
+
if (matchingCommand) {
|
|
1674
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
1675
|
+
throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
|
|
1676
|
+
}
|
|
1677
|
+
command._aliases.push(alias);
|
|
1678
|
+
return this;
|
|
1679
|
+
}
|
|
1680
|
+
aliases(aliases) {
|
|
1681
|
+
if (aliases === undefined)
|
|
1682
|
+
return this._aliases;
|
|
1683
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
1684
|
+
return this;
|
|
1685
|
+
}
|
|
1686
|
+
usage(str) {
|
|
1687
|
+
if (str === undefined) {
|
|
1688
|
+
if (this._usage)
|
|
1689
|
+
return this._usage;
|
|
1690
|
+
const args = this.registeredArguments.map((arg) => {
|
|
1691
|
+
return humanReadableArgName(arg);
|
|
1692
|
+
});
|
|
1693
|
+
return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
|
|
1694
|
+
}
|
|
1695
|
+
this._usage = str;
|
|
1696
|
+
return this;
|
|
1697
|
+
}
|
|
1698
|
+
name(str) {
|
|
1699
|
+
if (str === undefined)
|
|
1700
|
+
return this._name;
|
|
1701
|
+
this._name = str;
|
|
1702
|
+
return this;
|
|
1703
|
+
}
|
|
1704
|
+
nameFromFilename(filename) {
|
|
1705
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
1706
|
+
return this;
|
|
1707
|
+
}
|
|
1708
|
+
executableDir(path2) {
|
|
1709
|
+
if (path2 === undefined)
|
|
1710
|
+
return this._executableDir;
|
|
1711
|
+
this._executableDir = path2;
|
|
1712
|
+
return this;
|
|
1713
|
+
}
|
|
1714
|
+
helpInformation(contextOptions) {
|
|
1715
|
+
const helper = this.createHelp();
|
|
1716
|
+
if (helper.helpWidth === undefined) {
|
|
1717
|
+
helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
|
|
1718
|
+
}
|
|
1719
|
+
return helper.formatHelp(this, helper);
|
|
1720
|
+
}
|
|
1721
|
+
_getHelpContext(contextOptions) {
|
|
1722
|
+
contextOptions = contextOptions || {};
|
|
1723
|
+
const context = { error: !!contextOptions.error };
|
|
1724
|
+
let write;
|
|
1725
|
+
if (context.error) {
|
|
1726
|
+
write = (arg) => this._outputConfiguration.writeErr(arg);
|
|
1727
|
+
} else {
|
|
1728
|
+
write = (arg) => this._outputConfiguration.writeOut(arg);
|
|
1729
|
+
}
|
|
1730
|
+
context.write = contextOptions.write || write;
|
|
1731
|
+
context.command = this;
|
|
1732
|
+
return context;
|
|
1733
|
+
}
|
|
1734
|
+
outputHelp(contextOptions) {
|
|
1735
|
+
let deprecatedCallback;
|
|
1736
|
+
if (typeof contextOptions === "function") {
|
|
1737
|
+
deprecatedCallback = contextOptions;
|
|
1738
|
+
contextOptions = undefined;
|
|
1739
|
+
}
|
|
1740
|
+
const context = this._getHelpContext(contextOptions);
|
|
1741
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", context));
|
|
1742
|
+
this.emit("beforeHelp", context);
|
|
1743
|
+
let helpInformation = this.helpInformation(context);
|
|
1744
|
+
if (deprecatedCallback) {
|
|
1745
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
1746
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
1747
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
context.write(helpInformation);
|
|
1751
|
+
if (this._getHelpOption()?.long) {
|
|
1752
|
+
this.emit(this._getHelpOption().long);
|
|
1753
|
+
}
|
|
1754
|
+
this.emit("afterHelp", context);
|
|
1755
|
+
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", context));
|
|
1756
|
+
}
|
|
1757
|
+
helpOption(flags, description) {
|
|
1758
|
+
if (typeof flags === "boolean") {
|
|
1759
|
+
if (flags) {
|
|
1760
|
+
this._helpOption = this._helpOption ?? undefined;
|
|
1761
|
+
} else {
|
|
1762
|
+
this._helpOption = null;
|
|
1763
|
+
}
|
|
1764
|
+
return this;
|
|
1765
|
+
}
|
|
1766
|
+
flags = flags ?? "-h, --help";
|
|
1767
|
+
description = description ?? "display help for command";
|
|
1768
|
+
this._helpOption = this.createOption(flags, description);
|
|
1769
|
+
return this;
|
|
1770
|
+
}
|
|
1771
|
+
_getHelpOption() {
|
|
1772
|
+
if (this._helpOption === undefined) {
|
|
1773
|
+
this.helpOption(undefined, undefined);
|
|
1774
|
+
}
|
|
1775
|
+
return this._helpOption;
|
|
1776
|
+
}
|
|
1777
|
+
addHelpOption(option) {
|
|
1778
|
+
this._helpOption = option;
|
|
1779
|
+
return this;
|
|
1780
|
+
}
|
|
1781
|
+
help(contextOptions) {
|
|
1782
|
+
this.outputHelp(contextOptions);
|
|
1783
|
+
let exitCode = process2.exitCode || 0;
|
|
1784
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
1785
|
+
exitCode = 1;
|
|
1786
|
+
}
|
|
1787
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
1788
|
+
}
|
|
1789
|
+
addHelpText(position, text) {
|
|
1790
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
1791
|
+
if (!allowedValues.includes(position)) {
|
|
1792
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
1793
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1794
|
+
}
|
|
1795
|
+
const helpEvent = `${position}Help`;
|
|
1796
|
+
this.on(helpEvent, (context) => {
|
|
1797
|
+
let helpStr;
|
|
1798
|
+
if (typeof text === "function") {
|
|
1799
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
1800
|
+
} else {
|
|
1801
|
+
helpStr = text;
|
|
1802
|
+
}
|
|
1803
|
+
if (helpStr) {
|
|
1804
|
+
context.write(`${helpStr}
|
|
1805
|
+
`);
|
|
1806
|
+
}
|
|
1807
|
+
});
|
|
1808
|
+
return this;
|
|
1809
|
+
}
|
|
1810
|
+
_outputHelpIfRequested(args) {
|
|
1811
|
+
const helpOption = this._getHelpOption();
|
|
1812
|
+
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
1813
|
+
if (helpRequested) {
|
|
1814
|
+
this.outputHelp();
|
|
1815
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
function incrementNodeInspectorPort(args) {
|
|
1820
|
+
return args.map((arg) => {
|
|
1821
|
+
if (!arg.startsWith("--inspect")) {
|
|
1822
|
+
return arg;
|
|
1823
|
+
}
|
|
1824
|
+
let debugOption;
|
|
1825
|
+
let debugHost = "127.0.0.1";
|
|
1826
|
+
let debugPort = "9229";
|
|
1827
|
+
let match;
|
|
1828
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
1829
|
+
debugOption = match[1];
|
|
1830
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
1831
|
+
debugOption = match[1];
|
|
1832
|
+
if (/^\d+$/.test(match[3])) {
|
|
1833
|
+
debugPort = match[3];
|
|
1834
|
+
} else {
|
|
1835
|
+
debugHost = match[3];
|
|
1836
|
+
}
|
|
1837
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
1838
|
+
debugOption = match[1];
|
|
1839
|
+
debugHost = match[3];
|
|
1840
|
+
debugPort = match[4];
|
|
1841
|
+
}
|
|
1842
|
+
if (debugOption && debugPort !== "0") {
|
|
1843
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
1844
|
+
}
|
|
1845
|
+
return arg;
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
exports.Command = Command;
|
|
1849
|
+
});
|
|
1850
|
+
|
|
1851
|
+
// node_modules/commander/index.js
|
|
1852
|
+
var require_commander = __commonJS((exports) => {
|
|
1853
|
+
var { Argument } = require_argument();
|
|
1854
|
+
var { Command } = require_command();
|
|
1855
|
+
var { CommanderError, InvalidArgumentError } = require_error();
|
|
1856
|
+
var { Help } = require_help();
|
|
1857
|
+
var { Option } = require_option();
|
|
1858
|
+
exports.program = new Command;
|
|
1859
|
+
exports.createCommand = (name) => new Command(name);
|
|
1860
|
+
exports.createOption = (flags, description) => new Option(flags, description);
|
|
1861
|
+
exports.createArgument = (name, description) => new Argument(name, description);
|
|
1862
|
+
exports.Command = Command;
|
|
1863
|
+
exports.Option = Option;
|
|
1864
|
+
exports.Argument = Argument;
|
|
1865
|
+
exports.Help = Help;
|
|
1866
|
+
exports.CommanderError = CommanderError;
|
|
1867
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
1868
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
1869
|
+
});
|
|
1870
|
+
|
|
1871
|
+
// node_modules/commander/esm.mjs
|
|
1872
|
+
var import__ = __toESM(require_commander(), 1);
|
|
1873
|
+
var {
|
|
1874
|
+
program,
|
|
1875
|
+
createCommand,
|
|
1876
|
+
createArgument,
|
|
1877
|
+
createOption,
|
|
1878
|
+
CommanderError,
|
|
1879
|
+
InvalidArgumentError,
|
|
1880
|
+
InvalidOptionArgumentError,
|
|
1881
|
+
Command,
|
|
1882
|
+
Argument,
|
|
1883
|
+
Option,
|
|
1884
|
+
Help
|
|
1885
|
+
} = import__.default;
|
|
1886
|
+
|
|
1887
|
+
// bin/resource-builder.ts
|
|
1888
|
+
import { promises as fs } from "fs";
|
|
1889
|
+
import { join, extname, basename } from "path";
|
|
1890
|
+
|
|
1891
|
+
// node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
1892
|
+
var ANSI_BACKGROUND_OFFSET = 10;
|
|
1893
|
+
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
1894
|
+
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
1895
|
+
var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
|
|
1896
|
+
var styles = {
|
|
1897
|
+
modifier: {
|
|
1898
|
+
reset: [0, 0],
|
|
1899
|
+
bold: [1, 22],
|
|
1900
|
+
dim: [2, 22],
|
|
1901
|
+
italic: [3, 23],
|
|
1902
|
+
underline: [4, 24],
|
|
1903
|
+
overline: [53, 55],
|
|
1904
|
+
inverse: [7, 27],
|
|
1905
|
+
hidden: [8, 28],
|
|
1906
|
+
strikethrough: [9, 29]
|
|
1907
|
+
},
|
|
1908
|
+
color: {
|
|
1909
|
+
black: [30, 39],
|
|
1910
|
+
red: [31, 39],
|
|
1911
|
+
green: [32, 39],
|
|
1912
|
+
yellow: [33, 39],
|
|
1913
|
+
blue: [34, 39],
|
|
1914
|
+
magenta: [35, 39],
|
|
1915
|
+
cyan: [36, 39],
|
|
1916
|
+
white: [37, 39],
|
|
1917
|
+
blackBright: [90, 39],
|
|
1918
|
+
gray: [90, 39],
|
|
1919
|
+
grey: [90, 39],
|
|
1920
|
+
redBright: [91, 39],
|
|
1921
|
+
greenBright: [92, 39],
|
|
1922
|
+
yellowBright: [93, 39],
|
|
1923
|
+
blueBright: [94, 39],
|
|
1924
|
+
magentaBright: [95, 39],
|
|
1925
|
+
cyanBright: [96, 39],
|
|
1926
|
+
whiteBright: [97, 39]
|
|
1927
|
+
},
|
|
1928
|
+
bgColor: {
|
|
1929
|
+
bgBlack: [40, 49],
|
|
1930
|
+
bgRed: [41, 49],
|
|
1931
|
+
bgGreen: [42, 49],
|
|
1932
|
+
bgYellow: [43, 49],
|
|
1933
|
+
bgBlue: [44, 49],
|
|
1934
|
+
bgMagenta: [45, 49],
|
|
1935
|
+
bgCyan: [46, 49],
|
|
1936
|
+
bgWhite: [47, 49],
|
|
1937
|
+
bgBlackBright: [100, 49],
|
|
1938
|
+
bgGray: [100, 49],
|
|
1939
|
+
bgGrey: [100, 49],
|
|
1940
|
+
bgRedBright: [101, 49],
|
|
1941
|
+
bgGreenBright: [102, 49],
|
|
1942
|
+
bgYellowBright: [103, 49],
|
|
1943
|
+
bgBlueBright: [104, 49],
|
|
1944
|
+
bgMagentaBright: [105, 49],
|
|
1945
|
+
bgCyanBright: [106, 49],
|
|
1946
|
+
bgWhiteBright: [107, 49]
|
|
1947
|
+
}
|
|
1948
|
+
};
|
|
1949
|
+
var modifierNames = Object.keys(styles.modifier);
|
|
1950
|
+
var foregroundColorNames = Object.keys(styles.color);
|
|
1951
|
+
var backgroundColorNames = Object.keys(styles.bgColor);
|
|
1952
|
+
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
1953
|
+
function assembleStyles() {
|
|
1954
|
+
const codes = new Map;
|
|
1955
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
1956
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
1957
|
+
styles[styleName] = {
|
|
1958
|
+
open: `\x1B[${style[0]}m`,
|
|
1959
|
+
close: `\x1B[${style[1]}m`
|
|
1960
|
+
};
|
|
1961
|
+
group[styleName] = styles[styleName];
|
|
1962
|
+
codes.set(style[0], style[1]);
|
|
1963
|
+
}
|
|
1964
|
+
Object.defineProperty(styles, groupName, {
|
|
1965
|
+
value: group,
|
|
1966
|
+
enumerable: false
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
Object.defineProperty(styles, "codes", {
|
|
1970
|
+
value: codes,
|
|
1971
|
+
enumerable: false
|
|
1972
|
+
});
|
|
1973
|
+
styles.color.close = "\x1B[39m";
|
|
1974
|
+
styles.bgColor.close = "\x1B[49m";
|
|
1975
|
+
styles.color.ansi = wrapAnsi16();
|
|
1976
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
1977
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
1978
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
1979
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
1980
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
1981
|
+
Object.defineProperties(styles, {
|
|
1982
|
+
rgbToAnsi256: {
|
|
1983
|
+
value(red, green, blue) {
|
|
1984
|
+
if (red === green && green === blue) {
|
|
1985
|
+
if (red < 8) {
|
|
1986
|
+
return 16;
|
|
1987
|
+
}
|
|
1988
|
+
if (red > 248) {
|
|
1989
|
+
return 231;
|
|
1990
|
+
}
|
|
1991
|
+
return Math.round((red - 8) / 247 * 24) + 232;
|
|
1992
|
+
}
|
|
1993
|
+
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
1994
|
+
},
|
|
1995
|
+
enumerable: false
|
|
1996
|
+
},
|
|
1997
|
+
hexToRgb: {
|
|
1998
|
+
value(hex) {
|
|
1999
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
2000
|
+
if (!matches) {
|
|
2001
|
+
return [0, 0, 0];
|
|
2002
|
+
}
|
|
2003
|
+
let [colorString] = matches;
|
|
2004
|
+
if (colorString.length === 3) {
|
|
2005
|
+
colorString = [...colorString].map((character) => character + character).join("");
|
|
2006
|
+
}
|
|
2007
|
+
const integer = Number.parseInt(colorString, 16);
|
|
2008
|
+
return [
|
|
2009
|
+
integer >> 16 & 255,
|
|
2010
|
+
integer >> 8 & 255,
|
|
2011
|
+
integer & 255
|
|
2012
|
+
];
|
|
2013
|
+
},
|
|
2014
|
+
enumerable: false
|
|
2015
|
+
},
|
|
2016
|
+
hexToAnsi256: {
|
|
2017
|
+
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
2018
|
+
enumerable: false
|
|
2019
|
+
},
|
|
2020
|
+
ansi256ToAnsi: {
|
|
2021
|
+
value(code) {
|
|
2022
|
+
if (code < 8) {
|
|
2023
|
+
return 30 + code;
|
|
2024
|
+
}
|
|
2025
|
+
if (code < 16) {
|
|
2026
|
+
return 90 + (code - 8);
|
|
2027
|
+
}
|
|
2028
|
+
let red;
|
|
2029
|
+
let green;
|
|
2030
|
+
let blue;
|
|
2031
|
+
if (code >= 232) {
|
|
2032
|
+
red = ((code - 232) * 10 + 8) / 255;
|
|
2033
|
+
green = red;
|
|
2034
|
+
blue = red;
|
|
2035
|
+
} else {
|
|
2036
|
+
code -= 16;
|
|
2037
|
+
const remainder = code % 36;
|
|
2038
|
+
red = Math.floor(code / 36) / 5;
|
|
2039
|
+
green = Math.floor(remainder / 6) / 5;
|
|
2040
|
+
blue = remainder % 6 / 5;
|
|
2041
|
+
}
|
|
2042
|
+
const value = Math.max(red, green, blue) * 2;
|
|
2043
|
+
if (value === 0) {
|
|
2044
|
+
return 30;
|
|
2045
|
+
}
|
|
2046
|
+
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
2047
|
+
if (value === 2) {
|
|
2048
|
+
result += 60;
|
|
2049
|
+
}
|
|
2050
|
+
return result;
|
|
2051
|
+
},
|
|
2052
|
+
enumerable: false
|
|
2053
|
+
},
|
|
2054
|
+
rgbToAnsi: {
|
|
2055
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
2056
|
+
enumerable: false
|
|
2057
|
+
},
|
|
2058
|
+
hexToAnsi: {
|
|
2059
|
+
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
2060
|
+
enumerable: false
|
|
2061
|
+
}
|
|
2062
|
+
});
|
|
2063
|
+
return styles;
|
|
2064
|
+
}
|
|
2065
|
+
var ansiStyles = assembleStyles();
|
|
2066
|
+
var ansi_styles_default = ansiStyles;
|
|
2067
|
+
|
|
2068
|
+
// node_modules/chalk/source/vendor/supports-color/index.js
|
|
2069
|
+
import process2 from "node:process";
|
|
2070
|
+
import os from "node:os";
|
|
2071
|
+
import tty from "node:tty";
|
|
2072
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2.argv) {
|
|
2073
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
2074
|
+
const position = argv.indexOf(prefix + flag);
|
|
2075
|
+
const terminatorPosition = argv.indexOf("--");
|
|
2076
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
2077
|
+
}
|
|
2078
|
+
var { env } = process2;
|
|
2079
|
+
var flagForceColor;
|
|
2080
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
2081
|
+
flagForceColor = 0;
|
|
2082
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
2083
|
+
flagForceColor = 1;
|
|
2084
|
+
}
|
|
2085
|
+
function envForceColor() {
|
|
2086
|
+
if ("FORCE_COLOR" in env) {
|
|
2087
|
+
if (env.FORCE_COLOR === "true") {
|
|
2088
|
+
return 1;
|
|
2089
|
+
}
|
|
2090
|
+
if (env.FORCE_COLOR === "false") {
|
|
2091
|
+
return 0;
|
|
2092
|
+
}
|
|
2093
|
+
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
function translateLevel(level) {
|
|
2097
|
+
if (level === 0) {
|
|
2098
|
+
return false;
|
|
2099
|
+
}
|
|
2100
|
+
return {
|
|
2101
|
+
level,
|
|
2102
|
+
hasBasic: true,
|
|
2103
|
+
has256: level >= 2,
|
|
2104
|
+
has16m: level >= 3
|
|
2105
|
+
};
|
|
2106
|
+
}
|
|
2107
|
+
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
2108
|
+
const noFlagForceColor = envForceColor();
|
|
2109
|
+
if (noFlagForceColor !== undefined) {
|
|
2110
|
+
flagForceColor = noFlagForceColor;
|
|
2111
|
+
}
|
|
2112
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
2113
|
+
if (forceColor === 0) {
|
|
2114
|
+
return 0;
|
|
2115
|
+
}
|
|
2116
|
+
if (sniffFlags) {
|
|
2117
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
2118
|
+
return 3;
|
|
2119
|
+
}
|
|
2120
|
+
if (hasFlag("color=256")) {
|
|
2121
|
+
return 2;
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
2125
|
+
return 1;
|
|
2126
|
+
}
|
|
2127
|
+
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
2128
|
+
return 0;
|
|
2129
|
+
}
|
|
2130
|
+
const min = forceColor || 0;
|
|
2131
|
+
if (env.TERM === "dumb") {
|
|
2132
|
+
return min;
|
|
2133
|
+
}
|
|
2134
|
+
if (process2.platform === "win32") {
|
|
2135
|
+
const osRelease = os.release().split(".");
|
|
2136
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
2137
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
2138
|
+
}
|
|
2139
|
+
return 1;
|
|
2140
|
+
}
|
|
2141
|
+
if ("CI" in env) {
|
|
2142
|
+
if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => (key in env))) {
|
|
2143
|
+
return 3;
|
|
2144
|
+
}
|
|
2145
|
+
if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => (sign in env)) || env.CI_NAME === "codeship") {
|
|
2146
|
+
return 1;
|
|
2147
|
+
}
|
|
2148
|
+
return min;
|
|
2149
|
+
}
|
|
2150
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
2151
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
2152
|
+
}
|
|
2153
|
+
if (env.COLORTERM === "truecolor") {
|
|
2154
|
+
return 3;
|
|
2155
|
+
}
|
|
2156
|
+
if (env.TERM === "xterm-kitty") {
|
|
2157
|
+
return 3;
|
|
2158
|
+
}
|
|
2159
|
+
if ("TERM_PROGRAM" in env) {
|
|
2160
|
+
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
2161
|
+
switch (env.TERM_PROGRAM) {
|
|
2162
|
+
case "iTerm.app": {
|
|
2163
|
+
return version >= 3 ? 3 : 2;
|
|
2164
|
+
}
|
|
2165
|
+
case "Apple_Terminal": {
|
|
2166
|
+
return 2;
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
2171
|
+
return 2;
|
|
2172
|
+
}
|
|
2173
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
2174
|
+
return 1;
|
|
2175
|
+
}
|
|
2176
|
+
if ("COLORTERM" in env) {
|
|
2177
|
+
return 1;
|
|
2178
|
+
}
|
|
2179
|
+
return min;
|
|
2180
|
+
}
|
|
2181
|
+
function createSupportsColor(stream, options = {}) {
|
|
2182
|
+
const level = _supportsColor(stream, {
|
|
2183
|
+
streamIsTTY: stream && stream.isTTY,
|
|
2184
|
+
...options
|
|
2185
|
+
});
|
|
2186
|
+
return translateLevel(level);
|
|
2187
|
+
}
|
|
2188
|
+
var supportsColor = {
|
|
2189
|
+
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
|
2190
|
+
stderr: createSupportsColor({ isTTY: tty.isatty(2) })
|
|
2191
|
+
};
|
|
2192
|
+
var supports_color_default = supportsColor;
|
|
2193
|
+
|
|
2194
|
+
// node_modules/chalk/source/utilities.js
|
|
2195
|
+
function stringReplaceAll(string, substring, replacer) {
|
|
2196
|
+
let index = string.indexOf(substring);
|
|
2197
|
+
if (index === -1) {
|
|
2198
|
+
return string;
|
|
2199
|
+
}
|
|
2200
|
+
const substringLength = substring.length;
|
|
2201
|
+
let endIndex = 0;
|
|
2202
|
+
let returnValue = "";
|
|
2203
|
+
do {
|
|
2204
|
+
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
2205
|
+
endIndex = index + substringLength;
|
|
2206
|
+
index = string.indexOf(substring, endIndex);
|
|
2207
|
+
} while (index !== -1);
|
|
2208
|
+
returnValue += string.slice(endIndex);
|
|
2209
|
+
return returnValue;
|
|
2210
|
+
}
|
|
2211
|
+
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
2212
|
+
let endIndex = 0;
|
|
2213
|
+
let returnValue = "";
|
|
2214
|
+
do {
|
|
2215
|
+
const gotCR = string[index - 1] === "\r";
|
|
2216
|
+
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? `\r
|
|
2217
|
+
` : `
|
|
2218
|
+
`) + postfix;
|
|
2219
|
+
endIndex = index + 1;
|
|
2220
|
+
index = string.indexOf(`
|
|
2221
|
+
`, endIndex);
|
|
2222
|
+
} while (index !== -1);
|
|
2223
|
+
returnValue += string.slice(endIndex);
|
|
2224
|
+
return returnValue;
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
// node_modules/chalk/source/index.js
|
|
2228
|
+
var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
|
|
2229
|
+
var GENERATOR = Symbol("GENERATOR");
|
|
2230
|
+
var STYLER = Symbol("STYLER");
|
|
2231
|
+
var IS_EMPTY = Symbol("IS_EMPTY");
|
|
2232
|
+
var levelMapping = [
|
|
2233
|
+
"ansi",
|
|
2234
|
+
"ansi",
|
|
2235
|
+
"ansi256",
|
|
2236
|
+
"ansi16m"
|
|
2237
|
+
];
|
|
2238
|
+
var styles2 = Object.create(null);
|
|
2239
|
+
var applyOptions = (object, options = {}) => {
|
|
2240
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
2241
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
2242
|
+
}
|
|
2243
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
2244
|
+
object.level = options.level === undefined ? colorLevel : options.level;
|
|
2245
|
+
};
|
|
2246
|
+
var chalkFactory = (options) => {
|
|
2247
|
+
const chalk = (...strings) => strings.join(" ");
|
|
2248
|
+
applyOptions(chalk, options);
|
|
2249
|
+
Object.setPrototypeOf(chalk, createChalk.prototype);
|
|
2250
|
+
return chalk;
|
|
2251
|
+
};
|
|
2252
|
+
function createChalk(options) {
|
|
2253
|
+
return chalkFactory(options);
|
|
2254
|
+
}
|
|
2255
|
+
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
2256
|
+
for (const [styleName, style] of Object.entries(ansi_styles_default)) {
|
|
2257
|
+
styles2[styleName] = {
|
|
2258
|
+
get() {
|
|
2259
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
2260
|
+
Object.defineProperty(this, styleName, { value: builder });
|
|
2261
|
+
return builder;
|
|
2262
|
+
}
|
|
2263
|
+
};
|
|
2264
|
+
}
|
|
2265
|
+
styles2.visible = {
|
|
2266
|
+
get() {
|
|
2267
|
+
const builder = createBuilder(this, this[STYLER], true);
|
|
2268
|
+
Object.defineProperty(this, "visible", { value: builder });
|
|
2269
|
+
return builder;
|
|
2270
|
+
}
|
|
2271
|
+
};
|
|
2272
|
+
var getModelAnsi = (model, level, type, ...arguments_) => {
|
|
2273
|
+
if (model === "rgb") {
|
|
2274
|
+
if (level === "ansi16m") {
|
|
2275
|
+
return ansi_styles_default[type].ansi16m(...arguments_);
|
|
2276
|
+
}
|
|
2277
|
+
if (level === "ansi256") {
|
|
2278
|
+
return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
|
|
2279
|
+
}
|
|
2280
|
+
return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
|
|
2281
|
+
}
|
|
2282
|
+
if (model === "hex") {
|
|
2283
|
+
return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
|
|
2284
|
+
}
|
|
2285
|
+
return ansi_styles_default[type][model](...arguments_);
|
|
2286
|
+
};
|
|
2287
|
+
var usedModels = ["rgb", "hex", "ansi256"];
|
|
2288
|
+
for (const model of usedModels) {
|
|
2289
|
+
styles2[model] = {
|
|
2290
|
+
get() {
|
|
2291
|
+
const { level } = this;
|
|
2292
|
+
return function(...arguments_) {
|
|
2293
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
|
2294
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
2295
|
+
};
|
|
2296
|
+
}
|
|
2297
|
+
};
|
|
2298
|
+
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
2299
|
+
styles2[bgModel] = {
|
|
2300
|
+
get() {
|
|
2301
|
+
const { level } = this;
|
|
2302
|
+
return function(...arguments_) {
|
|
2303
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
|
|
2304
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
2305
|
+
};
|
|
2306
|
+
}
|
|
2307
|
+
};
|
|
2308
|
+
}
|
|
2309
|
+
var proto = Object.defineProperties(() => {
|
|
2310
|
+
}, {
|
|
2311
|
+
...styles2,
|
|
2312
|
+
level: {
|
|
2313
|
+
enumerable: true,
|
|
2314
|
+
get() {
|
|
2315
|
+
return this[GENERATOR].level;
|
|
2316
|
+
},
|
|
2317
|
+
set(level) {
|
|
2318
|
+
this[GENERATOR].level = level;
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
});
|
|
2322
|
+
var createStyler = (open, close, parent) => {
|
|
2323
|
+
let openAll;
|
|
2324
|
+
let closeAll;
|
|
2325
|
+
if (parent === undefined) {
|
|
2326
|
+
openAll = open;
|
|
2327
|
+
closeAll = close;
|
|
2328
|
+
} else {
|
|
2329
|
+
openAll = parent.openAll + open;
|
|
2330
|
+
closeAll = close + parent.closeAll;
|
|
2331
|
+
}
|
|
2332
|
+
return {
|
|
2333
|
+
open,
|
|
2334
|
+
close,
|
|
2335
|
+
openAll,
|
|
2336
|
+
closeAll,
|
|
2337
|
+
parent
|
|
2338
|
+
};
|
|
2339
|
+
};
|
|
2340
|
+
var createBuilder = (self, _styler, _isEmpty) => {
|
|
2341
|
+
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
2342
|
+
Object.setPrototypeOf(builder, proto);
|
|
2343
|
+
builder[GENERATOR] = self;
|
|
2344
|
+
builder[STYLER] = _styler;
|
|
2345
|
+
builder[IS_EMPTY] = _isEmpty;
|
|
2346
|
+
return builder;
|
|
2347
|
+
};
|
|
2348
|
+
var applyStyle = (self, string) => {
|
|
2349
|
+
if (self.level <= 0 || !string) {
|
|
2350
|
+
return self[IS_EMPTY] ? "" : string;
|
|
2351
|
+
}
|
|
2352
|
+
let styler = self[STYLER];
|
|
2353
|
+
if (styler === undefined) {
|
|
2354
|
+
return string;
|
|
2355
|
+
}
|
|
2356
|
+
const { openAll, closeAll } = styler;
|
|
2357
|
+
if (string.includes("\x1B")) {
|
|
2358
|
+
while (styler !== undefined) {
|
|
2359
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
2360
|
+
styler = styler.parent;
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
const lfIndex = string.indexOf(`
|
|
2364
|
+
`);
|
|
2365
|
+
if (lfIndex !== -1) {
|
|
2366
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
2367
|
+
}
|
|
2368
|
+
return openAll + string + closeAll;
|
|
2369
|
+
};
|
|
2370
|
+
Object.defineProperties(createChalk.prototype, styles2);
|
|
2371
|
+
var chalk = createChalk();
|
|
2372
|
+
var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
2373
|
+
var source_default = chalk;
|
|
2374
|
+
|
|
2375
|
+
// node_modules/uuid/dist/esm/stringify.js
|
|
2376
|
+
var byteToHex = [];
|
|
2377
|
+
for (let i = 0;i < 256; ++i) {
|
|
2378
|
+
byteToHex.push((i + 256).toString(16).slice(1));
|
|
2379
|
+
}
|
|
2380
|
+
function unsafeStringify(arr, offset = 0) {
|
|
2381
|
+
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
// node_modules/uuid/dist/esm/rng.js
|
|
2385
|
+
import { randomFillSync } from "crypto";
|
|
2386
|
+
var rnds8Pool = new Uint8Array(256);
|
|
2387
|
+
var poolPtr = rnds8Pool.length;
|
|
2388
|
+
function rng() {
|
|
2389
|
+
if (poolPtr > rnds8Pool.length - 16) {
|
|
2390
|
+
randomFillSync(rnds8Pool);
|
|
2391
|
+
poolPtr = 0;
|
|
2392
|
+
}
|
|
2393
|
+
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
// node_modules/uuid/dist/esm/native.js
|
|
2397
|
+
import { randomUUID } from "crypto";
|
|
2398
|
+
var native_default = { randomUUID };
|
|
2399
|
+
|
|
2400
|
+
// node_modules/uuid/dist/esm/v4.js
|
|
2401
|
+
function v4(options, buf, offset) {
|
|
2402
|
+
if (native_default.randomUUID && !buf && !options) {
|
|
2403
|
+
return native_default.randomUUID();
|
|
2404
|
+
}
|
|
2405
|
+
options = options || {};
|
|
2406
|
+
const rnds = options.random || (options.rng || rng)();
|
|
2407
|
+
rnds[6] = rnds[6] & 15 | 64;
|
|
2408
|
+
rnds[8] = rnds[8] & 63 | 128;
|
|
2409
|
+
if (buf) {
|
|
2410
|
+
offset = offset || 0;
|
|
2411
|
+
for (let i = 0;i < 16; ++i) {
|
|
2412
|
+
buf[offset + i] = rnds[i];
|
|
2413
|
+
}
|
|
2414
|
+
return buf;
|
|
2415
|
+
}
|
|
2416
|
+
return unsafeStringify(rnds);
|
|
2417
|
+
}
|
|
2418
|
+
var v4_default = v4;
|
|
2419
|
+
// bin/resource-builder.ts
|
|
2420
|
+
var log = console.log;
|
|
2421
|
+
var info = source_default.hex("#ffa552");
|
|
2422
|
+
var error = source_default.hex("#c42847");
|
|
2423
|
+
var alert = source_default.hex("#EFF2C0");
|
|
2424
|
+
var RESOURCE_TYPES = ["interface", "icon", "map", "sound", "macros"];
|
|
2425
|
+
var VALID_EXTENSIONS = ["vyint", "vyi", "vym", "vymac", "mp3", "aac", "wav", "m4a", "ogg", "flac"];
|
|
2426
|
+
var resourceJSON = initializeResourceJSON();
|
|
2427
|
+
var isVerbose = false;
|
|
2428
|
+
var ignoringSound = false;
|
|
2429
|
+
var resourceInDirectory = "";
|
|
2430
|
+
var resourceOutDirectory = "";
|
|
2431
|
+
var resourcesToProcess = [];
|
|
2432
|
+
function initializeResourceJSON() {
|
|
2433
|
+
return RESOURCE_TYPES.reduce((acc, type) => {
|
|
2434
|
+
acc[type] = [];
|
|
2435
|
+
return acc;
|
|
2436
|
+
}, {});
|
|
2437
|
+
}
|
|
2438
|
+
function prepareFileForProcessing(filePath) {
|
|
2439
|
+
const extension = extname(filePath).slice(1);
|
|
2440
|
+
const fileName = filePath.replace(/^.*[\\\/]/, "");
|
|
2441
|
+
const resourceIdentifier = `${v4_default()}.${extension}`;
|
|
2442
|
+
const type = getResourceType(extension);
|
|
2443
|
+
if (!type)
|
|
2444
|
+
return;
|
|
2445
|
+
if (type === "sound" && ignoringSound) {
|
|
2446
|
+
logVerbose(`[Ignored File] ${filePath} (ignoreSound flag enabled)`);
|
|
2447
|
+
return;
|
|
2448
|
+
}
|
|
2449
|
+
resourcesToProcess.push({ filePath, type });
|
|
2450
|
+
resourceJSON[type].push({ resourceIdentifier, fileName });
|
|
2451
|
+
}
|
|
2452
|
+
function getResourceType(pExtension) {
|
|
2453
|
+
switch (pExtension) {
|
|
2454
|
+
case "vyint":
|
|
2455
|
+
return "interface";
|
|
2456
|
+
case "vyi":
|
|
2457
|
+
return "icon";
|
|
2458
|
+
case "vym":
|
|
2459
|
+
return "map";
|
|
2460
|
+
case "vymac":
|
|
2461
|
+
return "macros";
|
|
2462
|
+
case "mp3":
|
|
2463
|
+
case "aac":
|
|
2464
|
+
case "wav":
|
|
2465
|
+
case "m4a":
|
|
2466
|
+
case "ogg":
|
|
2467
|
+
case "flac":
|
|
2468
|
+
return "sound";
|
|
2469
|
+
default:
|
|
2470
|
+
return null;
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
async function processDirectory(pDirectoryPath) {
|
|
2474
|
+
try {
|
|
2475
|
+
const contents = await fs.readdir(pDirectoryPath);
|
|
2476
|
+
for (const item of contents) {
|
|
2477
|
+
const itemPath = join(pDirectoryPath, item);
|
|
2478
|
+
const stats = await fs.stat(itemPath);
|
|
2479
|
+
if (stats.isDirectory()) {
|
|
2480
|
+
await processDirectory(itemPath);
|
|
2481
|
+
} else if (isValidExtension(extname(itemPath).slice(1))) {
|
|
2482
|
+
prepareFileForProcessing(itemPath);
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
} catch (pError) {
|
|
2486
|
+
logError(`[Error] Processing directory: ${pError}`);
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
function isValidExtension(pExtension) {
|
|
2490
|
+
return VALID_EXTENSIONS.includes(pExtension);
|
|
2491
|
+
}
|
|
2492
|
+
async function processAllFiles() {
|
|
2493
|
+
try {
|
|
2494
|
+
const copyOperations = resourcesToProcess.map(({ filePath, type }) => {
|
|
2495
|
+
const fileName = basename(filePath);
|
|
2496
|
+
const resource = resourceJSON[type].find((res) => res.fileName === fileName);
|
|
2497
|
+
if (!resource) {
|
|
2498
|
+
throw new Error(`Resource not found for file: ${fileName}`);
|
|
2499
|
+
}
|
|
2500
|
+
const destination = join(resourceOutDirectory, "resources", type);
|
|
2501
|
+
return copyFile(filePath, destination, resource.resourceIdentifier);
|
|
2502
|
+
});
|
|
2503
|
+
await Promise.all(copyOperations);
|
|
2504
|
+
logVerbose(`[Kit CLI] All resources have been processed.`);
|
|
2505
|
+
await saveResourceJSON();
|
|
2506
|
+
} catch (pError) {
|
|
2507
|
+
logError(`[Error] Processing files in batch: ${pError.message}`);
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
async function copyFile(pSource, pDestinationDir, pNewName) {
|
|
2511
|
+
try {
|
|
2512
|
+
await fs.mkdir(pDestinationDir, { recursive: true });
|
|
2513
|
+
await fs.copyFile(pSource, join(pDestinationDir, pNewName));
|
|
2514
|
+
} catch (pError) {
|
|
2515
|
+
logError(`[Error] Copying file ${pSource}: ${pError}`);
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2518
|
+
async function saveResourceJSON() {
|
|
2519
|
+
const filePath = join(resourceOutDirectory, "resource.json");
|
|
2520
|
+
try {
|
|
2521
|
+
await fs.writeFile(filePath, JSON.stringify(resourceJSON, null, 2));
|
|
2522
|
+
} catch (pError) {
|
|
2523
|
+
logError(`[Error] Saving resource JSON: ${pError}`);
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
async function processResources({ inDirectory, outDirectory, verbose, ignoreSound }) {
|
|
2527
|
+
resourceInDirectory = inDirectory;
|
|
2528
|
+
resourceOutDirectory = outDirectory;
|
|
2529
|
+
isVerbose = verbose;
|
|
2530
|
+
ignoringSound = ignoreSound;
|
|
2531
|
+
resourceJSON = initializeResourceJSON();
|
|
2532
|
+
if (!resourceInDirectory || !resourceOutDirectory) {
|
|
2533
|
+
logError("[Error] Input and output directories must be specified");
|
|
2534
|
+
return;
|
|
2535
|
+
}
|
|
2536
|
+
await processDirectory(resourceInDirectory);
|
|
2537
|
+
if (resourcesToProcess.length > 0) {
|
|
2538
|
+
await processAllFiles();
|
|
2539
|
+
} else {
|
|
2540
|
+
logAlert("No resources found!");
|
|
2541
|
+
await saveResourceJSON();
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
function logVerbose(pMessage) {
|
|
2545
|
+
if (isVerbose)
|
|
2546
|
+
log(info(pMessage));
|
|
2547
|
+
}
|
|
2548
|
+
function logError(pMessage) {
|
|
2549
|
+
log(error(pMessage));
|
|
2550
|
+
}
|
|
2551
|
+
function logAlert(pMessage) {
|
|
2552
|
+
log(alert(pMessage));
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2555
|
+
// bin/index.ts
|
|
2556
|
+
class KitCLI {
|
|
2557
|
+
static async processResources(pProcessOptions) {
|
|
2558
|
+
await processResources(pProcessOptions);
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
// package.json
|
|
2562
|
+
var package_default = {
|
|
2563
|
+
name: "@evitcastudio/kit",
|
|
2564
|
+
version: "1.0.0",
|
|
2565
|
+
author: "doubleactii 56242467+doubleactii@users.noreply.github.com (https://evitcastudio.com)",
|
|
2566
|
+
main: "./lib/src/index.js",
|
|
2567
|
+
types: "./lib/src/index.d.ts",
|
|
2568
|
+
module: "lib/src/index.js",
|
|
2569
|
+
type: "module",
|
|
2570
|
+
description: "A single-player/multiplayer framework for the Vylocity Game Engine.",
|
|
2571
|
+
"cli-description": "CLI for handling building resources and running | testing | publishing games.",
|
|
2572
|
+
keywords: [
|
|
2573
|
+
"framework",
|
|
2574
|
+
"multiplayer",
|
|
2575
|
+
"single-player",
|
|
2576
|
+
"toolkit",
|
|
2577
|
+
"kit"
|
|
2578
|
+
],
|
|
2579
|
+
repository: {
|
|
2580
|
+
type: "git",
|
|
2581
|
+
url: "git+https://github.com/EvitcaStudio/Kit.git"
|
|
2582
|
+
},
|
|
2583
|
+
bugs: {
|
|
2584
|
+
url: "https://github.com/EvitcaStudio/Kit/issues"
|
|
2585
|
+
},
|
|
2586
|
+
homepage: "https://github.com/EvitcaStudio/Kit",
|
|
2587
|
+
license: "MIT",
|
|
2588
|
+
scripts: {
|
|
2589
|
+
prepublishOnly: "bun run build-all",
|
|
2590
|
+
test: "bun test ./tests",
|
|
2591
|
+
"build-types": "bun tsc",
|
|
2592
|
+
"build-dist": "bun bun-build.ts",
|
|
2593
|
+
"build-docs": "bun typedoc ./src/index.ts ./src/types/shared-types.ts",
|
|
2594
|
+
"build-all": "bun run build-types && bun run build-dist && bun run build-docs"
|
|
2595
|
+
},
|
|
2596
|
+
bin: {
|
|
2597
|
+
kit: "./lib/bundle/cli/cli.js"
|
|
2598
|
+
},
|
|
2599
|
+
devDependencies: {
|
|
2600
|
+
"@types/bun": "latest",
|
|
2601
|
+
"@types/node": "^22.10.2",
|
|
2602
|
+
bun: "^1.1.42",
|
|
2603
|
+
typedoc: "^0.27.5",
|
|
2604
|
+
typescript: "^5.7.2"
|
|
2605
|
+
},
|
|
2606
|
+
dependencies: {
|
|
2607
|
+
chalk: "^5.4.0",
|
|
2608
|
+
commander: "^12.1.0",
|
|
2609
|
+
uuid: "^11.0.3"
|
|
2610
|
+
},
|
|
2611
|
+
directories: {
|
|
2612
|
+
test: "tests"
|
|
2613
|
+
}
|
|
2614
|
+
};
|
|
2615
|
+
|
|
2616
|
+
// bin/cli.ts
|
|
2617
|
+
var program2 = new Command;
|
|
2618
|
+
program2.version(`${package_default.version}`).description(`Kit - ${package_default["cli-description"]}`);
|
|
2619
|
+
program2.option("-i, --in <path>", "Input directory").option("-o, --out <path>", "Output directory").option("-is, --ignore-sound", "Ignore sound files", false).option("-v, --verbose", "Enable verbose mode", false);
|
|
2620
|
+
program2.helpInformation = () => {
|
|
2621
|
+
return `
|
|
2622
|
+
Kit CLI - ${package_default["cli-description"]}
|
|
2623
|
+
Version: ${package_default.version}
|
|
2624
|
+
|
|
2625
|
+
Usage: kit <command> [options]
|
|
2626
|
+
|
|
2627
|
+
Commands:
|
|
2628
|
+
build Build resources from the specified directory
|
|
2629
|
+
--help Display this help message
|
|
2630
|
+
|
|
2631
|
+
Options:
|
|
2632
|
+
-i, --in <path> Input directory (required)
|
|
2633
|
+
-o, --out <path> Output directory (required)
|
|
2634
|
+
-is, --ignore-sound Ignore sound files (optional)
|
|
2635
|
+
-v, --verbose Enable verbose mode for debugging
|
|
2636
|
+
|
|
2637
|
+
Examples:
|
|
2638
|
+
kit build --in ./src --out ./dist --verbose
|
|
2639
|
+
kit build --in ./resources --out ./dist --ignore-sound
|
|
2640
|
+
`;
|
|
2641
|
+
};
|
|
2642
|
+
if (!process.argv.slice(2).length) {
|
|
2643
|
+
program2.help();
|
|
2644
|
+
}
|
|
2645
|
+
program2.command("build").description("Build resources from the specified directory").action(() => {
|
|
2646
|
+
const flags = program2.opts();
|
|
2647
|
+
if (!flags.in || !flags.out) {
|
|
2648
|
+
console.error("Error: --in and --out are required flags for the build command.");
|
|
2649
|
+
process.exit(1);
|
|
2650
|
+
}
|
|
2651
|
+
const ProcessOptions = {
|
|
2652
|
+
inDirectory: flags.in,
|
|
2653
|
+
outDirectory: flags.out,
|
|
2654
|
+
ignoreSound: flags.ignoreSound || false,
|
|
2655
|
+
verbose: flags.verbose || false
|
|
2656
|
+
};
|
|
2657
|
+
KitCLI.processResources(ProcessOptions);
|
|
2658
|
+
});
|
|
2659
|
+
program2.parse(process.argv);
|