create-awesome-node-app 0.4.23 → 0.4.26
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/README.md +36 -6
- package/dist/index.cjs +684 -2458
- package/dist/index.js +684 -2458
- package/package.json +9 -6
package/dist/index.js
CHANGED
|
@@ -31,1874 +31,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
31
31
|
mod
|
|
32
32
|
));
|
|
33
33
|
|
|
34
|
-
//
|
|
35
|
-
var require_commander = __commonJS({
|
|
36
|
-
"../../node_modules/commander/index.js"(exports, module) {
|
|
37
|
-
var EventEmitter = __require("events").EventEmitter;
|
|
38
|
-
var childProcess = __require("child_process");
|
|
39
|
-
var path = __require("path");
|
|
40
|
-
var fs = __require("fs");
|
|
41
|
-
var Help = class {
|
|
42
|
-
constructor() {
|
|
43
|
-
this.helpWidth = void 0;
|
|
44
|
-
this.sortSubcommands = false;
|
|
45
|
-
this.sortOptions = false;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
49
|
-
*
|
|
50
|
-
* @param {Command} cmd
|
|
51
|
-
* @returns {Command[]}
|
|
52
|
-
*/
|
|
53
|
-
visibleCommands(cmd) {
|
|
54
|
-
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
55
|
-
if (cmd._hasImplicitHelpCommand()) {
|
|
56
|
-
const args = cmd._helpCommandnameAndArgs.split(/ +/);
|
|
57
|
-
const helpCommand = cmd.createCommand(args.shift()).helpOption(false);
|
|
58
|
-
helpCommand.description(cmd._helpCommandDescription);
|
|
59
|
-
helpCommand._parseExpectedArgs(args);
|
|
60
|
-
visibleCommands.push(helpCommand);
|
|
61
|
-
}
|
|
62
|
-
if (this.sortSubcommands) {
|
|
63
|
-
visibleCommands.sort((a, b) => {
|
|
64
|
-
return a.name().localeCompare(b.name());
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return visibleCommands;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
71
|
-
*
|
|
72
|
-
* @param {Command} cmd
|
|
73
|
-
* @returns {Option[]}
|
|
74
|
-
*/
|
|
75
|
-
visibleOptions(cmd) {
|
|
76
|
-
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
77
|
-
const showShortHelpFlag = cmd._hasHelpOption && cmd._helpShortFlag && !cmd._findOption(cmd._helpShortFlag);
|
|
78
|
-
const showLongHelpFlag = cmd._hasHelpOption && !cmd._findOption(cmd._helpLongFlag);
|
|
79
|
-
if (showShortHelpFlag || showLongHelpFlag) {
|
|
80
|
-
let helpOption;
|
|
81
|
-
if (!showShortHelpFlag) {
|
|
82
|
-
helpOption = cmd.createOption(cmd._helpLongFlag, cmd._helpDescription);
|
|
83
|
-
} else if (!showLongHelpFlag) {
|
|
84
|
-
helpOption = cmd.createOption(cmd._helpShortFlag, cmd._helpDescription);
|
|
85
|
-
} else {
|
|
86
|
-
helpOption = cmd.createOption(cmd._helpFlags, cmd._helpDescription);
|
|
87
|
-
}
|
|
88
|
-
visibleOptions.push(helpOption);
|
|
89
|
-
}
|
|
90
|
-
if (this.sortOptions) {
|
|
91
|
-
const getSortKey = (option) => {
|
|
92
|
-
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
93
|
-
};
|
|
94
|
-
visibleOptions.sort((a, b) => {
|
|
95
|
-
return getSortKey(a).localeCompare(getSortKey(b));
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return visibleOptions;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Get an array of the arguments which have descriptions.
|
|
102
|
-
*
|
|
103
|
-
* @param {Command} cmd
|
|
104
|
-
* @returns {{ term: string, description:string }[]}
|
|
105
|
-
*/
|
|
106
|
-
visibleArguments(cmd) {
|
|
107
|
-
if (cmd._argsDescription && cmd._args.length) {
|
|
108
|
-
return cmd._args.map((argument) => {
|
|
109
|
-
return { term: argument.name, description: cmd._argsDescription[argument.name] || "" };
|
|
110
|
-
}, 0);
|
|
111
|
-
}
|
|
112
|
-
return [];
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Get the command term to show in the list of subcommands.
|
|
116
|
-
*
|
|
117
|
-
* @param {Command} cmd
|
|
118
|
-
* @returns {string}
|
|
119
|
-
*/
|
|
120
|
-
subcommandTerm(cmd) {
|
|
121
|
-
const args = cmd._args.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
122
|
-
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + // simplistic check for non-help option
|
|
123
|
-
(args ? " " + args : "");
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Get the option term to show in the list of options.
|
|
127
|
-
*
|
|
128
|
-
* @param {Option} option
|
|
129
|
-
* @returns {string}
|
|
130
|
-
*/
|
|
131
|
-
optionTerm(option) {
|
|
132
|
-
return option.flags;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Get the longest command term length.
|
|
136
|
-
*
|
|
137
|
-
* @param {Command} cmd
|
|
138
|
-
* @param {Help} helper
|
|
139
|
-
* @returns {number}
|
|
140
|
-
*/
|
|
141
|
-
longestSubcommandTermLength(cmd, helper) {
|
|
142
|
-
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
143
|
-
return Math.max(max, helper.subcommandTerm(command).length);
|
|
144
|
-
}, 0);
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Get the longest option term length.
|
|
148
|
-
*
|
|
149
|
-
* @param {Command} cmd
|
|
150
|
-
* @param {Help} helper
|
|
151
|
-
* @returns {number}
|
|
152
|
-
*/
|
|
153
|
-
longestOptionTermLength(cmd, helper) {
|
|
154
|
-
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
155
|
-
return Math.max(max, helper.optionTerm(option).length);
|
|
156
|
-
}, 0);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Get the longest argument term length.
|
|
160
|
-
*
|
|
161
|
-
* @param {Command} cmd
|
|
162
|
-
* @param {Help} helper
|
|
163
|
-
* @returns {number}
|
|
164
|
-
*/
|
|
165
|
-
longestArgumentTermLength(cmd, helper) {
|
|
166
|
-
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
167
|
-
return Math.max(max, argument.term.length);
|
|
168
|
-
}, 0);
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Get the command usage to be displayed at the top of the built-in help.
|
|
172
|
-
*
|
|
173
|
-
* @param {Command} cmd
|
|
174
|
-
* @returns {string}
|
|
175
|
-
*/
|
|
176
|
-
commandUsage(cmd) {
|
|
177
|
-
let cmdName = cmd._name;
|
|
178
|
-
if (cmd._aliases[0]) {
|
|
179
|
-
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
180
|
-
}
|
|
181
|
-
let parentCmdNames = "";
|
|
182
|
-
for (let parentCmd = cmd.parent; parentCmd; parentCmd = parentCmd.parent) {
|
|
183
|
-
parentCmdNames = parentCmd.name() + " " + parentCmdNames;
|
|
184
|
-
}
|
|
185
|
-
return parentCmdNames + cmdName + " " + cmd.usage();
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Get the description for the command.
|
|
189
|
-
*
|
|
190
|
-
* @param {Command} cmd
|
|
191
|
-
* @returns {string}
|
|
192
|
-
*/
|
|
193
|
-
commandDescription(cmd) {
|
|
194
|
-
return cmd.description();
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Get the command description to show in the list of subcommands.
|
|
198
|
-
*
|
|
199
|
-
* @param {Command} cmd
|
|
200
|
-
* @returns {string}
|
|
201
|
-
*/
|
|
202
|
-
subcommandDescription(cmd) {
|
|
203
|
-
return cmd.description();
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Get the option description to show in the list of options.
|
|
207
|
-
*
|
|
208
|
-
* @param {Option} option
|
|
209
|
-
* @return {string}
|
|
210
|
-
*/
|
|
211
|
-
optionDescription(option) {
|
|
212
|
-
if (option.negate) {
|
|
213
|
-
return option.description;
|
|
214
|
-
}
|
|
215
|
-
const extraInfo = [];
|
|
216
|
-
if (option.argChoices) {
|
|
217
|
-
extraInfo.push(
|
|
218
|
-
// use stringify to match the display of the default value
|
|
219
|
-
`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
if (option.defaultValue !== void 0) {
|
|
223
|
-
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
224
|
-
}
|
|
225
|
-
if (extraInfo.length > 0) {
|
|
226
|
-
return `${option.description} (${extraInfo.join(", ")})`;
|
|
227
|
-
}
|
|
228
|
-
return option.description;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Generate the built-in help text.
|
|
232
|
-
*
|
|
233
|
-
* @param {Command} cmd
|
|
234
|
-
* @param {Help} helper
|
|
235
|
-
* @returns {string}
|
|
236
|
-
*/
|
|
237
|
-
formatHelp(cmd, helper) {
|
|
238
|
-
const termWidth = helper.padWidth(cmd, helper);
|
|
239
|
-
const helpWidth = helper.helpWidth || 80;
|
|
240
|
-
const itemIndentWidth = 2;
|
|
241
|
-
const itemSeparatorWidth = 2;
|
|
242
|
-
function formatItem(term, description) {
|
|
243
|
-
if (description) {
|
|
244
|
-
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
245
|
-
return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
|
|
246
|
-
}
|
|
247
|
-
return term;
|
|
248
|
-
}
|
|
249
|
-
;
|
|
250
|
-
function formatList(textArray) {
|
|
251
|
-
return textArray.join("\n").replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
252
|
-
}
|
|
253
|
-
let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
|
|
254
|
-
const commandDescription = helper.commandDescription(cmd);
|
|
255
|
-
if (commandDescription.length > 0) {
|
|
256
|
-
output = output.concat([commandDescription, ""]);
|
|
257
|
-
}
|
|
258
|
-
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
259
|
-
return formatItem(argument.term, argument.description);
|
|
260
|
-
});
|
|
261
|
-
if (argumentList.length > 0) {
|
|
262
|
-
output = output.concat(["Arguments:", formatList(argumentList), ""]);
|
|
263
|
-
}
|
|
264
|
-
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
265
|
-
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
266
|
-
});
|
|
267
|
-
if (optionList.length > 0) {
|
|
268
|
-
output = output.concat(["Options:", formatList(optionList), ""]);
|
|
269
|
-
}
|
|
270
|
-
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
271
|
-
return formatItem(helper.subcommandTerm(cmd2), helper.subcommandDescription(cmd2));
|
|
272
|
-
});
|
|
273
|
-
if (commandList.length > 0) {
|
|
274
|
-
output = output.concat(["Commands:", formatList(commandList), ""]);
|
|
275
|
-
}
|
|
276
|
-
return output.join("\n");
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Calculate the pad width from the maximum term length.
|
|
280
|
-
*
|
|
281
|
-
* @param {Command} cmd
|
|
282
|
-
* @param {Help} helper
|
|
283
|
-
* @returns {number}
|
|
284
|
-
*/
|
|
285
|
-
padWidth(cmd, helper) {
|
|
286
|
-
return Math.max(
|
|
287
|
-
helper.longestOptionTermLength(cmd, helper),
|
|
288
|
-
helper.longestSubcommandTermLength(cmd, helper),
|
|
289
|
-
helper.longestArgumentTermLength(cmd, helper)
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Wrap the given string to width characters per line, with lines after the first indented.
|
|
294
|
-
* Do not wrap if insufficient room for wrapping (minColumnWidth), or string is manually formatted.
|
|
295
|
-
*
|
|
296
|
-
* @param {string} str
|
|
297
|
-
* @param {number} width
|
|
298
|
-
* @param {number} indent
|
|
299
|
-
* @param {number} [minColumnWidth=40]
|
|
300
|
-
* @return {string}
|
|
301
|
-
*
|
|
302
|
-
*/
|
|
303
|
-
wrap(str, width, indent, minColumnWidth = 40) {
|
|
304
|
-
if (str.match(/[\n]\s+/))
|
|
305
|
-
return str;
|
|
306
|
-
const columnWidth = width - indent;
|
|
307
|
-
if (columnWidth < minColumnWidth)
|
|
308
|
-
return str;
|
|
309
|
-
const leadingStr = str.substr(0, indent);
|
|
310
|
-
const columnText = str.substr(indent);
|
|
311
|
-
const indentString = " ".repeat(indent);
|
|
312
|
-
const regex = new RegExp(".{1," + (columnWidth - 1) + "}([\\s\u200B]|$)|[^\\s\u200B]+?([\\s\u200B]|$)", "g");
|
|
313
|
-
const lines = columnText.match(regex) || [];
|
|
314
|
-
return leadingStr + lines.map((line, i) => {
|
|
315
|
-
if (line.slice(-1) === "\n") {
|
|
316
|
-
line = line.slice(0, line.length - 1);
|
|
317
|
-
}
|
|
318
|
-
return (i > 0 ? indentString : "") + line.trimRight();
|
|
319
|
-
}).join("\n");
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
var Option = class {
|
|
323
|
-
/**
|
|
324
|
-
* Initialize a new `Option` with the given `flags` and `description`.
|
|
325
|
-
*
|
|
326
|
-
* @param {string} flags
|
|
327
|
-
* @param {string} [description]
|
|
328
|
-
*/
|
|
329
|
-
constructor(flags, description) {
|
|
330
|
-
this.flags = flags;
|
|
331
|
-
this.description = description || "";
|
|
332
|
-
this.required = flags.includes("<");
|
|
333
|
-
this.optional = flags.includes("[");
|
|
334
|
-
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
335
|
-
this.mandatory = false;
|
|
336
|
-
const optionFlags = _parseOptionFlags(flags);
|
|
337
|
-
this.short = optionFlags.shortFlag;
|
|
338
|
-
this.long = optionFlags.longFlag;
|
|
339
|
-
this.negate = false;
|
|
340
|
-
if (this.long) {
|
|
341
|
-
this.negate = this.long.startsWith("--no-");
|
|
342
|
-
}
|
|
343
|
-
this.defaultValue = void 0;
|
|
344
|
-
this.defaultValueDescription = void 0;
|
|
345
|
-
this.parseArg = void 0;
|
|
346
|
-
this.hidden = false;
|
|
347
|
-
this.argChoices = void 0;
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
351
|
-
*
|
|
352
|
-
* @param {any} value
|
|
353
|
-
* @param {string} [description]
|
|
354
|
-
* @return {Option}
|
|
355
|
-
*/
|
|
356
|
-
default(value, description) {
|
|
357
|
-
this.defaultValue = value;
|
|
358
|
-
this.defaultValueDescription = description;
|
|
359
|
-
return this;
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Set the custom handler for processing CLI option arguments into option values.
|
|
363
|
-
*
|
|
364
|
-
* @param {Function} [fn]
|
|
365
|
-
* @return {Option}
|
|
366
|
-
*/
|
|
367
|
-
argParser(fn) {
|
|
368
|
-
this.parseArg = fn;
|
|
369
|
-
return this;
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Whether the option is mandatory and must have a value after parsing.
|
|
373
|
-
*
|
|
374
|
-
* @param {boolean} [mandatory=true]
|
|
375
|
-
* @return {Option}
|
|
376
|
-
*/
|
|
377
|
-
makeOptionMandatory(mandatory = true) {
|
|
378
|
-
this.mandatory = !!mandatory;
|
|
379
|
-
return this;
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* Hide option in help.
|
|
383
|
-
*
|
|
384
|
-
* @param {boolean} [hide=true]
|
|
385
|
-
* @return {Option}
|
|
386
|
-
*/
|
|
387
|
-
hideHelp(hide = true) {
|
|
388
|
-
this.hidden = !!hide;
|
|
389
|
-
return this;
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* @api private
|
|
393
|
-
*/
|
|
394
|
-
_concatValue(value, previous) {
|
|
395
|
-
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
396
|
-
return [value];
|
|
397
|
-
}
|
|
398
|
-
return previous.concat(value);
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Only allow option value to be one of choices.
|
|
402
|
-
*
|
|
403
|
-
* @param {string[]} values
|
|
404
|
-
* @return {Option}
|
|
405
|
-
*/
|
|
406
|
-
choices(values) {
|
|
407
|
-
this.argChoices = values;
|
|
408
|
-
this.parseArg = (arg, previous) => {
|
|
409
|
-
if (!values.includes(arg)) {
|
|
410
|
-
throw new InvalidOptionArgumentError(`Allowed choices are ${values.join(", ")}.`);
|
|
411
|
-
}
|
|
412
|
-
if (this.variadic) {
|
|
413
|
-
return this._concatValue(arg, previous);
|
|
414
|
-
}
|
|
415
|
-
return arg;
|
|
416
|
-
};
|
|
417
|
-
return this;
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Return option name.
|
|
421
|
-
*
|
|
422
|
-
* @return {string}
|
|
423
|
-
*/
|
|
424
|
-
name() {
|
|
425
|
-
if (this.long) {
|
|
426
|
-
return this.long.replace(/^--/, "");
|
|
427
|
-
}
|
|
428
|
-
return this.short.replace(/^-/, "");
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* Return option name, in a camelcase format that can be used
|
|
432
|
-
* as a object attribute key.
|
|
433
|
-
*
|
|
434
|
-
* @return {string}
|
|
435
|
-
* @api private
|
|
436
|
-
*/
|
|
437
|
-
attributeName() {
|
|
438
|
-
return camelcase(this.name().replace(/^no-/, ""));
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Check if `arg` matches the short or long flag.
|
|
442
|
-
*
|
|
443
|
-
* @param {string} arg
|
|
444
|
-
* @return {boolean}
|
|
445
|
-
* @api private
|
|
446
|
-
*/
|
|
447
|
-
is(arg) {
|
|
448
|
-
return this.short === arg || this.long === arg;
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
var CommanderError = class extends Error {
|
|
452
|
-
/**
|
|
453
|
-
* Constructs the CommanderError class
|
|
454
|
-
* @param {number} exitCode suggested exit code which could be used with process.exit
|
|
455
|
-
* @param {string} code an id string representing the error
|
|
456
|
-
* @param {string} message human-readable description of the error
|
|
457
|
-
* @constructor
|
|
458
|
-
*/
|
|
459
|
-
constructor(exitCode, code, message) {
|
|
460
|
-
super(message);
|
|
461
|
-
Error.captureStackTrace(this, this.constructor);
|
|
462
|
-
this.name = this.constructor.name;
|
|
463
|
-
this.code = code;
|
|
464
|
-
this.exitCode = exitCode;
|
|
465
|
-
this.nestedError = void 0;
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
var InvalidOptionArgumentError = class extends CommanderError {
|
|
469
|
-
/**
|
|
470
|
-
* Constructs the InvalidOptionArgumentError class
|
|
471
|
-
* @param {string} [message] explanation of why argument is invalid
|
|
472
|
-
* @constructor
|
|
473
|
-
*/
|
|
474
|
-
constructor(message) {
|
|
475
|
-
super(1, "commander.invalidOptionArgument", message);
|
|
476
|
-
Error.captureStackTrace(this, this.constructor);
|
|
477
|
-
this.name = this.constructor.name;
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
var Command = class extends EventEmitter {
|
|
481
|
-
/**
|
|
482
|
-
* Initialize a new `Command`.
|
|
483
|
-
*
|
|
484
|
-
* @param {string} [name]
|
|
485
|
-
*/
|
|
486
|
-
constructor(name) {
|
|
487
|
-
super();
|
|
488
|
-
this.commands = [];
|
|
489
|
-
this.options = [];
|
|
490
|
-
this.parent = null;
|
|
491
|
-
this._allowUnknownOption = false;
|
|
492
|
-
this._allowExcessArguments = true;
|
|
493
|
-
this._args = [];
|
|
494
|
-
this.rawArgs = null;
|
|
495
|
-
this._scriptPath = null;
|
|
496
|
-
this._name = name || "";
|
|
497
|
-
this._optionValues = {};
|
|
498
|
-
this._storeOptionsAsProperties = false;
|
|
499
|
-
this._actionResults = [];
|
|
500
|
-
this._actionHandler = null;
|
|
501
|
-
this._executableHandler = false;
|
|
502
|
-
this._executableFile = null;
|
|
503
|
-
this._defaultCommandName = null;
|
|
504
|
-
this._exitCallback = null;
|
|
505
|
-
this._aliases = [];
|
|
506
|
-
this._combineFlagAndOptionalValue = true;
|
|
507
|
-
this._description = "";
|
|
508
|
-
this._argsDescription = void 0;
|
|
509
|
-
this._enablePositionalOptions = false;
|
|
510
|
-
this._passThroughOptions = false;
|
|
511
|
-
this._outputConfiguration = {
|
|
512
|
-
writeOut: (str) => process.stdout.write(str),
|
|
513
|
-
writeErr: (str) => process.stderr.write(str),
|
|
514
|
-
getOutHelpWidth: () => process.stdout.isTTY ? process.stdout.columns : void 0,
|
|
515
|
-
getErrHelpWidth: () => process.stderr.isTTY ? process.stderr.columns : void 0,
|
|
516
|
-
outputError: (str, write) => write(str)
|
|
517
|
-
};
|
|
518
|
-
this._hidden = false;
|
|
519
|
-
this._hasHelpOption = true;
|
|
520
|
-
this._helpFlags = "-h, --help";
|
|
521
|
-
this._helpDescription = "display help for command";
|
|
522
|
-
this._helpShortFlag = "-h";
|
|
523
|
-
this._helpLongFlag = "--help";
|
|
524
|
-
this._addImplicitHelpCommand = void 0;
|
|
525
|
-
this._helpCommandName = "help";
|
|
526
|
-
this._helpCommandnameAndArgs = "help [command]";
|
|
527
|
-
this._helpCommandDescription = "display help for command";
|
|
528
|
-
this._helpConfiguration = {};
|
|
529
|
-
}
|
|
530
|
-
/**
|
|
531
|
-
* Define a command.
|
|
532
|
-
*
|
|
533
|
-
* There are two styles of command: pay attention to where to put the description.
|
|
534
|
-
*
|
|
535
|
-
* Examples:
|
|
536
|
-
*
|
|
537
|
-
* // Command implemented using action handler (description is supplied separately to `.command`)
|
|
538
|
-
* program
|
|
539
|
-
* .command('clone <source> [destination]')
|
|
540
|
-
* .description('clone a repository into a newly created directory')
|
|
541
|
-
* .action((source, destination) => {
|
|
542
|
-
* console.log('clone command called');
|
|
543
|
-
* });
|
|
544
|
-
*
|
|
545
|
-
* // Command implemented using separate executable file (description is second parameter to `.command`)
|
|
546
|
-
* program
|
|
547
|
-
* .command('start <service>', 'start named service')
|
|
548
|
-
* .command('stop [service]', 'stop named service, or all if no name supplied');
|
|
549
|
-
*
|
|
550
|
-
* @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
|
|
551
|
-
* @param {Object|string} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
|
|
552
|
-
* @param {Object} [execOpts] - configuration options (for executable)
|
|
553
|
-
* @return {Command} returns new command for action handler, or `this` for executable command
|
|
554
|
-
*/
|
|
555
|
-
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
556
|
-
let desc = actionOptsOrExecDesc;
|
|
557
|
-
let opts = execOpts;
|
|
558
|
-
if (typeof desc === "object" && desc !== null) {
|
|
559
|
-
opts = desc;
|
|
560
|
-
desc = null;
|
|
561
|
-
}
|
|
562
|
-
opts = opts || {};
|
|
563
|
-
const args = nameAndArgs.split(/ +/);
|
|
564
|
-
const cmd = this.createCommand(args.shift());
|
|
565
|
-
if (desc) {
|
|
566
|
-
cmd.description(desc);
|
|
567
|
-
cmd._executableHandler = true;
|
|
568
|
-
}
|
|
569
|
-
if (opts.isDefault)
|
|
570
|
-
this._defaultCommandName = cmd._name;
|
|
571
|
-
cmd._outputConfiguration = this._outputConfiguration;
|
|
572
|
-
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
573
|
-
cmd._hasHelpOption = this._hasHelpOption;
|
|
574
|
-
cmd._helpFlags = this._helpFlags;
|
|
575
|
-
cmd._helpDescription = this._helpDescription;
|
|
576
|
-
cmd._helpShortFlag = this._helpShortFlag;
|
|
577
|
-
cmd._helpLongFlag = this._helpLongFlag;
|
|
578
|
-
cmd._helpCommandName = this._helpCommandName;
|
|
579
|
-
cmd._helpCommandnameAndArgs = this._helpCommandnameAndArgs;
|
|
580
|
-
cmd._helpCommandDescription = this._helpCommandDescription;
|
|
581
|
-
cmd._helpConfiguration = this._helpConfiguration;
|
|
582
|
-
cmd._exitCallback = this._exitCallback;
|
|
583
|
-
cmd._storeOptionsAsProperties = this._storeOptionsAsProperties;
|
|
584
|
-
cmd._combineFlagAndOptionalValue = this._combineFlagAndOptionalValue;
|
|
585
|
-
cmd._allowExcessArguments = this._allowExcessArguments;
|
|
586
|
-
cmd._enablePositionalOptions = this._enablePositionalOptions;
|
|
587
|
-
cmd._executableFile = opts.executableFile || null;
|
|
588
|
-
this.commands.push(cmd);
|
|
589
|
-
cmd._parseExpectedArgs(args);
|
|
590
|
-
cmd.parent = this;
|
|
591
|
-
if (desc)
|
|
592
|
-
return this;
|
|
593
|
-
return cmd;
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* Factory routine to create a new unattached command.
|
|
597
|
-
*
|
|
598
|
-
* See .command() for creating an attached subcommand, which uses this routine to
|
|
599
|
-
* create the command. You can override createCommand to customise subcommands.
|
|
600
|
-
*
|
|
601
|
-
* @param {string} [name]
|
|
602
|
-
* @return {Command} new command
|
|
603
|
-
*/
|
|
604
|
-
createCommand(name) {
|
|
605
|
-
return new Command(name);
|
|
606
|
-
}
|
|
607
|
-
/**
|
|
608
|
-
* You can customise the help with a subclass of Help by overriding createHelp,
|
|
609
|
-
* or by overriding Help properties using configureHelp().
|
|
610
|
-
*
|
|
611
|
-
* @return {Help}
|
|
612
|
-
*/
|
|
613
|
-
createHelp() {
|
|
614
|
-
return Object.assign(new Help(), this.configureHelp());
|
|
615
|
-
}
|
|
616
|
-
/**
|
|
617
|
-
* You can customise the help by overriding Help properties using configureHelp(),
|
|
618
|
-
* or with a subclass of Help by overriding createHelp().
|
|
619
|
-
*
|
|
620
|
-
* @param {Object} [configuration] - configuration options
|
|
621
|
-
* @return {Command|Object} `this` command for chaining, or stored configuration
|
|
622
|
-
*/
|
|
623
|
-
configureHelp(configuration) {
|
|
624
|
-
if (configuration === void 0)
|
|
625
|
-
return this._helpConfiguration;
|
|
626
|
-
this._helpConfiguration = configuration;
|
|
627
|
-
return this;
|
|
628
|
-
}
|
|
629
|
-
/**
|
|
630
|
-
* The default output goes to stdout and stderr. You can customise this for special
|
|
631
|
-
* applications. You can also customise the display of errors by overriding outputError.
|
|
632
|
-
*
|
|
633
|
-
* The configuration properties are all functions:
|
|
634
|
-
*
|
|
635
|
-
* // functions to change where being written, stdout and stderr
|
|
636
|
-
* writeOut(str)
|
|
637
|
-
* writeErr(str)
|
|
638
|
-
* // matching functions to specify width for wrapping help
|
|
639
|
-
* getOutHelpWidth()
|
|
640
|
-
* getErrHelpWidth()
|
|
641
|
-
* // functions based on what is being written out
|
|
642
|
-
* outputError(str, write) // used for displaying errors, and not used for displaying help
|
|
643
|
-
*
|
|
644
|
-
* @param {Object} [configuration] - configuration options
|
|
645
|
-
* @return {Command|Object} `this` command for chaining, or stored configuration
|
|
646
|
-
*/
|
|
647
|
-
configureOutput(configuration) {
|
|
648
|
-
if (configuration === void 0)
|
|
649
|
-
return this._outputConfiguration;
|
|
650
|
-
Object.assign(this._outputConfiguration, configuration);
|
|
651
|
-
return this;
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* Add a prepared subcommand.
|
|
655
|
-
*
|
|
656
|
-
* See .command() for creating an attached subcommand which inherits settings from its parent.
|
|
657
|
-
*
|
|
658
|
-
* @param {Command} cmd - new subcommand
|
|
659
|
-
* @param {Object} [opts] - configuration options
|
|
660
|
-
* @return {Command} `this` command for chaining
|
|
661
|
-
*/
|
|
662
|
-
addCommand(cmd, opts) {
|
|
663
|
-
if (!cmd._name)
|
|
664
|
-
throw new Error("Command passed to .addCommand() must have a name");
|
|
665
|
-
function checkExplicitNames(commandArray) {
|
|
666
|
-
commandArray.forEach((cmd2) => {
|
|
667
|
-
if (cmd2._executableHandler && !cmd2._executableFile) {
|
|
668
|
-
throw new Error(`Must specify executableFile for deeply nested executable: ${cmd2.name()}`);
|
|
669
|
-
}
|
|
670
|
-
checkExplicitNames(cmd2.commands);
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
|
-
checkExplicitNames(cmd.commands);
|
|
674
|
-
opts = opts || {};
|
|
675
|
-
if (opts.isDefault)
|
|
676
|
-
this._defaultCommandName = cmd._name;
|
|
677
|
-
if (opts.noHelp || opts.hidden)
|
|
678
|
-
cmd._hidden = true;
|
|
679
|
-
this.commands.push(cmd);
|
|
680
|
-
cmd.parent = this;
|
|
681
|
-
return this;
|
|
682
|
-
}
|
|
683
|
-
/**
|
|
684
|
-
* Define argument syntax for the command.
|
|
685
|
-
*/
|
|
686
|
-
arguments(desc) {
|
|
687
|
-
return this._parseExpectedArgs(desc.split(/ +/));
|
|
688
|
-
}
|
|
689
|
-
/**
|
|
690
|
-
* Override default decision whether to add implicit help command.
|
|
691
|
-
*
|
|
692
|
-
* addHelpCommand() // force on
|
|
693
|
-
* addHelpCommand(false); // force off
|
|
694
|
-
* addHelpCommand('help [cmd]', 'display help for [cmd]'); // force on with custom details
|
|
695
|
-
*
|
|
696
|
-
* @return {Command} `this` command for chaining
|
|
697
|
-
*/
|
|
698
|
-
addHelpCommand(enableOrNameAndArgs, description) {
|
|
699
|
-
if (enableOrNameAndArgs === false) {
|
|
700
|
-
this._addImplicitHelpCommand = false;
|
|
701
|
-
} else {
|
|
702
|
-
this._addImplicitHelpCommand = true;
|
|
703
|
-
if (typeof enableOrNameAndArgs === "string") {
|
|
704
|
-
this._helpCommandName = enableOrNameAndArgs.split(" ")[0];
|
|
705
|
-
this._helpCommandnameAndArgs = enableOrNameAndArgs;
|
|
706
|
-
}
|
|
707
|
-
this._helpCommandDescription = description || this._helpCommandDescription;
|
|
708
|
-
}
|
|
709
|
-
return this;
|
|
710
|
-
}
|
|
711
|
-
/**
|
|
712
|
-
* @return {boolean}
|
|
713
|
-
* @api private
|
|
714
|
-
*/
|
|
715
|
-
_hasImplicitHelpCommand() {
|
|
716
|
-
if (this._addImplicitHelpCommand === void 0) {
|
|
717
|
-
return this.commands.length && !this._actionHandler && !this._findCommand("help");
|
|
718
|
-
}
|
|
719
|
-
return this._addImplicitHelpCommand;
|
|
720
|
-
}
|
|
721
|
-
/**
|
|
722
|
-
* Parse expected `args`.
|
|
723
|
-
*
|
|
724
|
-
* For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`.
|
|
725
|
-
*
|
|
726
|
-
* @param {Array} args
|
|
727
|
-
* @return {Command} `this` command for chaining
|
|
728
|
-
* @api private
|
|
729
|
-
*/
|
|
730
|
-
_parseExpectedArgs(args) {
|
|
731
|
-
if (!args.length)
|
|
732
|
-
return;
|
|
733
|
-
args.forEach((arg) => {
|
|
734
|
-
const argDetails = {
|
|
735
|
-
required: false,
|
|
736
|
-
name: "",
|
|
737
|
-
variadic: false
|
|
738
|
-
};
|
|
739
|
-
switch (arg[0]) {
|
|
740
|
-
case "<":
|
|
741
|
-
argDetails.required = true;
|
|
742
|
-
argDetails.name = arg.slice(1, -1);
|
|
743
|
-
break;
|
|
744
|
-
case "[":
|
|
745
|
-
argDetails.name = arg.slice(1, -1);
|
|
746
|
-
break;
|
|
747
|
-
}
|
|
748
|
-
if (argDetails.name.length > 3 && argDetails.name.slice(-3) === "...") {
|
|
749
|
-
argDetails.variadic = true;
|
|
750
|
-
argDetails.name = argDetails.name.slice(0, -3);
|
|
751
|
-
}
|
|
752
|
-
if (argDetails.name) {
|
|
753
|
-
this._args.push(argDetails);
|
|
754
|
-
}
|
|
755
|
-
});
|
|
756
|
-
this._args.forEach((arg, i) => {
|
|
757
|
-
if (arg.variadic && i < this._args.length - 1) {
|
|
758
|
-
throw new Error(`only the last argument can be variadic '${arg.name}'`);
|
|
759
|
-
}
|
|
760
|
-
});
|
|
761
|
-
return this;
|
|
762
|
-
}
|
|
763
|
-
/**
|
|
764
|
-
* Register callback to use as replacement for calling process.exit.
|
|
765
|
-
*
|
|
766
|
-
* @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
|
|
767
|
-
* @return {Command} `this` command for chaining
|
|
768
|
-
*/
|
|
769
|
-
exitOverride(fn) {
|
|
770
|
-
if (fn) {
|
|
771
|
-
this._exitCallback = fn;
|
|
772
|
-
} else {
|
|
773
|
-
this._exitCallback = (err) => {
|
|
774
|
-
if (err.code !== "commander.executeSubCommandAsync") {
|
|
775
|
-
throw err;
|
|
776
|
-
} else {
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
}
|
|
780
|
-
return this;
|
|
781
|
-
}
|
|
782
|
-
/**
|
|
783
|
-
* Call process.exit, and _exitCallback if defined.
|
|
784
|
-
*
|
|
785
|
-
* @param {number} exitCode exit code for using with process.exit
|
|
786
|
-
* @param {string} code an id string representing the error
|
|
787
|
-
* @param {string} message human-readable description of the error
|
|
788
|
-
* @return never
|
|
789
|
-
* @api private
|
|
790
|
-
*/
|
|
791
|
-
_exit(exitCode, code, message) {
|
|
792
|
-
if (this._exitCallback) {
|
|
793
|
-
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
794
|
-
}
|
|
795
|
-
process.exit(exitCode);
|
|
796
|
-
}
|
|
797
|
-
/**
|
|
798
|
-
* Register callback `fn` for the command.
|
|
799
|
-
*
|
|
800
|
-
* Examples:
|
|
801
|
-
*
|
|
802
|
-
* program
|
|
803
|
-
* .command('help')
|
|
804
|
-
* .description('display verbose help')
|
|
805
|
-
* .action(function() {
|
|
806
|
-
* // output help here
|
|
807
|
-
* });
|
|
808
|
-
*
|
|
809
|
-
* @param {Function} fn
|
|
810
|
-
* @return {Command} `this` command for chaining
|
|
811
|
-
*/
|
|
812
|
-
action(fn) {
|
|
813
|
-
const listener = (args) => {
|
|
814
|
-
const expectedArgsCount = this._args.length;
|
|
815
|
-
const actionArgs = args.slice(0, expectedArgsCount);
|
|
816
|
-
if (this._storeOptionsAsProperties) {
|
|
817
|
-
actionArgs[expectedArgsCount] = this;
|
|
818
|
-
} else {
|
|
819
|
-
actionArgs[expectedArgsCount] = this.opts();
|
|
820
|
-
}
|
|
821
|
-
actionArgs.push(this);
|
|
822
|
-
const actionResult = fn.apply(this, actionArgs);
|
|
823
|
-
let rootCommand = this;
|
|
824
|
-
while (rootCommand.parent) {
|
|
825
|
-
rootCommand = rootCommand.parent;
|
|
826
|
-
}
|
|
827
|
-
rootCommand._actionResults.push(actionResult);
|
|
828
|
-
};
|
|
829
|
-
this._actionHandler = listener;
|
|
830
|
-
return this;
|
|
831
|
-
}
|
|
832
|
-
/**
|
|
833
|
-
* Factory routine to create a new unattached option.
|
|
834
|
-
*
|
|
835
|
-
* See .option() for creating an attached option, which uses this routine to
|
|
836
|
-
* create the option. You can override createOption to return a custom option.
|
|
837
|
-
*
|
|
838
|
-
* @param {string} flags
|
|
839
|
-
* @param {string} [description]
|
|
840
|
-
* @return {Option} new option
|
|
841
|
-
*/
|
|
842
|
-
createOption(flags, description) {
|
|
843
|
-
return new Option(flags, description);
|
|
844
|
-
}
|
|
845
|
-
/**
|
|
846
|
-
* Add an option.
|
|
847
|
-
*
|
|
848
|
-
* @param {Option} option
|
|
849
|
-
* @return {Command} `this` command for chaining
|
|
850
|
-
*/
|
|
851
|
-
addOption(option) {
|
|
852
|
-
const oname = option.name();
|
|
853
|
-
const name = option.attributeName();
|
|
854
|
-
let defaultValue = option.defaultValue;
|
|
855
|
-
if (option.negate || option.optional || option.required || typeof defaultValue === "boolean") {
|
|
856
|
-
if (option.negate) {
|
|
857
|
-
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
858
|
-
defaultValue = this._findOption(positiveLongFlag) ? this._getOptionValue(name) : true;
|
|
859
|
-
}
|
|
860
|
-
if (defaultValue !== void 0) {
|
|
861
|
-
this._setOptionValue(name, defaultValue);
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
this.options.push(option);
|
|
865
|
-
this.on("option:" + oname, (val) => {
|
|
866
|
-
const oldValue = this._getOptionValue(name);
|
|
867
|
-
if (val !== null && option.parseArg) {
|
|
868
|
-
try {
|
|
869
|
-
val = option.parseArg(val, oldValue === void 0 ? defaultValue : oldValue);
|
|
870
|
-
} catch (err) {
|
|
871
|
-
if (err.code === "commander.invalidOptionArgument") {
|
|
872
|
-
const message = `error: option '${option.flags}' argument '${val}' is invalid. ${err.message}`;
|
|
873
|
-
this._displayError(err.exitCode, err.code, message);
|
|
874
|
-
}
|
|
875
|
-
throw err;
|
|
876
|
-
}
|
|
877
|
-
} else if (val !== null && option.variadic) {
|
|
878
|
-
val = option._concatValue(val, oldValue);
|
|
879
|
-
}
|
|
880
|
-
if (typeof oldValue === "boolean" || typeof oldValue === "undefined") {
|
|
881
|
-
if (val == null) {
|
|
882
|
-
this._setOptionValue(name, option.negate ? false : defaultValue || true);
|
|
883
|
-
} else {
|
|
884
|
-
this._setOptionValue(name, val);
|
|
885
|
-
}
|
|
886
|
-
} else if (val !== null) {
|
|
887
|
-
this._setOptionValue(name, option.negate ? false : val);
|
|
888
|
-
}
|
|
889
|
-
});
|
|
890
|
-
return this;
|
|
891
|
-
}
|
|
892
|
-
/**
|
|
893
|
-
* Internal implementation shared by .option() and .requiredOption()
|
|
894
|
-
*
|
|
895
|
-
* @api private
|
|
896
|
-
*/
|
|
897
|
-
_optionEx(config, flags, description, fn, defaultValue) {
|
|
898
|
-
const option = this.createOption(flags, description);
|
|
899
|
-
option.makeOptionMandatory(!!config.mandatory);
|
|
900
|
-
if (typeof fn === "function") {
|
|
901
|
-
option.default(defaultValue).argParser(fn);
|
|
902
|
-
} else if (fn instanceof RegExp) {
|
|
903
|
-
const regex = fn;
|
|
904
|
-
fn = (val, def) => {
|
|
905
|
-
const m = regex.exec(val);
|
|
906
|
-
return m ? m[0] : def;
|
|
907
|
-
};
|
|
908
|
-
option.default(defaultValue).argParser(fn);
|
|
909
|
-
} else {
|
|
910
|
-
option.default(fn);
|
|
911
|
-
}
|
|
912
|
-
return this.addOption(option);
|
|
913
|
-
}
|
|
914
|
-
/**
|
|
915
|
-
* Define option with `flags`, `description` and optional
|
|
916
|
-
* coercion `fn`.
|
|
917
|
-
*
|
|
918
|
-
* The `flags` string contains the short and/or long flags,
|
|
919
|
-
* separated by comma, a pipe or space. The following are all valid
|
|
920
|
-
* all will output this way when `--help` is used.
|
|
921
|
-
*
|
|
922
|
-
* "-p, --pepper"
|
|
923
|
-
* "-p|--pepper"
|
|
924
|
-
* "-p --pepper"
|
|
925
|
-
*
|
|
926
|
-
* Examples:
|
|
927
|
-
*
|
|
928
|
-
* // simple boolean defaulting to undefined
|
|
929
|
-
* program.option('-p, --pepper', 'add pepper');
|
|
930
|
-
*
|
|
931
|
-
* program.pepper
|
|
932
|
-
* // => undefined
|
|
933
|
-
*
|
|
934
|
-
* --pepper
|
|
935
|
-
* program.pepper
|
|
936
|
-
* // => true
|
|
937
|
-
*
|
|
938
|
-
* // simple boolean defaulting to true (unless non-negated option is also defined)
|
|
939
|
-
* program.option('-C, --no-cheese', 'remove cheese');
|
|
940
|
-
*
|
|
941
|
-
* program.cheese
|
|
942
|
-
* // => true
|
|
943
|
-
*
|
|
944
|
-
* --no-cheese
|
|
945
|
-
* program.cheese
|
|
946
|
-
* // => false
|
|
947
|
-
*
|
|
948
|
-
* // required argument
|
|
949
|
-
* program.option('-C, --chdir <path>', 'change the working directory');
|
|
950
|
-
*
|
|
951
|
-
* --chdir /tmp
|
|
952
|
-
* program.chdir
|
|
953
|
-
* // => "/tmp"
|
|
954
|
-
*
|
|
955
|
-
* // optional argument
|
|
956
|
-
* program.option('-c, --cheese [type]', 'add cheese [marble]');
|
|
957
|
-
*
|
|
958
|
-
* @param {string} flags
|
|
959
|
-
* @param {string} [description]
|
|
960
|
-
* @param {Function|*} [fn] - custom option processing function or default value
|
|
961
|
-
* @param {*} [defaultValue]
|
|
962
|
-
* @return {Command} `this` command for chaining
|
|
963
|
-
*/
|
|
964
|
-
option(flags, description, fn, defaultValue) {
|
|
965
|
-
return this._optionEx({}, flags, description, fn, defaultValue);
|
|
966
|
-
}
|
|
967
|
-
/**
|
|
968
|
-
* Add a required option which must have a value after parsing. This usually means
|
|
969
|
-
* the option must be specified on the command line. (Otherwise the same as .option().)
|
|
970
|
-
*
|
|
971
|
-
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
|
|
972
|
-
*
|
|
973
|
-
* @param {string} flags
|
|
974
|
-
* @param {string} [description]
|
|
975
|
-
* @param {Function|*} [fn] - custom option processing function or default value
|
|
976
|
-
* @param {*} [defaultValue]
|
|
977
|
-
* @return {Command} `this` command for chaining
|
|
978
|
-
*/
|
|
979
|
-
requiredOption(flags, description, fn, defaultValue) {
|
|
980
|
-
return this._optionEx({ mandatory: true }, flags, description, fn, defaultValue);
|
|
981
|
-
}
|
|
982
|
-
/**
|
|
983
|
-
* Alter parsing of short flags with optional values.
|
|
984
|
-
*
|
|
985
|
-
* Examples:
|
|
986
|
-
*
|
|
987
|
-
* // for `.option('-f,--flag [value]'):
|
|
988
|
-
* .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour
|
|
989
|
-
* .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
|
|
990
|
-
*
|
|
991
|
-
* @param {Boolean} [combine=true] - if `true` or omitted, an optional value can be specified directly after the flag.
|
|
992
|
-
*/
|
|
993
|
-
combineFlagAndOptionalValue(combine = true) {
|
|
994
|
-
this._combineFlagAndOptionalValue = !!combine;
|
|
995
|
-
return this;
|
|
996
|
-
}
|
|
997
|
-
/**
|
|
998
|
-
* Allow unknown options on the command line.
|
|
999
|
-
*
|
|
1000
|
-
* @param {Boolean} [allowUnknown=true] - if `true` or omitted, no error will be thrown
|
|
1001
|
-
* for unknown options.
|
|
1002
|
-
*/
|
|
1003
|
-
allowUnknownOption(allowUnknown = true) {
|
|
1004
|
-
this._allowUnknownOption = !!allowUnknown;
|
|
1005
|
-
return this;
|
|
1006
|
-
}
|
|
1007
|
-
/**
|
|
1008
|
-
* Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
|
|
1009
|
-
*
|
|
1010
|
-
* @param {Boolean} [allowExcess=true] - if `true` or omitted, no error will be thrown
|
|
1011
|
-
* for excess arguments.
|
|
1012
|
-
*/
|
|
1013
|
-
allowExcessArguments(allowExcess = true) {
|
|
1014
|
-
this._allowExcessArguments = !!allowExcess;
|
|
1015
|
-
return this;
|
|
1016
|
-
}
|
|
1017
|
-
/**
|
|
1018
|
-
* Enable positional options. Positional means global options are specified before subcommands which lets
|
|
1019
|
-
* subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
|
|
1020
|
-
* The default behaviour is non-positional and global options may appear anywhere on the command line.
|
|
1021
|
-
*
|
|
1022
|
-
* @param {Boolean} [positional=true]
|
|
1023
|
-
*/
|
|
1024
|
-
enablePositionalOptions(positional = true) {
|
|
1025
|
-
this._enablePositionalOptions = !!positional;
|
|
1026
|
-
return this;
|
|
1027
|
-
}
|
|
1028
|
-
/**
|
|
1029
|
-
* Pass through options that come after command-arguments rather than treat them as command-options,
|
|
1030
|
-
* so actual command-options come before command-arguments. Turning this on for a subcommand requires
|
|
1031
|
-
* positional options to have been enabled on the program (parent commands).
|
|
1032
|
-
* The default behaviour is non-positional and options may appear before or after command-arguments.
|
|
1033
|
-
*
|
|
1034
|
-
* @param {Boolean} [passThrough=true]
|
|
1035
|
-
* for unknown options.
|
|
1036
|
-
*/
|
|
1037
|
-
passThroughOptions(passThrough = true) {
|
|
1038
|
-
this._passThroughOptions = !!passThrough;
|
|
1039
|
-
if (!!this.parent && passThrough && !this.parent._enablePositionalOptions) {
|
|
1040
|
-
throw new Error("passThroughOptions can not be used without turning on enablePositionalOptions for parent command(s)");
|
|
1041
|
-
}
|
|
1042
|
-
return this;
|
|
1043
|
-
}
|
|
1044
|
-
/**
|
|
1045
|
-
* Whether to store option values as properties on command object,
|
|
1046
|
-
* or store separately (specify false). In both cases the option values can be accessed using .opts().
|
|
1047
|
-
*
|
|
1048
|
-
* @param {boolean} [storeAsProperties=true]
|
|
1049
|
-
* @return {Command} `this` command for chaining
|
|
1050
|
-
*/
|
|
1051
|
-
storeOptionsAsProperties(storeAsProperties = true) {
|
|
1052
|
-
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
1053
|
-
if (this.options.length) {
|
|
1054
|
-
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
1055
|
-
}
|
|
1056
|
-
return this;
|
|
1057
|
-
}
|
|
1058
|
-
/**
|
|
1059
|
-
* Store option value
|
|
1060
|
-
*
|
|
1061
|
-
* @param {string} key
|
|
1062
|
-
* @param {Object} value
|
|
1063
|
-
* @api private
|
|
1064
|
-
*/
|
|
1065
|
-
_setOptionValue(key, value) {
|
|
1066
|
-
if (this._storeOptionsAsProperties) {
|
|
1067
|
-
this[key] = value;
|
|
1068
|
-
} else {
|
|
1069
|
-
this._optionValues[key] = value;
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
/**
|
|
1073
|
-
* Retrieve option value
|
|
1074
|
-
*
|
|
1075
|
-
* @param {string} key
|
|
1076
|
-
* @return {Object} value
|
|
1077
|
-
* @api private
|
|
1078
|
-
*/
|
|
1079
|
-
_getOptionValue(key) {
|
|
1080
|
-
if (this._storeOptionsAsProperties) {
|
|
1081
|
-
return this[key];
|
|
1082
|
-
}
|
|
1083
|
-
return this._optionValues[key];
|
|
1084
|
-
}
|
|
1085
|
-
/**
|
|
1086
|
-
* Parse `argv`, setting options and invoking commands when defined.
|
|
1087
|
-
*
|
|
1088
|
-
* The default expectation is that the arguments are from node and have the application as argv[0]
|
|
1089
|
-
* and the script being run in argv[1], with user parameters after that.
|
|
1090
|
-
*
|
|
1091
|
-
* Examples:
|
|
1092
|
-
*
|
|
1093
|
-
* program.parse(process.argv);
|
|
1094
|
-
* program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
|
|
1095
|
-
* program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
1096
|
-
*
|
|
1097
|
-
* @param {string[]} [argv] - optional, defaults to process.argv
|
|
1098
|
-
* @param {Object} [parseOptions] - optionally specify style of options with from: node/user/electron
|
|
1099
|
-
* @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
|
|
1100
|
-
* @return {Command} `this` command for chaining
|
|
1101
|
-
*/
|
|
1102
|
-
parse(argv, parseOptions) {
|
|
1103
|
-
if (argv !== void 0 && !Array.isArray(argv)) {
|
|
1104
|
-
throw new Error("first parameter to parse must be array or undefined");
|
|
1105
|
-
}
|
|
1106
|
-
parseOptions = parseOptions || {};
|
|
1107
|
-
if (argv === void 0) {
|
|
1108
|
-
argv = process.argv;
|
|
1109
|
-
if (process.versions && process.versions.electron) {
|
|
1110
|
-
parseOptions.from = "electron";
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
this.rawArgs = argv.slice();
|
|
1114
|
-
let userArgs;
|
|
1115
|
-
switch (parseOptions.from) {
|
|
1116
|
-
case void 0:
|
|
1117
|
-
case "node":
|
|
1118
|
-
this._scriptPath = argv[1];
|
|
1119
|
-
userArgs = argv.slice(2);
|
|
1120
|
-
break;
|
|
1121
|
-
case "electron":
|
|
1122
|
-
if (process.defaultApp) {
|
|
1123
|
-
this._scriptPath = argv[1];
|
|
1124
|
-
userArgs = argv.slice(2);
|
|
1125
|
-
} else {
|
|
1126
|
-
userArgs = argv.slice(1);
|
|
1127
|
-
}
|
|
1128
|
-
break;
|
|
1129
|
-
case "user":
|
|
1130
|
-
userArgs = argv.slice(0);
|
|
1131
|
-
break;
|
|
1132
|
-
default:
|
|
1133
|
-
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
1134
|
-
}
|
|
1135
|
-
if (!this._scriptPath && __require.main) {
|
|
1136
|
-
this._scriptPath = __require.main.filename;
|
|
1137
|
-
}
|
|
1138
|
-
this._name = this._name || this._scriptPath && path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
1139
|
-
this._parseCommand([], userArgs);
|
|
1140
|
-
return this;
|
|
1141
|
-
}
|
|
1142
|
-
/**
|
|
1143
|
-
* Parse `argv`, setting options and invoking commands when defined.
|
|
1144
|
-
*
|
|
1145
|
-
* Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
|
|
1146
|
-
*
|
|
1147
|
-
* The default expectation is that the arguments are from node and have the application as argv[0]
|
|
1148
|
-
* and the script being run in argv[1], with user parameters after that.
|
|
1149
|
-
*
|
|
1150
|
-
* Examples:
|
|
1151
|
-
*
|
|
1152
|
-
* program.parseAsync(process.argv);
|
|
1153
|
-
* program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
|
|
1154
|
-
* program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
1155
|
-
*
|
|
1156
|
-
* @param {string[]} [argv]
|
|
1157
|
-
* @param {Object} [parseOptions]
|
|
1158
|
-
* @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
|
|
1159
|
-
* @return {Promise}
|
|
1160
|
-
*/
|
|
1161
|
-
parseAsync(argv, parseOptions) {
|
|
1162
|
-
this.parse(argv, parseOptions);
|
|
1163
|
-
return Promise.all(this._actionResults).then(() => this);
|
|
1164
|
-
}
|
|
1165
|
-
/**
|
|
1166
|
-
* Execute a sub-command executable.
|
|
1167
|
-
*
|
|
1168
|
-
* @api private
|
|
1169
|
-
*/
|
|
1170
|
-
_executeSubCommand(subcommand, args) {
|
|
1171
|
-
args = args.slice();
|
|
1172
|
-
let launchWithNode = false;
|
|
1173
|
-
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1174
|
-
this._checkForMissingMandatoryOptions();
|
|
1175
|
-
let scriptPath = this._scriptPath;
|
|
1176
|
-
if (!scriptPath && __require.main) {
|
|
1177
|
-
scriptPath = __require.main.filename;
|
|
1178
|
-
}
|
|
1179
|
-
let baseDir;
|
|
1180
|
-
try {
|
|
1181
|
-
const resolvedLink = fs.realpathSync(scriptPath);
|
|
1182
|
-
baseDir = path.dirname(resolvedLink);
|
|
1183
|
-
} catch (e) {
|
|
1184
|
-
baseDir = ".";
|
|
1185
|
-
}
|
|
1186
|
-
let bin = path.basename(scriptPath, path.extname(scriptPath)) + "-" + subcommand._name;
|
|
1187
|
-
if (subcommand._executableFile) {
|
|
1188
|
-
bin = subcommand._executableFile;
|
|
1189
|
-
}
|
|
1190
|
-
const localBin = path.join(baseDir, bin);
|
|
1191
|
-
if (fs.existsSync(localBin)) {
|
|
1192
|
-
bin = localBin;
|
|
1193
|
-
} else {
|
|
1194
|
-
sourceExt.forEach((ext) => {
|
|
1195
|
-
if (fs.existsSync(`${localBin}${ext}`)) {
|
|
1196
|
-
bin = `${localBin}${ext}`;
|
|
1197
|
-
}
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
|
-
launchWithNode = sourceExt.includes(path.extname(bin));
|
|
1201
|
-
let proc;
|
|
1202
|
-
if (process.platform !== "win32") {
|
|
1203
|
-
if (launchWithNode) {
|
|
1204
|
-
args.unshift(bin);
|
|
1205
|
-
args = incrementNodeInspectorPort(process.execArgv).concat(args);
|
|
1206
|
-
proc = childProcess.spawn(process.argv[0], args, { stdio: "inherit" });
|
|
1207
|
-
} else {
|
|
1208
|
-
proc = childProcess.spawn(bin, args, { stdio: "inherit" });
|
|
1209
|
-
}
|
|
1210
|
-
} else {
|
|
1211
|
-
args.unshift(bin);
|
|
1212
|
-
args = incrementNodeInspectorPort(process.execArgv).concat(args);
|
|
1213
|
-
proc = childProcess.spawn(process.execPath, args, { stdio: "inherit" });
|
|
1214
|
-
}
|
|
1215
|
-
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
1216
|
-
signals.forEach((signal) => {
|
|
1217
|
-
process.on(signal, () => {
|
|
1218
|
-
if (proc.killed === false && proc.exitCode === null) {
|
|
1219
|
-
proc.kill(signal);
|
|
1220
|
-
}
|
|
1221
|
-
});
|
|
1222
|
-
});
|
|
1223
|
-
const exitCallback = this._exitCallback;
|
|
1224
|
-
if (!exitCallback) {
|
|
1225
|
-
proc.on("close", process.exit.bind(process));
|
|
1226
|
-
} else {
|
|
1227
|
-
proc.on("close", () => {
|
|
1228
|
-
exitCallback(new CommanderError(process.exitCode || 0, "commander.executeSubCommandAsync", "(close)"));
|
|
1229
|
-
});
|
|
1230
|
-
}
|
|
1231
|
-
proc.on("error", (err) => {
|
|
1232
|
-
if (err.code === "ENOENT") {
|
|
1233
|
-
const executableMissing = `'${bin}' does not exist
|
|
1234
|
-
- if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1235
|
-
- if the default executable name is not suitable, use the executableFile option to supply a custom name`;
|
|
1236
|
-
throw new Error(executableMissing);
|
|
1237
|
-
} else if (err.code === "EACCES") {
|
|
1238
|
-
throw new Error(`'${bin}' not executable`);
|
|
1239
|
-
}
|
|
1240
|
-
if (!exitCallback) {
|
|
1241
|
-
process.exit(1);
|
|
1242
|
-
} else {
|
|
1243
|
-
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
1244
|
-
wrappedError.nestedError = err;
|
|
1245
|
-
exitCallback(wrappedError);
|
|
1246
|
-
}
|
|
1247
|
-
});
|
|
1248
|
-
this.runningCommand = proc;
|
|
1249
|
-
}
|
|
1250
|
-
/**
|
|
1251
|
-
* @api private
|
|
1252
|
-
*/
|
|
1253
|
-
_dispatchSubcommand(commandName, operands, unknown) {
|
|
1254
|
-
const subCommand = this._findCommand(commandName);
|
|
1255
|
-
if (!subCommand)
|
|
1256
|
-
this.help({ error: true });
|
|
1257
|
-
if (subCommand._executableHandler) {
|
|
1258
|
-
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
1259
|
-
} else {
|
|
1260
|
-
subCommand._parseCommand(operands, unknown);
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
/**
|
|
1264
|
-
* Process arguments in context of this command.
|
|
1265
|
-
*
|
|
1266
|
-
* @api private
|
|
1267
|
-
*/
|
|
1268
|
-
_parseCommand(operands, unknown) {
|
|
1269
|
-
const parsed = this.parseOptions(unknown);
|
|
1270
|
-
operands = operands.concat(parsed.operands);
|
|
1271
|
-
unknown = parsed.unknown;
|
|
1272
|
-
this.args = operands.concat(unknown);
|
|
1273
|
-
if (operands && this._findCommand(operands[0])) {
|
|
1274
|
-
this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
1275
|
-
} else if (this._hasImplicitHelpCommand() && operands[0] === this._helpCommandName) {
|
|
1276
|
-
if (operands.length === 1) {
|
|
1277
|
-
this.help();
|
|
1278
|
-
} else {
|
|
1279
|
-
this._dispatchSubcommand(operands[1], [], [this._helpLongFlag]);
|
|
1280
|
-
}
|
|
1281
|
-
} else if (this._defaultCommandName) {
|
|
1282
|
-
outputHelpIfRequested(this, unknown);
|
|
1283
|
-
this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
1284
|
-
} else {
|
|
1285
|
-
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
1286
|
-
this.help({ error: true });
|
|
1287
|
-
}
|
|
1288
|
-
outputHelpIfRequested(this, parsed.unknown);
|
|
1289
|
-
this._checkForMissingMandatoryOptions();
|
|
1290
|
-
const checkForUnknownOptions = () => {
|
|
1291
|
-
if (parsed.unknown.length > 0) {
|
|
1292
|
-
this.unknownOption(parsed.unknown[0]);
|
|
1293
|
-
}
|
|
1294
|
-
};
|
|
1295
|
-
const commandEvent = `command:${this.name()}`;
|
|
1296
|
-
if (this._actionHandler) {
|
|
1297
|
-
checkForUnknownOptions();
|
|
1298
|
-
const args = this.args.slice();
|
|
1299
|
-
this._args.forEach((arg, i) => {
|
|
1300
|
-
if (arg.required && args[i] == null) {
|
|
1301
|
-
this.missingArgument(arg.name);
|
|
1302
|
-
} else if (arg.variadic) {
|
|
1303
|
-
args[i] = args.splice(i);
|
|
1304
|
-
args.length = Math.min(i + 1, args.length);
|
|
1305
|
-
}
|
|
1306
|
-
});
|
|
1307
|
-
if (args.length > this._args.length) {
|
|
1308
|
-
this._excessArguments(args);
|
|
1309
|
-
}
|
|
1310
|
-
this._actionHandler(args);
|
|
1311
|
-
if (this.parent)
|
|
1312
|
-
this.parent.emit(commandEvent, operands, unknown);
|
|
1313
|
-
} else if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
1314
|
-
checkForUnknownOptions();
|
|
1315
|
-
this.parent.emit(commandEvent, operands, unknown);
|
|
1316
|
-
} else if (operands.length) {
|
|
1317
|
-
if (this._findCommand("*")) {
|
|
1318
|
-
this._dispatchSubcommand("*", operands, unknown);
|
|
1319
|
-
} else if (this.listenerCount("command:*")) {
|
|
1320
|
-
this.emit("command:*", operands, unknown);
|
|
1321
|
-
} else if (this.commands.length) {
|
|
1322
|
-
this.unknownCommand();
|
|
1323
|
-
} else {
|
|
1324
|
-
checkForUnknownOptions();
|
|
1325
|
-
}
|
|
1326
|
-
} else if (this.commands.length) {
|
|
1327
|
-
this.help({ error: true });
|
|
1328
|
-
} else {
|
|
1329
|
-
checkForUnknownOptions();
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
/**
|
|
1334
|
-
* Find matching command.
|
|
1335
|
-
*
|
|
1336
|
-
* @api private
|
|
1337
|
-
*/
|
|
1338
|
-
_findCommand(name) {
|
|
1339
|
-
if (!name)
|
|
1340
|
-
return void 0;
|
|
1341
|
-
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
1342
|
-
}
|
|
1343
|
-
/**
|
|
1344
|
-
* Return an option matching `arg` if any.
|
|
1345
|
-
*
|
|
1346
|
-
* @param {string} arg
|
|
1347
|
-
* @return {Option}
|
|
1348
|
-
* @api private
|
|
1349
|
-
*/
|
|
1350
|
-
_findOption(arg) {
|
|
1351
|
-
return this.options.find((option) => option.is(arg));
|
|
1352
|
-
}
|
|
1353
|
-
/**
|
|
1354
|
-
* Display an error message if a mandatory option does not have a value.
|
|
1355
|
-
* Lazy calling after checking for help flags from leaf subcommand.
|
|
1356
|
-
*
|
|
1357
|
-
* @api private
|
|
1358
|
-
*/
|
|
1359
|
-
_checkForMissingMandatoryOptions() {
|
|
1360
|
-
for (let cmd = this; cmd; cmd = cmd.parent) {
|
|
1361
|
-
cmd.options.forEach((anOption) => {
|
|
1362
|
-
if (anOption.mandatory && cmd._getOptionValue(anOption.attributeName()) === void 0) {
|
|
1363
|
-
cmd.missingMandatoryOptionValue(anOption);
|
|
1364
|
-
}
|
|
1365
|
-
});
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
/**
|
|
1369
|
-
* Parse options from `argv` removing known options,
|
|
1370
|
-
* and return argv split into operands and unknown arguments.
|
|
1371
|
-
*
|
|
1372
|
-
* Examples:
|
|
1373
|
-
*
|
|
1374
|
-
* argv => operands, unknown
|
|
1375
|
-
* --known kkk op => [op], []
|
|
1376
|
-
* op --known kkk => [op], []
|
|
1377
|
-
* sub --unknown uuu op => [sub], [--unknown uuu op]
|
|
1378
|
-
* sub -- --unknown uuu op => [sub --unknown uuu op], []
|
|
1379
|
-
*
|
|
1380
|
-
* @param {String[]} argv
|
|
1381
|
-
* @return {{operands: String[], unknown: String[]}}
|
|
1382
|
-
*/
|
|
1383
|
-
parseOptions(argv) {
|
|
1384
|
-
const operands = [];
|
|
1385
|
-
const unknown = [];
|
|
1386
|
-
let dest = operands;
|
|
1387
|
-
const args = argv.slice();
|
|
1388
|
-
function maybeOption(arg) {
|
|
1389
|
-
return arg.length > 1 && arg[0] === "-";
|
|
1390
|
-
}
|
|
1391
|
-
let activeVariadicOption = null;
|
|
1392
|
-
while (args.length) {
|
|
1393
|
-
const arg = args.shift();
|
|
1394
|
-
if (arg === "--") {
|
|
1395
|
-
if (dest === unknown)
|
|
1396
|
-
dest.push(arg);
|
|
1397
|
-
dest.push(...args);
|
|
1398
|
-
break;
|
|
1399
|
-
}
|
|
1400
|
-
if (activeVariadicOption && !maybeOption(arg)) {
|
|
1401
|
-
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1402
|
-
continue;
|
|
1403
|
-
}
|
|
1404
|
-
activeVariadicOption = null;
|
|
1405
|
-
if (maybeOption(arg)) {
|
|
1406
|
-
const option = this._findOption(arg);
|
|
1407
|
-
if (option) {
|
|
1408
|
-
if (option.required) {
|
|
1409
|
-
const value = args.shift();
|
|
1410
|
-
if (value === void 0)
|
|
1411
|
-
this.optionMissingArgument(option);
|
|
1412
|
-
this.emit(`option:${option.name()}`, value);
|
|
1413
|
-
} else if (option.optional) {
|
|
1414
|
-
let value = null;
|
|
1415
|
-
if (args.length > 0 && !maybeOption(args[0])) {
|
|
1416
|
-
value = args.shift();
|
|
1417
|
-
}
|
|
1418
|
-
this.emit(`option:${option.name()}`, value);
|
|
1419
|
-
} else {
|
|
1420
|
-
this.emit(`option:${option.name()}`);
|
|
1421
|
-
}
|
|
1422
|
-
activeVariadicOption = option.variadic ? option : null;
|
|
1423
|
-
continue;
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1427
|
-
const option = this._findOption(`-${arg[1]}`);
|
|
1428
|
-
if (option) {
|
|
1429
|
-
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
1430
|
-
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1431
|
-
} else {
|
|
1432
|
-
this.emit(`option:${option.name()}`);
|
|
1433
|
-
args.unshift(`-${arg.slice(2)}`);
|
|
1434
|
-
}
|
|
1435
|
-
continue;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
if (/^--[^=]+=/.test(arg)) {
|
|
1439
|
-
const index = arg.indexOf("=");
|
|
1440
|
-
const option = this._findOption(arg.slice(0, index));
|
|
1441
|
-
if (option && (option.required || option.optional)) {
|
|
1442
|
-
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1443
|
-
continue;
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
if (maybeOption(arg)) {
|
|
1447
|
-
dest = unknown;
|
|
1448
|
-
}
|
|
1449
|
-
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1450
|
-
if (this._findCommand(arg)) {
|
|
1451
|
-
operands.push(arg);
|
|
1452
|
-
if (args.length > 0)
|
|
1453
|
-
unknown.push(...args);
|
|
1454
|
-
break;
|
|
1455
|
-
} else if (arg === this._helpCommandName && this._hasImplicitHelpCommand()) {
|
|
1456
|
-
operands.push(arg);
|
|
1457
|
-
if (args.length > 0)
|
|
1458
|
-
operands.push(...args);
|
|
1459
|
-
break;
|
|
1460
|
-
} else if (this._defaultCommandName) {
|
|
1461
|
-
unknown.push(arg);
|
|
1462
|
-
if (args.length > 0)
|
|
1463
|
-
unknown.push(...args);
|
|
1464
|
-
break;
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
if (this._passThroughOptions) {
|
|
1468
|
-
dest.push(arg);
|
|
1469
|
-
if (args.length > 0)
|
|
1470
|
-
dest.push(...args);
|
|
1471
|
-
break;
|
|
1472
|
-
}
|
|
1473
|
-
dest.push(arg);
|
|
1474
|
-
}
|
|
1475
|
-
return { operands, unknown };
|
|
1476
|
-
}
|
|
1477
|
-
/**
|
|
1478
|
-
* Return an object containing options as key-value pairs
|
|
1479
|
-
*
|
|
1480
|
-
* @return {Object}
|
|
1481
|
-
*/
|
|
1482
|
-
opts() {
|
|
1483
|
-
if (this._storeOptionsAsProperties) {
|
|
1484
|
-
const result = {};
|
|
1485
|
-
const len = this.options.length;
|
|
1486
|
-
for (let i = 0; i < len; i++) {
|
|
1487
|
-
const key = this.options[i].attributeName();
|
|
1488
|
-
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
1489
|
-
}
|
|
1490
|
-
return result;
|
|
1491
|
-
}
|
|
1492
|
-
return this._optionValues;
|
|
1493
|
-
}
|
|
1494
|
-
/**
|
|
1495
|
-
* Internal bottleneck for handling of parsing errors.
|
|
1496
|
-
*
|
|
1497
|
-
* @api private
|
|
1498
|
-
*/
|
|
1499
|
-
_displayError(exitCode, code, message) {
|
|
1500
|
-
this._outputConfiguration.outputError(`${message}
|
|
1501
|
-
`, this._outputConfiguration.writeErr);
|
|
1502
|
-
this._exit(exitCode, code, message);
|
|
1503
|
-
}
|
|
1504
|
-
/**
|
|
1505
|
-
* Argument `name` is missing.
|
|
1506
|
-
*
|
|
1507
|
-
* @param {string} name
|
|
1508
|
-
* @api private
|
|
1509
|
-
*/
|
|
1510
|
-
missingArgument(name) {
|
|
1511
|
-
const message = `error: missing required argument '${name}'`;
|
|
1512
|
-
this._displayError(1, "commander.missingArgument", message);
|
|
1513
|
-
}
|
|
1514
|
-
/**
|
|
1515
|
-
* `Option` is missing an argument.
|
|
1516
|
-
*
|
|
1517
|
-
* @param {Option} option
|
|
1518
|
-
* @api private
|
|
1519
|
-
*/
|
|
1520
|
-
optionMissingArgument(option) {
|
|
1521
|
-
const message = `error: option '${option.flags}' argument missing`;
|
|
1522
|
-
this._displayError(1, "commander.optionMissingArgument", message);
|
|
1523
|
-
}
|
|
1524
|
-
/**
|
|
1525
|
-
* `Option` does not have a value, and is a mandatory option.
|
|
1526
|
-
*
|
|
1527
|
-
* @param {Option} option
|
|
1528
|
-
* @api private
|
|
1529
|
-
*/
|
|
1530
|
-
missingMandatoryOptionValue(option) {
|
|
1531
|
-
const message = `error: required option '${option.flags}' not specified`;
|
|
1532
|
-
this._displayError(1, "commander.missingMandatoryOptionValue", message);
|
|
1533
|
-
}
|
|
1534
|
-
/**
|
|
1535
|
-
* Unknown option `flag`.
|
|
1536
|
-
*
|
|
1537
|
-
* @param {string} flag
|
|
1538
|
-
* @api private
|
|
1539
|
-
*/
|
|
1540
|
-
unknownOption(flag) {
|
|
1541
|
-
if (this._allowUnknownOption)
|
|
1542
|
-
return;
|
|
1543
|
-
const message = `error: unknown option '${flag}'`;
|
|
1544
|
-
this._displayError(1, "commander.unknownOption", message);
|
|
1545
|
-
}
|
|
1546
|
-
/**
|
|
1547
|
-
* Excess arguments, more than expected.
|
|
1548
|
-
*
|
|
1549
|
-
* @param {string[]} receivedArgs
|
|
1550
|
-
* @api private
|
|
1551
|
-
*/
|
|
1552
|
-
_excessArguments(receivedArgs) {
|
|
1553
|
-
if (this._allowExcessArguments)
|
|
1554
|
-
return;
|
|
1555
|
-
const expected = this._args.length;
|
|
1556
|
-
const s = expected === 1 ? "" : "s";
|
|
1557
|
-
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
1558
|
-
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
1559
|
-
this._displayError(1, "commander.excessArguments", message);
|
|
1560
|
-
}
|
|
1561
|
-
/**
|
|
1562
|
-
* Unknown command.
|
|
1563
|
-
*
|
|
1564
|
-
* @api private
|
|
1565
|
-
*/
|
|
1566
|
-
unknownCommand() {
|
|
1567
|
-
const partCommands = [this.name()];
|
|
1568
|
-
for (let parentCmd = this.parent; parentCmd; parentCmd = parentCmd.parent) {
|
|
1569
|
-
partCommands.unshift(parentCmd.name());
|
|
1570
|
-
}
|
|
1571
|
-
const fullCommand = partCommands.join(" ");
|
|
1572
|
-
const message = `error: unknown command '${this.args[0]}'.` + (this._hasHelpOption ? ` See '${fullCommand} ${this._helpLongFlag}'.` : "");
|
|
1573
|
-
this._displayError(1, "commander.unknownCommand", message);
|
|
1574
|
-
}
|
|
1575
|
-
/**
|
|
1576
|
-
* Set the program version to `str`.
|
|
1577
|
-
*
|
|
1578
|
-
* This method auto-registers the "-V, --version" flag
|
|
1579
|
-
* which will print the version number when passed.
|
|
1580
|
-
*
|
|
1581
|
-
* You can optionally supply the flags and description to override the defaults.
|
|
1582
|
-
*
|
|
1583
|
-
* @param {string} str
|
|
1584
|
-
* @param {string} [flags]
|
|
1585
|
-
* @param {string} [description]
|
|
1586
|
-
* @return {this | string} `this` command for chaining, or version string if no arguments
|
|
1587
|
-
*/
|
|
1588
|
-
version(str, flags, description) {
|
|
1589
|
-
if (str === void 0)
|
|
1590
|
-
return this._version;
|
|
1591
|
-
this._version = str;
|
|
1592
|
-
flags = flags || "-V, --version";
|
|
1593
|
-
description = description || "output the version number";
|
|
1594
|
-
const versionOption = this.createOption(flags, description);
|
|
1595
|
-
this._versionOptionName = versionOption.attributeName();
|
|
1596
|
-
this.options.push(versionOption);
|
|
1597
|
-
this.on("option:" + versionOption.name(), () => {
|
|
1598
|
-
this._outputConfiguration.writeOut(`${str}
|
|
1599
|
-
`);
|
|
1600
|
-
this._exit(0, "commander.version", str);
|
|
1601
|
-
});
|
|
1602
|
-
return this;
|
|
1603
|
-
}
|
|
1604
|
-
/**
|
|
1605
|
-
* Set the description to `str`.
|
|
1606
|
-
*
|
|
1607
|
-
* @param {string} [str]
|
|
1608
|
-
* @param {Object} [argsDescription]
|
|
1609
|
-
* @return {string|Command}
|
|
1610
|
-
*/
|
|
1611
|
-
description(str, argsDescription) {
|
|
1612
|
-
if (str === void 0 && argsDescription === void 0)
|
|
1613
|
-
return this._description;
|
|
1614
|
-
this._description = str;
|
|
1615
|
-
this._argsDescription = argsDescription;
|
|
1616
|
-
return this;
|
|
1617
|
-
}
|
|
1618
|
-
/**
|
|
1619
|
-
* Set an alias for the command.
|
|
1620
|
-
*
|
|
1621
|
-
* You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
|
|
1622
|
-
*
|
|
1623
|
-
* @param {string} [alias]
|
|
1624
|
-
* @return {string|Command}
|
|
1625
|
-
*/
|
|
1626
|
-
alias(alias) {
|
|
1627
|
-
if (alias === void 0)
|
|
1628
|
-
return this._aliases[0];
|
|
1629
|
-
let command = this;
|
|
1630
|
-
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
1631
|
-
command = this.commands[this.commands.length - 1];
|
|
1632
|
-
}
|
|
1633
|
-
if (alias === command._name)
|
|
1634
|
-
throw new Error("Command alias can't be the same as its name");
|
|
1635
|
-
command._aliases.push(alias);
|
|
1636
|
-
return this;
|
|
1637
|
-
}
|
|
1638
|
-
/**
|
|
1639
|
-
* Set aliases for the command.
|
|
1640
|
-
*
|
|
1641
|
-
* Only the first alias is shown in the auto-generated help.
|
|
1642
|
-
*
|
|
1643
|
-
* @param {string[]} [aliases]
|
|
1644
|
-
* @return {string[]|Command}
|
|
1645
|
-
*/
|
|
1646
|
-
aliases(aliases) {
|
|
1647
|
-
if (aliases === void 0)
|
|
1648
|
-
return this._aliases;
|
|
1649
|
-
aliases.forEach((alias) => this.alias(alias));
|
|
1650
|
-
return this;
|
|
1651
|
-
}
|
|
1652
|
-
/**
|
|
1653
|
-
* Set / get the command usage `str`.
|
|
1654
|
-
*
|
|
1655
|
-
* @param {string} [str]
|
|
1656
|
-
* @return {String|Command}
|
|
1657
|
-
*/
|
|
1658
|
-
usage(str) {
|
|
1659
|
-
if (str === void 0) {
|
|
1660
|
-
if (this._usage)
|
|
1661
|
-
return this._usage;
|
|
1662
|
-
const args = this._args.map((arg) => {
|
|
1663
|
-
return humanReadableArgName(arg);
|
|
1664
|
-
});
|
|
1665
|
-
return [].concat(
|
|
1666
|
-
this.options.length || this._hasHelpOption ? "[options]" : [],
|
|
1667
|
-
this.commands.length ? "[command]" : [],
|
|
1668
|
-
this._args.length ? args : []
|
|
1669
|
-
).join(" ");
|
|
1670
|
-
}
|
|
1671
|
-
this._usage = str;
|
|
1672
|
-
return this;
|
|
1673
|
-
}
|
|
1674
|
-
/**
|
|
1675
|
-
* Get or set the name of the command
|
|
1676
|
-
*
|
|
1677
|
-
* @param {string} [str]
|
|
1678
|
-
* @return {string|Command}
|
|
1679
|
-
*/
|
|
1680
|
-
name(str) {
|
|
1681
|
-
if (str === void 0)
|
|
1682
|
-
return this._name;
|
|
1683
|
-
this._name = str;
|
|
1684
|
-
return this;
|
|
1685
|
-
}
|
|
1686
|
-
/**
|
|
1687
|
-
* Return program help documentation.
|
|
1688
|
-
*
|
|
1689
|
-
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to wrap for stderr instead of stdout
|
|
1690
|
-
* @return {string}
|
|
1691
|
-
*/
|
|
1692
|
-
helpInformation(contextOptions) {
|
|
1693
|
-
const helper = this.createHelp();
|
|
1694
|
-
if (helper.helpWidth === void 0) {
|
|
1695
|
-
helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
|
|
1696
|
-
}
|
|
1697
|
-
return helper.formatHelp(this, helper);
|
|
1698
|
-
}
|
|
1699
|
-
/**
|
|
1700
|
-
* @api private
|
|
1701
|
-
*/
|
|
1702
|
-
_getHelpContext(contextOptions) {
|
|
1703
|
-
contextOptions = contextOptions || {};
|
|
1704
|
-
const context = { error: !!contextOptions.error };
|
|
1705
|
-
let write;
|
|
1706
|
-
if (context.error) {
|
|
1707
|
-
write = (arg) => this._outputConfiguration.writeErr(arg);
|
|
1708
|
-
} else {
|
|
1709
|
-
write = (arg) => this._outputConfiguration.writeOut(arg);
|
|
1710
|
-
}
|
|
1711
|
-
context.write = contextOptions.write || write;
|
|
1712
|
-
context.command = this;
|
|
1713
|
-
return context;
|
|
1714
|
-
}
|
|
1715
|
-
/**
|
|
1716
|
-
* Output help information for this command.
|
|
1717
|
-
*
|
|
1718
|
-
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
1719
|
-
*
|
|
1720
|
-
* @param {{ error: boolean } | Function} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
1721
|
-
*/
|
|
1722
|
-
outputHelp(contextOptions) {
|
|
1723
|
-
let deprecatedCallback;
|
|
1724
|
-
if (typeof contextOptions === "function") {
|
|
1725
|
-
deprecatedCallback = contextOptions;
|
|
1726
|
-
contextOptions = void 0;
|
|
1727
|
-
}
|
|
1728
|
-
const context = this._getHelpContext(contextOptions);
|
|
1729
|
-
const groupListeners = [];
|
|
1730
|
-
let command = this;
|
|
1731
|
-
while (command) {
|
|
1732
|
-
groupListeners.push(command);
|
|
1733
|
-
command = command.parent;
|
|
1734
|
-
}
|
|
1735
|
-
groupListeners.slice().reverse().forEach((command2) => command2.emit("beforeAllHelp", context));
|
|
1736
|
-
this.emit("beforeHelp", context);
|
|
1737
|
-
let helpInformation = this.helpInformation(context);
|
|
1738
|
-
if (deprecatedCallback) {
|
|
1739
|
-
helpInformation = deprecatedCallback(helpInformation);
|
|
1740
|
-
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
1741
|
-
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
context.write(helpInformation);
|
|
1745
|
-
this.emit(this._helpLongFlag);
|
|
1746
|
-
this.emit("afterHelp", context);
|
|
1747
|
-
groupListeners.forEach((command2) => command2.emit("afterAllHelp", context));
|
|
1748
|
-
}
|
|
1749
|
-
/**
|
|
1750
|
-
* You can pass in flags and a description to override the help
|
|
1751
|
-
* flags and help description for your command. Pass in false to
|
|
1752
|
-
* disable the built-in help option.
|
|
1753
|
-
*
|
|
1754
|
-
* @param {string | boolean} [flags]
|
|
1755
|
-
* @param {string} [description]
|
|
1756
|
-
* @return {Command} `this` command for chaining
|
|
1757
|
-
*/
|
|
1758
|
-
helpOption(flags, description) {
|
|
1759
|
-
if (typeof flags === "boolean") {
|
|
1760
|
-
this._hasHelpOption = flags;
|
|
1761
|
-
return this;
|
|
1762
|
-
}
|
|
1763
|
-
this._helpFlags = flags || this._helpFlags;
|
|
1764
|
-
this._helpDescription = description || this._helpDescription;
|
|
1765
|
-
const helpFlags = _parseOptionFlags(this._helpFlags);
|
|
1766
|
-
this._helpShortFlag = helpFlags.shortFlag;
|
|
1767
|
-
this._helpLongFlag = helpFlags.longFlag;
|
|
1768
|
-
return this;
|
|
1769
|
-
}
|
|
1770
|
-
/**
|
|
1771
|
-
* Output help information and exit.
|
|
1772
|
-
*
|
|
1773
|
-
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
1774
|
-
*
|
|
1775
|
-
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
1776
|
-
*/
|
|
1777
|
-
help(contextOptions) {
|
|
1778
|
-
this.outputHelp(contextOptions);
|
|
1779
|
-
let exitCode = process.exitCode || 0;
|
|
1780
|
-
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
1781
|
-
exitCode = 1;
|
|
1782
|
-
}
|
|
1783
|
-
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
1784
|
-
}
|
|
1785
|
-
/**
|
|
1786
|
-
* Add additional text to be displayed with the built-in help.
|
|
1787
|
-
*
|
|
1788
|
-
* Position is 'before' or 'after' to affect just this command,
|
|
1789
|
-
* and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
|
|
1790
|
-
*
|
|
1791
|
-
* @param {string} position - before or after built-in help
|
|
1792
|
-
* @param {string | Function} text - string to add, or a function returning a string
|
|
1793
|
-
* @return {Command} `this` command for chaining
|
|
1794
|
-
*/
|
|
1795
|
-
addHelpText(position, text) {
|
|
1796
|
-
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
1797
|
-
if (!allowedValues.includes(position)) {
|
|
1798
|
-
throw new Error(`Unexpected value for position to addHelpText.
|
|
1799
|
-
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1800
|
-
}
|
|
1801
|
-
const helpEvent = `${position}Help`;
|
|
1802
|
-
this.on(helpEvent, (context) => {
|
|
1803
|
-
let helpStr;
|
|
1804
|
-
if (typeof text === "function") {
|
|
1805
|
-
helpStr = text({ error: context.error, command: context.command });
|
|
1806
|
-
} else {
|
|
1807
|
-
helpStr = text;
|
|
1808
|
-
}
|
|
1809
|
-
if (helpStr) {
|
|
1810
|
-
context.write(`${helpStr}
|
|
1811
|
-
`);
|
|
1812
|
-
}
|
|
1813
|
-
});
|
|
1814
|
-
return this;
|
|
1815
|
-
}
|
|
1816
|
-
};
|
|
1817
|
-
exports = module.exports = new Command();
|
|
1818
|
-
exports.program = exports;
|
|
1819
|
-
exports.Command = Command;
|
|
1820
|
-
exports.Option = Option;
|
|
1821
|
-
exports.CommanderError = CommanderError;
|
|
1822
|
-
exports.InvalidOptionArgumentError = InvalidOptionArgumentError;
|
|
1823
|
-
exports.Help = Help;
|
|
1824
|
-
function camelcase(flag) {
|
|
1825
|
-
return flag.split("-").reduce((str, word) => {
|
|
1826
|
-
return str + word[0].toUpperCase() + word.slice(1);
|
|
1827
|
-
});
|
|
1828
|
-
}
|
|
1829
|
-
function outputHelpIfRequested(cmd, args) {
|
|
1830
|
-
const helpOption = cmd._hasHelpOption && args.find((arg) => arg === cmd._helpLongFlag || arg === cmd._helpShortFlag);
|
|
1831
|
-
if (helpOption) {
|
|
1832
|
-
cmd.outputHelp();
|
|
1833
|
-
cmd._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
1834
|
-
}
|
|
1835
|
-
}
|
|
1836
|
-
function humanReadableArgName(arg) {
|
|
1837
|
-
const nameOutput = arg.name + (arg.variadic === true ? "..." : "");
|
|
1838
|
-
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
1839
|
-
}
|
|
1840
|
-
function _parseOptionFlags(flags) {
|
|
1841
|
-
let shortFlag;
|
|
1842
|
-
let longFlag;
|
|
1843
|
-
const flagParts = flags.split(/[ |,]+/);
|
|
1844
|
-
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
1845
|
-
shortFlag = flagParts.shift();
|
|
1846
|
-
longFlag = flagParts.shift();
|
|
1847
|
-
if (!shortFlag && /^-[^-]$/.test(longFlag)) {
|
|
1848
|
-
shortFlag = longFlag;
|
|
1849
|
-
longFlag = void 0;
|
|
1850
|
-
}
|
|
1851
|
-
return { shortFlag, longFlag };
|
|
1852
|
-
}
|
|
1853
|
-
function incrementNodeInspectorPort(args) {
|
|
1854
|
-
return args.map((arg) => {
|
|
1855
|
-
if (!arg.startsWith("--inspect")) {
|
|
1856
|
-
return arg;
|
|
1857
|
-
}
|
|
1858
|
-
let debugOption;
|
|
1859
|
-
let debugHost = "127.0.0.1";
|
|
1860
|
-
let debugPort = "9229";
|
|
1861
|
-
let match;
|
|
1862
|
-
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
1863
|
-
debugOption = match[1];
|
|
1864
|
-
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
1865
|
-
debugOption = match[1];
|
|
1866
|
-
if (/^\d+$/.test(match[3])) {
|
|
1867
|
-
debugPort = match[3];
|
|
1868
|
-
} else {
|
|
1869
|
-
debugHost = match[3];
|
|
1870
|
-
}
|
|
1871
|
-
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
1872
|
-
debugOption = match[1];
|
|
1873
|
-
debugHost = match[3];
|
|
1874
|
-
debugPort = match[4];
|
|
1875
|
-
}
|
|
1876
|
-
if (debugOption && debugPort !== "0") {
|
|
1877
|
-
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
1878
|
-
}
|
|
1879
|
-
return arg;
|
|
1880
|
-
});
|
|
1881
|
-
}
|
|
1882
|
-
}
|
|
1883
|
-
});
|
|
1884
|
-
|
|
1885
|
-
// ../../node_modules/escape-string-regexp/index.js
|
|
1886
|
-
var require_escape_string_regexp = __commonJS({
|
|
1887
|
-
"../../node_modules/escape-string-regexp/index.js"(exports, module) {
|
|
1888
|
-
"use strict";
|
|
1889
|
-
var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
|
|
1890
|
-
module.exports = function(str) {
|
|
1891
|
-
if (typeof str !== "string") {
|
|
1892
|
-
throw new TypeError("Expected a string");
|
|
1893
|
-
}
|
|
1894
|
-
return str.replace(matchOperatorsRe, "\\$&");
|
|
1895
|
-
};
|
|
1896
|
-
}
|
|
1897
|
-
});
|
|
1898
|
-
|
|
1899
|
-
// ../../node_modules/color-name/index.js
|
|
34
|
+
// node_modules/color-name/index.js
|
|
1900
35
|
var require_color_name = __commonJS({
|
|
1901
|
-
"
|
|
36
|
+
"node_modules/color-name/index.js"(exports, module) {
|
|
1902
37
|
"use strict";
|
|
1903
38
|
module.exports = {
|
|
1904
39
|
"aliceblue": [240, 248, 255],
|
|
@@ -2053,18 +188,15 @@ var require_color_name = __commonJS({
|
|
|
2053
188
|
}
|
|
2054
189
|
});
|
|
2055
190
|
|
|
2056
|
-
//
|
|
191
|
+
// node_modules/color-convert/conversions.js
|
|
2057
192
|
var require_conversions = __commonJS({
|
|
2058
|
-
"
|
|
193
|
+
"node_modules/color-convert/conversions.js"(exports, module) {
|
|
2059
194
|
var cssKeywords = require_color_name();
|
|
2060
195
|
var reverseKeywords = {};
|
|
2061
|
-
for (key
|
|
2062
|
-
|
|
2063
|
-
reverseKeywords[cssKeywords[key]] = key;
|
|
2064
|
-
}
|
|
196
|
+
for (const key of Object.keys(cssKeywords)) {
|
|
197
|
+
reverseKeywords[cssKeywords[key]] = key;
|
|
2065
198
|
}
|
|
2066
|
-
var
|
|
2067
|
-
var convert = module.exports = {
|
|
199
|
+
var convert = {
|
|
2068
200
|
rgb: { channels: 3, labels: "rgb" },
|
|
2069
201
|
hsl: { channels: 3, labels: "hsl" },
|
|
2070
202
|
hsv: { channels: 3, labels: "hsv" },
|
|
@@ -2081,38 +213,32 @@ var require_conversions = __commonJS({
|
|
|
2081
213
|
apple: { channels: 3, labels: ["r16", "g16", "b16"] },
|
|
2082
214
|
gray: { channels: 1, labels: ["gray"] }
|
|
2083
215
|
};
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
}
|
|
2089
|
-
if (!("labels" in convert[model])) {
|
|
2090
|
-
throw new Error("missing channel labels property: " + model);
|
|
2091
|
-
}
|
|
2092
|
-
if (convert[model].labels.length !== convert[model].channels) {
|
|
2093
|
-
throw new Error("channel and label counts mismatch: " + model);
|
|
2094
|
-
}
|
|
2095
|
-
channels = convert[model].channels;
|
|
2096
|
-
labels = convert[model].labels;
|
|
2097
|
-
delete convert[model].channels;
|
|
2098
|
-
delete convert[model].labels;
|
|
2099
|
-
Object.defineProperty(convert[model], "channels", { value: channels });
|
|
2100
|
-
Object.defineProperty(convert[model], "labels", { value: labels });
|
|
216
|
+
module.exports = convert;
|
|
217
|
+
for (const model of Object.keys(convert)) {
|
|
218
|
+
if (!("channels" in convert[model])) {
|
|
219
|
+
throw new Error("missing channels property: " + model);
|
|
2101
220
|
}
|
|
221
|
+
if (!("labels" in convert[model])) {
|
|
222
|
+
throw new Error("missing channel labels property: " + model);
|
|
223
|
+
}
|
|
224
|
+
if (convert[model].labels.length !== convert[model].channels) {
|
|
225
|
+
throw new Error("channel and label counts mismatch: " + model);
|
|
226
|
+
}
|
|
227
|
+
const { channels, labels } = convert[model];
|
|
228
|
+
delete convert[model].channels;
|
|
229
|
+
delete convert[model].labels;
|
|
230
|
+
Object.defineProperty(convert[model], "channels", { value: channels });
|
|
231
|
+
Object.defineProperty(convert[model], "labels", { value: labels });
|
|
2102
232
|
}
|
|
2103
|
-
var channels;
|
|
2104
|
-
var labels;
|
|
2105
|
-
var model;
|
|
2106
233
|
convert.rgb.hsl = function(rgb) {
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
var l;
|
|
234
|
+
const r = rgb[0] / 255;
|
|
235
|
+
const g = rgb[1] / 255;
|
|
236
|
+
const b = rgb[2] / 255;
|
|
237
|
+
const min = Math.min(r, g, b);
|
|
238
|
+
const max = Math.max(r, g, b);
|
|
239
|
+
const delta = max - min;
|
|
240
|
+
let h;
|
|
241
|
+
let s;
|
|
2116
242
|
if (max === min) {
|
|
2117
243
|
h = 0;
|
|
2118
244
|
} else if (r === max) {
|
|
@@ -2126,7 +252,7 @@ var require_conversions = __commonJS({
|
|
|
2126
252
|
if (h < 0) {
|
|
2127
253
|
h += 360;
|
|
2128
254
|
}
|
|
2129
|
-
l = (min + max) / 2;
|
|
255
|
+
const l = (min + max) / 2;
|
|
2130
256
|
if (max === min) {
|
|
2131
257
|
s = 0;
|
|
2132
258
|
} else if (l <= 0.5) {
|
|
@@ -2137,21 +263,22 @@ var require_conversions = __commonJS({
|
|
|
2137
263
|
return [h, s * 100, l * 100];
|
|
2138
264
|
};
|
|
2139
265
|
convert.rgb.hsv = function(rgb) {
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
266
|
+
let rdif;
|
|
267
|
+
let gdif;
|
|
268
|
+
let bdif;
|
|
269
|
+
let h;
|
|
270
|
+
let s;
|
|
271
|
+
const r = rgb[0] / 255;
|
|
272
|
+
const g = rgb[1] / 255;
|
|
273
|
+
const b = rgb[2] / 255;
|
|
274
|
+
const v = Math.max(r, g, b);
|
|
275
|
+
const diff = v - Math.min(r, g, b);
|
|
276
|
+
const diffc = function(c) {
|
|
2151
277
|
return (v - c) / 6 / diff + 1 / 2;
|
|
2152
278
|
};
|
|
2153
279
|
if (diff === 0) {
|
|
2154
|
-
h =
|
|
280
|
+
h = 0;
|
|
281
|
+
s = 0;
|
|
2155
282
|
} else {
|
|
2156
283
|
s = diff / v;
|
|
2157
284
|
rdif = diffc(r);
|
|
@@ -2177,46 +304,40 @@ var require_conversions = __commonJS({
|
|
|
2177
304
|
];
|
|
2178
305
|
};
|
|
2179
306
|
convert.rgb.hwb = function(rgb) {
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
307
|
+
const r = rgb[0];
|
|
308
|
+
const g = rgb[1];
|
|
309
|
+
let b = rgb[2];
|
|
310
|
+
const h = convert.rgb.hsl(rgb)[0];
|
|
311
|
+
const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
|
2185
312
|
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
|
2186
313
|
return [h, w * 100, b * 100];
|
|
2187
314
|
};
|
|
2188
315
|
convert.rgb.cmyk = function(rgb) {
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
k = Math.min(1 - r, 1 - g, 1 - b);
|
|
2197
|
-
c = (1 - r - k) / (1 - k) || 0;
|
|
2198
|
-
m = (1 - g - k) / (1 - k) || 0;
|
|
2199
|
-
y = (1 - b - k) / (1 - k) || 0;
|
|
316
|
+
const r = rgb[0] / 255;
|
|
317
|
+
const g = rgb[1] / 255;
|
|
318
|
+
const b = rgb[2] / 255;
|
|
319
|
+
const k = Math.min(1 - r, 1 - g, 1 - b);
|
|
320
|
+
const c = (1 - r - k) / (1 - k) || 0;
|
|
321
|
+
const m = (1 - g - k) / (1 - k) || 0;
|
|
322
|
+
const y = (1 - b - k) / (1 - k) || 0;
|
|
2200
323
|
return [c * 100, m * 100, y * 100, k * 100];
|
|
2201
324
|
};
|
|
2202
325
|
function comparativeDistance(x, y) {
|
|
2203
|
-
return
|
|
326
|
+
return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
|
|
2204
327
|
}
|
|
2205
328
|
convert.rgb.keyword = function(rgb) {
|
|
2206
|
-
|
|
329
|
+
const reversed = reverseKeywords[rgb];
|
|
2207
330
|
if (reversed) {
|
|
2208
331
|
return reversed;
|
|
2209
332
|
}
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
for (
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
currentClosestKeyword = keyword;
|
|
2219
|
-
}
|
|
333
|
+
let currentClosestDistance = Infinity;
|
|
334
|
+
let currentClosestKeyword;
|
|
335
|
+
for (const keyword of Object.keys(cssKeywords)) {
|
|
336
|
+
const value = cssKeywords[keyword];
|
|
337
|
+
const distance = comparativeDistance(rgb, value);
|
|
338
|
+
if (distance < currentClosestDistance) {
|
|
339
|
+
currentClosestDistance = distance;
|
|
340
|
+
currentClosestKeyword = keyword;
|
|
2220
341
|
}
|
|
2221
342
|
}
|
|
2222
343
|
return currentClosestKeyword;
|
|
@@ -2225,45 +346,40 @@ var require_conversions = __commonJS({
|
|
|
2225
346
|
return cssKeywords[keyword];
|
|
2226
347
|
};
|
|
2227
348
|
convert.rgb.xyz = function(rgb) {
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
r = r > 0.04045 ?
|
|
2232
|
-
g = g > 0.04045 ?
|
|
2233
|
-
b = b > 0.04045 ?
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
349
|
+
let r = rgb[0] / 255;
|
|
350
|
+
let g = rgb[1] / 255;
|
|
351
|
+
let b = rgb[2] / 255;
|
|
352
|
+
r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
|
|
353
|
+
g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
|
|
354
|
+
b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
|
|
355
|
+
const x = r * 0.4124 + g * 0.3576 + b * 0.1805;
|
|
356
|
+
const y = r * 0.2126 + g * 0.7152 + b * 0.0722;
|
|
357
|
+
const z = r * 0.0193 + g * 0.1192 + b * 0.9505;
|
|
2237
358
|
return [x * 100, y * 100, z * 100];
|
|
2238
359
|
};
|
|
2239
360
|
convert.rgb.lab = function(rgb) {
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
var l;
|
|
2245
|
-
var a;
|
|
2246
|
-
var b;
|
|
361
|
+
const xyz = convert.rgb.xyz(rgb);
|
|
362
|
+
let x = xyz[0];
|
|
363
|
+
let y = xyz[1];
|
|
364
|
+
let z = xyz[2];
|
|
2247
365
|
x /= 95.047;
|
|
2248
366
|
y /= 100;
|
|
2249
367
|
z /= 108.883;
|
|
2250
|
-
x = x > 8856e-6 ?
|
|
2251
|
-
y = y > 8856e-6 ?
|
|
2252
|
-
z = z > 8856e-6 ?
|
|
2253
|
-
l = 116 * y - 16;
|
|
2254
|
-
a = 500 * (x - y);
|
|
2255
|
-
b = 200 * (y - z);
|
|
368
|
+
x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
|
369
|
+
y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
|
370
|
+
z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
|
371
|
+
const l = 116 * y - 16;
|
|
372
|
+
const a = 500 * (x - y);
|
|
373
|
+
const b = 200 * (y - z);
|
|
2256
374
|
return [l, a, b];
|
|
2257
375
|
};
|
|
2258
376
|
convert.hsl.rgb = function(hsl) {
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
var rgb;
|
|
2266
|
-
var val;
|
|
377
|
+
const h = hsl[0] / 360;
|
|
378
|
+
const s = hsl[1] / 100;
|
|
379
|
+
const l = hsl[2] / 100;
|
|
380
|
+
let t2;
|
|
381
|
+
let t3;
|
|
382
|
+
let val;
|
|
2267
383
|
if (s === 0) {
|
|
2268
384
|
val = l * 255;
|
|
2269
385
|
return [val, val, val];
|
|
@@ -2273,9 +389,9 @@ var require_conversions = __commonJS({
|
|
|
2273
389
|
} else {
|
|
2274
390
|
t2 = l + s - l * s;
|
|
2275
391
|
}
|
|
2276
|
-
t1 = 2 * l - t2;
|
|
2277
|
-
rgb = [0, 0, 0];
|
|
2278
|
-
for (
|
|
392
|
+
const t1 = 2 * l - t2;
|
|
393
|
+
const rgb = [0, 0, 0];
|
|
394
|
+
for (let i = 0; i < 3; i++) {
|
|
2279
395
|
t3 = h + 1 / 3 * -(i - 1);
|
|
2280
396
|
if (t3 < 0) {
|
|
2281
397
|
t3++;
|
|
@@ -2297,29 +413,27 @@ var require_conversions = __commonJS({
|
|
|
2297
413
|
return rgb;
|
|
2298
414
|
};
|
|
2299
415
|
convert.hsl.hsv = function(hsl) {
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
var sv;
|
|
2306
|
-
var v;
|
|
416
|
+
const h = hsl[0];
|
|
417
|
+
let s = hsl[1] / 100;
|
|
418
|
+
let l = hsl[2] / 100;
|
|
419
|
+
let smin = s;
|
|
420
|
+
const lmin = Math.max(l, 0.01);
|
|
2307
421
|
l *= 2;
|
|
2308
422
|
s *= l <= 1 ? l : 2 - l;
|
|
2309
423
|
smin *= lmin <= 1 ? lmin : 2 - lmin;
|
|
2310
|
-
v = (l + s) / 2;
|
|
2311
|
-
sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
|
|
424
|
+
const v = (l + s) / 2;
|
|
425
|
+
const sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
|
|
2312
426
|
return [h, sv * 100, v * 100];
|
|
2313
427
|
};
|
|
2314
428
|
convert.hsv.rgb = function(hsv) {
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
429
|
+
const h = hsv[0] / 60;
|
|
430
|
+
const s = hsv[1] / 100;
|
|
431
|
+
let v = hsv[2] / 100;
|
|
432
|
+
const hi = Math.floor(h) % 6;
|
|
433
|
+
const f = h - Math.floor(h);
|
|
434
|
+
const p = 255 * v * (1 - s);
|
|
435
|
+
const q = 255 * v * (1 - s * f);
|
|
436
|
+
const t = 255 * v * (1 - s * (1 - f));
|
|
2323
437
|
v *= 255;
|
|
2324
438
|
switch (hi) {
|
|
2325
439
|
case 0:
|
|
@@ -2337,15 +451,14 @@ var require_conversions = __commonJS({
|
|
|
2337
451
|
}
|
|
2338
452
|
};
|
|
2339
453
|
convert.hsv.hsl = function(hsv) {
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
var l;
|
|
454
|
+
const h = hsv[0];
|
|
455
|
+
const s = hsv[1] / 100;
|
|
456
|
+
const v = hsv[2] / 100;
|
|
457
|
+
const vmin = Math.max(v, 0.01);
|
|
458
|
+
let sl;
|
|
459
|
+
let l;
|
|
2347
460
|
l = (2 - s) * v;
|
|
2348
|
-
lmin = (2 - s) * vmin;
|
|
461
|
+
const lmin = (2 - s) * vmin;
|
|
2349
462
|
sl = s * vmin;
|
|
2350
463
|
sl /= lmin <= 1 ? lmin : 2 - lmin;
|
|
2351
464
|
sl = sl || 0;
|
|
@@ -2353,28 +466,25 @@ var require_conversions = __commonJS({
|
|
|
2353
466
|
return [h, sl * 100, l * 100];
|
|
2354
467
|
};
|
|
2355
468
|
convert.hwb.rgb = function(hwb) {
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
var v;
|
|
2362
|
-
var f;
|
|
2363
|
-
var n;
|
|
469
|
+
const h = hwb[0] / 360;
|
|
470
|
+
let wh = hwb[1] / 100;
|
|
471
|
+
let bl = hwb[2] / 100;
|
|
472
|
+
const ratio = wh + bl;
|
|
473
|
+
let f;
|
|
2364
474
|
if (ratio > 1) {
|
|
2365
475
|
wh /= ratio;
|
|
2366
476
|
bl /= ratio;
|
|
2367
477
|
}
|
|
2368
|
-
i = Math.floor(6 * h);
|
|
2369
|
-
v = 1 - bl;
|
|
478
|
+
const i = Math.floor(6 * h);
|
|
479
|
+
const v = 1 - bl;
|
|
2370
480
|
f = 6 * h - i;
|
|
2371
481
|
if ((i & 1) !== 0) {
|
|
2372
482
|
f = 1 - f;
|
|
2373
483
|
}
|
|
2374
|
-
n = wh + f * (v - wh);
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
484
|
+
const n = wh + f * (v - wh);
|
|
485
|
+
let r;
|
|
486
|
+
let g;
|
|
487
|
+
let b;
|
|
2378
488
|
switch (i) {
|
|
2379
489
|
default:
|
|
2380
490
|
case 6:
|
|
@@ -2412,67 +522,61 @@ var require_conversions = __commonJS({
|
|
|
2412
522
|
return [r * 255, g * 255, b * 255];
|
|
2413
523
|
};
|
|
2414
524
|
convert.cmyk.rgb = function(cmyk) {
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
r = 1 - Math.min(1, c * (1 - k) + k);
|
|
2423
|
-
g = 1 - Math.min(1, m * (1 - k) + k);
|
|
2424
|
-
b = 1 - Math.min(1, y * (1 - k) + k);
|
|
525
|
+
const c = cmyk[0] / 100;
|
|
526
|
+
const m = cmyk[1] / 100;
|
|
527
|
+
const y = cmyk[2] / 100;
|
|
528
|
+
const k = cmyk[3] / 100;
|
|
529
|
+
const r = 1 - Math.min(1, c * (1 - k) + k);
|
|
530
|
+
const g = 1 - Math.min(1, m * (1 - k) + k);
|
|
531
|
+
const b = 1 - Math.min(1, y * (1 - k) + k);
|
|
2425
532
|
return [r * 255, g * 255, b * 255];
|
|
2426
533
|
};
|
|
2427
534
|
convert.xyz.rgb = function(xyz) {
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
535
|
+
const x = xyz[0] / 100;
|
|
536
|
+
const y = xyz[1] / 100;
|
|
537
|
+
const z = xyz[2] / 100;
|
|
538
|
+
let r;
|
|
539
|
+
let g;
|
|
540
|
+
let b;
|
|
2434
541
|
r = x * 3.2406 + y * -1.5372 + z * -0.4986;
|
|
2435
542
|
g = x * -0.9689 + y * 1.8758 + z * 0.0415;
|
|
2436
543
|
b = x * 0.0557 + y * -0.204 + z * 1.057;
|
|
2437
|
-
r = r > 31308e-7 ? 1.055 *
|
|
2438
|
-
g = g > 31308e-7 ? 1.055 *
|
|
2439
|
-
b = b > 31308e-7 ? 1.055 *
|
|
544
|
+
r = r > 31308e-7 ? 1.055 * r ** (1 / 2.4) - 0.055 : r * 12.92;
|
|
545
|
+
g = g > 31308e-7 ? 1.055 * g ** (1 / 2.4) - 0.055 : g * 12.92;
|
|
546
|
+
b = b > 31308e-7 ? 1.055 * b ** (1 / 2.4) - 0.055 : b * 12.92;
|
|
2440
547
|
r = Math.min(Math.max(0, r), 1);
|
|
2441
548
|
g = Math.min(Math.max(0, g), 1);
|
|
2442
549
|
b = Math.min(Math.max(0, b), 1);
|
|
2443
550
|
return [r * 255, g * 255, b * 255];
|
|
2444
551
|
};
|
|
2445
552
|
convert.xyz.lab = function(xyz) {
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
var l;
|
|
2450
|
-
var a;
|
|
2451
|
-
var b;
|
|
553
|
+
let x = xyz[0];
|
|
554
|
+
let y = xyz[1];
|
|
555
|
+
let z = xyz[2];
|
|
2452
556
|
x /= 95.047;
|
|
2453
557
|
y /= 100;
|
|
2454
558
|
z /= 108.883;
|
|
2455
|
-
x = x > 8856e-6 ?
|
|
2456
|
-
y = y > 8856e-6 ?
|
|
2457
|
-
z = z > 8856e-6 ?
|
|
2458
|
-
l = 116 * y - 16;
|
|
2459
|
-
a = 500 * (x - y);
|
|
2460
|
-
b = 200 * (y - z);
|
|
559
|
+
x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
|
560
|
+
y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
|
561
|
+
z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
|
562
|
+
const l = 116 * y - 16;
|
|
563
|
+
const a = 500 * (x - y);
|
|
564
|
+
const b = 200 * (y - z);
|
|
2461
565
|
return [l, a, b];
|
|
2462
566
|
};
|
|
2463
567
|
convert.lab.xyz = function(lab) {
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
568
|
+
const l = lab[0];
|
|
569
|
+
const a = lab[1];
|
|
570
|
+
const b = lab[2];
|
|
571
|
+
let x;
|
|
572
|
+
let y;
|
|
573
|
+
let z;
|
|
2470
574
|
y = (l + 16) / 116;
|
|
2471
575
|
x = a / 500 + y;
|
|
2472
576
|
z = y - b / 200;
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
577
|
+
const y2 = y ** 3;
|
|
578
|
+
const x2 = x ** 3;
|
|
579
|
+
const z2 = z ** 3;
|
|
2476
580
|
y = y2 > 8856e-6 ? y2 : (y - 16 / 116) / 7.787;
|
|
2477
581
|
x = x2 > 8856e-6 ? x2 : (x - 16 / 116) / 7.787;
|
|
2478
582
|
z = z2 > 8856e-6 ? z2 : (z - 16 / 116) / 7.787;
|
|
@@ -2482,42 +586,35 @@ var require_conversions = __commonJS({
|
|
|
2482
586
|
return [x, y, z];
|
|
2483
587
|
};
|
|
2484
588
|
convert.lab.lch = function(lab) {
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
var c;
|
|
2491
|
-
hr = Math.atan2(b, a);
|
|
589
|
+
const l = lab[0];
|
|
590
|
+
const a = lab[1];
|
|
591
|
+
const b = lab[2];
|
|
592
|
+
let h;
|
|
593
|
+
const hr = Math.atan2(b, a);
|
|
2492
594
|
h = hr * 360 / 2 / Math.PI;
|
|
2493
595
|
if (h < 0) {
|
|
2494
596
|
h += 360;
|
|
2495
597
|
}
|
|
2496
|
-
c = Math.sqrt(a * a + b * b);
|
|
598
|
+
const c = Math.sqrt(a * a + b * b);
|
|
2497
599
|
return [l, c, h];
|
|
2498
600
|
};
|
|
2499
601
|
convert.lch.lab = function(lch) {
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
hr = h / 360 * 2 * Math.PI;
|
|
2507
|
-
a = c * Math.cos(hr);
|
|
2508
|
-
b = c * Math.sin(hr);
|
|
602
|
+
const l = lch[0];
|
|
603
|
+
const c = lch[1];
|
|
604
|
+
const h = lch[2];
|
|
605
|
+
const hr = h / 360 * 2 * Math.PI;
|
|
606
|
+
const a = c * Math.cos(hr);
|
|
607
|
+
const b = c * Math.sin(hr);
|
|
2509
608
|
return [l, a, b];
|
|
2510
609
|
};
|
|
2511
|
-
convert.rgb.ansi16 = function(args) {
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
var b = args[2];
|
|
2515
|
-
var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2];
|
|
610
|
+
convert.rgb.ansi16 = function(args, saturation = null) {
|
|
611
|
+
const [r, g, b] = args;
|
|
612
|
+
let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation;
|
|
2516
613
|
value = Math.round(value / 50);
|
|
2517
614
|
if (value === 0) {
|
|
2518
615
|
return 30;
|
|
2519
616
|
}
|
|
2520
|
-
|
|
617
|
+
let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
|
|
2521
618
|
if (value === 2) {
|
|
2522
619
|
ansi += 60;
|
|
2523
620
|
}
|
|
@@ -2527,9 +624,9 @@ var require_conversions = __commonJS({
|
|
|
2527
624
|
return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
|
|
2528
625
|
};
|
|
2529
626
|
convert.rgb.ansi256 = function(args) {
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
627
|
+
const r = args[0];
|
|
628
|
+
const g = args[1];
|
|
629
|
+
const b = args[2];
|
|
2533
630
|
if (r === g && g === b) {
|
|
2534
631
|
if (r < 8) {
|
|
2535
632
|
return 16;
|
|
@@ -2539,11 +636,11 @@ var require_conversions = __commonJS({
|
|
|
2539
636
|
}
|
|
2540
637
|
return Math.round((r - 8) / 247 * 24) + 232;
|
|
2541
638
|
}
|
|
2542
|
-
|
|
639
|
+
const ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
|
|
2543
640
|
return ansi;
|
|
2544
641
|
};
|
|
2545
642
|
convert.ansi16.rgb = function(args) {
|
|
2546
|
-
|
|
643
|
+
let color = args % 10;
|
|
2547
644
|
if (color === 0 || color === 7) {
|
|
2548
645
|
if (args > 50) {
|
|
2549
646
|
color += 3.5;
|
|
@@ -2551,55 +648,55 @@ var require_conversions = __commonJS({
|
|
|
2551
648
|
color = color / 10.5 * 255;
|
|
2552
649
|
return [color, color, color];
|
|
2553
650
|
}
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
651
|
+
const mult = (~~(args > 50) + 1) * 0.5;
|
|
652
|
+
const r = (color & 1) * mult * 255;
|
|
653
|
+
const g = (color >> 1 & 1) * mult * 255;
|
|
654
|
+
const b = (color >> 2 & 1) * mult * 255;
|
|
2558
655
|
return [r, g, b];
|
|
2559
656
|
};
|
|
2560
657
|
convert.ansi256.rgb = function(args) {
|
|
2561
658
|
if (args >= 232) {
|
|
2562
|
-
|
|
659
|
+
const c = (args - 232) * 10 + 8;
|
|
2563
660
|
return [c, c, c];
|
|
2564
661
|
}
|
|
2565
662
|
args -= 16;
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
663
|
+
let rem;
|
|
664
|
+
const r = Math.floor(args / 36) / 5 * 255;
|
|
665
|
+
const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
|
666
|
+
const b = rem % 6 / 5 * 255;
|
|
2570
667
|
return [r, g, b];
|
|
2571
668
|
};
|
|
2572
669
|
convert.rgb.hex = function(args) {
|
|
2573
|
-
|
|
2574
|
-
|
|
670
|
+
const integer = ((Math.round(args[0]) & 255) << 16) + ((Math.round(args[1]) & 255) << 8) + (Math.round(args[2]) & 255);
|
|
671
|
+
const string = integer.toString(16).toUpperCase();
|
|
2575
672
|
return "000000".substring(string.length) + string;
|
|
2576
673
|
};
|
|
2577
674
|
convert.hex.rgb = function(args) {
|
|
2578
|
-
|
|
675
|
+
const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
2579
676
|
if (!match) {
|
|
2580
677
|
return [0, 0, 0];
|
|
2581
678
|
}
|
|
2582
|
-
|
|
679
|
+
let colorString = match[0];
|
|
2583
680
|
if (match[0].length === 3) {
|
|
2584
|
-
colorString = colorString.split("").map(
|
|
681
|
+
colorString = colorString.split("").map((char) => {
|
|
2585
682
|
return char + char;
|
|
2586
683
|
}).join("");
|
|
2587
684
|
}
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
685
|
+
const integer = parseInt(colorString, 16);
|
|
686
|
+
const r = integer >> 16 & 255;
|
|
687
|
+
const g = integer >> 8 & 255;
|
|
688
|
+
const b = integer & 255;
|
|
2592
689
|
return [r, g, b];
|
|
2593
690
|
};
|
|
2594
691
|
convert.rgb.hcg = function(rgb) {
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
692
|
+
const r = rgb[0] / 255;
|
|
693
|
+
const g = rgb[1] / 255;
|
|
694
|
+
const b = rgb[2] / 255;
|
|
695
|
+
const max = Math.max(Math.max(r, g), b);
|
|
696
|
+
const min = Math.min(Math.min(r, g), b);
|
|
697
|
+
const chroma = max - min;
|
|
698
|
+
let grayscale;
|
|
699
|
+
let hue;
|
|
2603
700
|
if (chroma < 1) {
|
|
2604
701
|
grayscale = min / (1 - chroma);
|
|
2605
702
|
} else {
|
|
@@ -2612,49 +709,44 @@ var require_conversions = __commonJS({
|
|
|
2612
709
|
} else if (max === g) {
|
|
2613
710
|
hue = 2 + (b - r) / chroma;
|
|
2614
711
|
} else {
|
|
2615
|
-
hue = 4 + (r - g) / chroma
|
|
712
|
+
hue = 4 + (r - g) / chroma;
|
|
2616
713
|
}
|
|
2617
714
|
hue /= 6;
|
|
2618
715
|
hue %= 1;
|
|
2619
716
|
return [hue * 360, chroma * 100, grayscale * 100];
|
|
2620
717
|
};
|
|
2621
718
|
convert.hsl.hcg = function(hsl) {
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
if (l < 0.5) {
|
|
2627
|
-
c = 2 * s * l;
|
|
2628
|
-
} else {
|
|
2629
|
-
c = 2 * s * (1 - l);
|
|
2630
|
-
}
|
|
719
|
+
const s = hsl[1] / 100;
|
|
720
|
+
const l = hsl[2] / 100;
|
|
721
|
+
const c = l < 0.5 ? 2 * s * l : 2 * s * (1 - l);
|
|
722
|
+
let f = 0;
|
|
2631
723
|
if (c < 1) {
|
|
2632
724
|
f = (l - 0.5 * c) / (1 - c);
|
|
2633
725
|
}
|
|
2634
726
|
return [hsl[0], c * 100, f * 100];
|
|
2635
727
|
};
|
|
2636
728
|
convert.hsv.hcg = function(hsv) {
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
729
|
+
const s = hsv[1] / 100;
|
|
730
|
+
const v = hsv[2] / 100;
|
|
731
|
+
const c = s * v;
|
|
732
|
+
let f = 0;
|
|
2641
733
|
if (c < 1) {
|
|
2642
734
|
f = (v - c) / (1 - c);
|
|
2643
735
|
}
|
|
2644
736
|
return [hsv[0], c * 100, f * 100];
|
|
2645
737
|
};
|
|
2646
738
|
convert.hcg.rgb = function(hcg) {
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
739
|
+
const h = hcg[0] / 360;
|
|
740
|
+
const c = hcg[1] / 100;
|
|
741
|
+
const g = hcg[2] / 100;
|
|
2650
742
|
if (c === 0) {
|
|
2651
743
|
return [g * 255, g * 255, g * 255];
|
|
2652
744
|
}
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
745
|
+
const pure = [0, 0, 0];
|
|
746
|
+
const hi = h % 1 * 6;
|
|
747
|
+
const v = hi % 1;
|
|
748
|
+
const w = 1 - v;
|
|
749
|
+
let mg = 0;
|
|
2658
750
|
switch (Math.floor(hi)) {
|
|
2659
751
|
case 0:
|
|
2660
752
|
pure[0] = 1;
|
|
@@ -2694,20 +786,20 @@ var require_conversions = __commonJS({
|
|
|
2694
786
|
];
|
|
2695
787
|
};
|
|
2696
788
|
convert.hcg.hsv = function(hcg) {
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
789
|
+
const c = hcg[1] / 100;
|
|
790
|
+
const g = hcg[2] / 100;
|
|
791
|
+
const v = c + g * (1 - c);
|
|
792
|
+
let f = 0;
|
|
2701
793
|
if (v > 0) {
|
|
2702
794
|
f = c / v;
|
|
2703
795
|
}
|
|
2704
796
|
return [hcg[0], f * 100, v * 100];
|
|
2705
797
|
};
|
|
2706
798
|
convert.hcg.hsl = function(hcg) {
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
799
|
+
const c = hcg[1] / 100;
|
|
800
|
+
const g = hcg[2] / 100;
|
|
801
|
+
const l = g * (1 - c) + 0.5 * c;
|
|
802
|
+
let s = 0;
|
|
2711
803
|
if (l > 0 && l < 0.5) {
|
|
2712
804
|
s = c / (2 * l);
|
|
2713
805
|
} else if (l >= 0.5 && l < 1) {
|
|
@@ -2716,17 +808,17 @@ var require_conversions = __commonJS({
|
|
|
2716
808
|
return [hcg[0], s * 100, l * 100];
|
|
2717
809
|
};
|
|
2718
810
|
convert.hcg.hwb = function(hcg) {
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
811
|
+
const c = hcg[1] / 100;
|
|
812
|
+
const g = hcg[2] / 100;
|
|
813
|
+
const v = c + g * (1 - c);
|
|
2722
814
|
return [hcg[0], (v - c) * 100, (1 - v) * 100];
|
|
2723
815
|
};
|
|
2724
816
|
convert.hwb.hcg = function(hwb) {
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
817
|
+
const w = hwb[1] / 100;
|
|
818
|
+
const b = hwb[2] / 100;
|
|
819
|
+
const v = 1 - b;
|
|
820
|
+
const c = v - w;
|
|
821
|
+
let g = 0;
|
|
2730
822
|
if (c < 1) {
|
|
2731
823
|
g = (v - c) / (1 - c);
|
|
2732
824
|
}
|
|
@@ -2741,9 +833,10 @@ var require_conversions = __commonJS({
|
|
|
2741
833
|
convert.gray.rgb = function(args) {
|
|
2742
834
|
return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
|
2743
835
|
};
|
|
2744
|
-
convert.gray.hsl =
|
|
836
|
+
convert.gray.hsl = function(args) {
|
|
2745
837
|
return [0, 0, args[0]];
|
|
2746
838
|
};
|
|
839
|
+
convert.gray.hsv = convert.gray.hsl;
|
|
2747
840
|
convert.gray.hwb = function(gray) {
|
|
2748
841
|
return [0, 100, gray[0]];
|
|
2749
842
|
};
|
|
@@ -2754,26 +847,26 @@ var require_conversions = __commonJS({
|
|
|
2754
847
|
return [gray[0], 0, 0];
|
|
2755
848
|
};
|
|
2756
849
|
convert.gray.hex = function(gray) {
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
850
|
+
const val = Math.round(gray[0] / 100 * 255) & 255;
|
|
851
|
+
const integer = (val << 16) + (val << 8) + val;
|
|
852
|
+
const string = integer.toString(16).toUpperCase();
|
|
2760
853
|
return "000000".substring(string.length) + string;
|
|
2761
854
|
};
|
|
2762
855
|
convert.rgb.gray = function(rgb) {
|
|
2763
|
-
|
|
856
|
+
const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
|
2764
857
|
return [val / 255 * 100];
|
|
2765
858
|
};
|
|
2766
859
|
}
|
|
2767
860
|
});
|
|
2768
861
|
|
|
2769
|
-
//
|
|
862
|
+
// node_modules/color-convert/route.js
|
|
2770
863
|
var require_route = __commonJS({
|
|
2771
|
-
"
|
|
864
|
+
"node_modules/color-convert/route.js"(exports, module) {
|
|
2772
865
|
var conversions = require_conversions();
|
|
2773
866
|
function buildGraph() {
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
for (
|
|
867
|
+
const graph = {};
|
|
868
|
+
const models = Object.keys(conversions);
|
|
869
|
+
for (let len = models.length, i = 0; i < len; i++) {
|
|
2777
870
|
graph[models[i]] = {
|
|
2778
871
|
// http://jsperf.com/1-vs-infinity
|
|
2779
872
|
// micro-opt, but this is simple.
|
|
@@ -2784,15 +877,15 @@ var require_route = __commonJS({
|
|
|
2784
877
|
return graph;
|
|
2785
878
|
}
|
|
2786
879
|
function deriveBFS(fromModel) {
|
|
2787
|
-
|
|
2788
|
-
|
|
880
|
+
const graph = buildGraph();
|
|
881
|
+
const queue = [fromModel];
|
|
2789
882
|
graph[fromModel].distance = 0;
|
|
2790
883
|
while (queue.length) {
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
for (
|
|
2794
|
-
|
|
2795
|
-
|
|
884
|
+
const current = queue.pop();
|
|
885
|
+
const adjacents = Object.keys(conversions[current]);
|
|
886
|
+
for (let len = adjacents.length, i = 0; i < len; i++) {
|
|
887
|
+
const adjacent = adjacents[i];
|
|
888
|
+
const node = graph[adjacent];
|
|
2796
889
|
if (node.distance === -1) {
|
|
2797
890
|
node.distance = graph[current].distance + 1;
|
|
2798
891
|
node.parent = current;
|
|
@@ -2808,9 +901,9 @@ var require_route = __commonJS({
|
|
|
2808
901
|
};
|
|
2809
902
|
}
|
|
2810
903
|
function wrapConversion(toModel, graph) {
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
904
|
+
const path = [graph[toModel].parent, toModel];
|
|
905
|
+
let fn = conversions[graph[toModel].parent][toModel];
|
|
906
|
+
let cur = graph[toModel].parent;
|
|
2814
907
|
while (graph[cur].parent) {
|
|
2815
908
|
path.unshift(graph[cur].parent);
|
|
2816
909
|
fn = link(conversions[graph[cur].parent][cur], fn);
|
|
@@ -2820,12 +913,12 @@ var require_route = __commonJS({
|
|
|
2820
913
|
return fn;
|
|
2821
914
|
}
|
|
2822
915
|
module.exports = function(fromModel) {
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
for (
|
|
2827
|
-
|
|
2828
|
-
|
|
916
|
+
const graph = deriveBFS(fromModel);
|
|
917
|
+
const conversion = {};
|
|
918
|
+
const models = Object.keys(graph);
|
|
919
|
+
for (let len = models.length, i = 0; i < len; i++) {
|
|
920
|
+
const toModel = models[i];
|
|
921
|
+
const node = graph[toModel];
|
|
2829
922
|
if (node.parent === null) {
|
|
2830
923
|
continue;
|
|
2831
924
|
}
|
|
@@ -2836,20 +929,21 @@ var require_route = __commonJS({
|
|
|
2836
929
|
}
|
|
2837
930
|
});
|
|
2838
931
|
|
|
2839
|
-
//
|
|
932
|
+
// node_modules/color-convert/index.js
|
|
2840
933
|
var require_color_convert = __commonJS({
|
|
2841
|
-
"
|
|
934
|
+
"node_modules/color-convert/index.js"(exports, module) {
|
|
2842
935
|
var conversions = require_conversions();
|
|
2843
936
|
var route = require_route();
|
|
2844
937
|
var convert = {};
|
|
2845
938
|
var models = Object.keys(conversions);
|
|
2846
939
|
function wrapRaw(fn) {
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
940
|
+
const wrappedFn = function(...args) {
|
|
941
|
+
const arg0 = args[0];
|
|
942
|
+
if (arg0 === void 0 || arg0 === null) {
|
|
943
|
+
return arg0;
|
|
2850
944
|
}
|
|
2851
|
-
if (
|
|
2852
|
-
args =
|
|
945
|
+
if (arg0.length > 1) {
|
|
946
|
+
args = arg0;
|
|
2853
947
|
}
|
|
2854
948
|
return fn(args);
|
|
2855
949
|
};
|
|
@@ -2859,16 +953,17 @@ var require_color_convert = __commonJS({
|
|
|
2859
953
|
return wrappedFn;
|
|
2860
954
|
}
|
|
2861
955
|
function wrapRounded(fn) {
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
956
|
+
const wrappedFn = function(...args) {
|
|
957
|
+
const arg0 = args[0];
|
|
958
|
+
if (arg0 === void 0 || arg0 === null) {
|
|
959
|
+
return arg0;
|
|
2865
960
|
}
|
|
2866
|
-
if (
|
|
2867
|
-
args =
|
|
961
|
+
if (arg0.length > 1) {
|
|
962
|
+
args = arg0;
|
|
2868
963
|
}
|
|
2869
|
-
|
|
964
|
+
const result = fn(args);
|
|
2870
965
|
if (typeof result === "object") {
|
|
2871
|
-
for (
|
|
966
|
+
for (let len = result.length, i = 0; i < len; i++) {
|
|
2872
967
|
result[i] = Math.round(result[i]);
|
|
2873
968
|
}
|
|
2874
969
|
}
|
|
@@ -2879,14 +974,14 @@ var require_color_convert = __commonJS({
|
|
|
2879
974
|
}
|
|
2880
975
|
return wrappedFn;
|
|
2881
976
|
}
|
|
2882
|
-
models.forEach(
|
|
977
|
+
models.forEach((fromModel) => {
|
|
2883
978
|
convert[fromModel] = {};
|
|
2884
979
|
Object.defineProperty(convert[fromModel], "channels", { value: conversions[fromModel].channels });
|
|
2885
980
|
Object.defineProperty(convert[fromModel], "labels", { value: conversions[fromModel].labels });
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
routeModels.forEach(
|
|
2889
|
-
|
|
981
|
+
const routes = route(fromModel);
|
|
982
|
+
const routeModels = Object.keys(routes);
|
|
983
|
+
routeModels.forEach((toModel) => {
|
|
984
|
+
const fn = routes[toModel];
|
|
2890
985
|
convert[fromModel][toModel] = wrapRounded(fn);
|
|
2891
986
|
convert[fromModel][toModel].raw = wrapRaw(fn);
|
|
2892
987
|
});
|
|
@@ -2895,23 +990,56 @@ var require_color_convert = __commonJS({
|
|
|
2895
990
|
}
|
|
2896
991
|
});
|
|
2897
992
|
|
|
2898
|
-
//
|
|
993
|
+
// node_modules/ansi-styles/index.js
|
|
2899
994
|
var require_ansi_styles = __commonJS({
|
|
2900
|
-
"
|
|
995
|
+
"node_modules/ansi-styles/index.js"(exports, module) {
|
|
2901
996
|
"use strict";
|
|
2902
|
-
var
|
|
2903
|
-
|
|
2904
|
-
const code = fn.apply(colorConvert, arguments);
|
|
997
|
+
var wrapAnsi16 = (fn, offset) => (...args) => {
|
|
998
|
+
const code = fn(...args);
|
|
2905
999
|
return `\x1B[${code + offset}m`;
|
|
2906
1000
|
};
|
|
2907
|
-
var wrapAnsi256 = (fn, offset) =>
|
|
2908
|
-
const code = fn
|
|
1001
|
+
var wrapAnsi256 = (fn, offset) => (...args) => {
|
|
1002
|
+
const code = fn(...args);
|
|
2909
1003
|
return `\x1B[${38 + offset};5;${code}m`;
|
|
2910
1004
|
};
|
|
2911
|
-
var wrapAnsi16m = (fn, offset) =>
|
|
2912
|
-
const rgb = fn
|
|
1005
|
+
var wrapAnsi16m = (fn, offset) => (...args) => {
|
|
1006
|
+
const rgb = fn(...args);
|
|
2913
1007
|
return `\x1B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
|
|
2914
1008
|
};
|
|
1009
|
+
var ansi2ansi = (n) => n;
|
|
1010
|
+
var rgb2rgb = (r, g, b) => [r, g, b];
|
|
1011
|
+
var setLazyProperty = (object, property, get) => {
|
|
1012
|
+
Object.defineProperty(object, property, {
|
|
1013
|
+
get: () => {
|
|
1014
|
+
const value = get();
|
|
1015
|
+
Object.defineProperty(object, property, {
|
|
1016
|
+
value,
|
|
1017
|
+
enumerable: true,
|
|
1018
|
+
configurable: true
|
|
1019
|
+
});
|
|
1020
|
+
return value;
|
|
1021
|
+
},
|
|
1022
|
+
enumerable: true,
|
|
1023
|
+
configurable: true
|
|
1024
|
+
});
|
|
1025
|
+
};
|
|
1026
|
+
var colorConvert;
|
|
1027
|
+
var makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
|
|
1028
|
+
if (colorConvert === void 0) {
|
|
1029
|
+
colorConvert = require_color_convert();
|
|
1030
|
+
}
|
|
1031
|
+
const offset = isBackground ? 10 : 0;
|
|
1032
|
+
const styles = {};
|
|
1033
|
+
for (const [sourceSpace, suite] of Object.entries(colorConvert)) {
|
|
1034
|
+
const name = sourceSpace === "ansi16" ? "ansi" : sourceSpace;
|
|
1035
|
+
if (sourceSpace === targetSpace) {
|
|
1036
|
+
styles[name] = wrap(identity, offset);
|
|
1037
|
+
} else if (typeof suite === "object") {
|
|
1038
|
+
styles[name] = wrap(suite[targetSpace], offset);
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
return styles;
|
|
1042
|
+
};
|
|
2915
1043
|
function assembleStyles() {
|
|
2916
1044
|
const codes = /* @__PURE__ */ new Map();
|
|
2917
1045
|
const styles = {
|
|
@@ -2935,8 +1063,8 @@ var require_ansi_styles = __commonJS({
|
|
|
2935
1063
|
magenta: [35, 39],
|
|
2936
1064
|
cyan: [36, 39],
|
|
2937
1065
|
white: [37, 39],
|
|
2938
|
-
gray: [90, 39],
|
|
2939
1066
|
// Bright color
|
|
1067
|
+
blackBright: [90, 39],
|
|
2940
1068
|
redBright: [91, 39],
|
|
2941
1069
|
greenBright: [92, 39],
|
|
2942
1070
|
yellowBright: [93, 39],
|
|
@@ -2965,11 +1093,12 @@ var require_ansi_styles = __commonJS({
|
|
|
2965
1093
|
bgWhiteBright: [107, 49]
|
|
2966
1094
|
}
|
|
2967
1095
|
};
|
|
2968
|
-
styles.color.
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
1096
|
+
styles.color.gray = styles.color.blackBright;
|
|
1097
|
+
styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
|
|
1098
|
+
styles.color.grey = styles.color.blackBright;
|
|
1099
|
+
styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
|
|
1100
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
1101
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
2973
1102
|
styles[styleName] = {
|
|
2974
1103
|
open: `\x1B[${style[0]}m`,
|
|
2975
1104
|
close: `\x1B[${style[1]}m`
|
|
@@ -2981,54 +1110,19 @@ var require_ansi_styles = __commonJS({
|
|
|
2981
1110
|
value: group,
|
|
2982
1111
|
enumerable: false
|
|
2983
1112
|
});
|
|
2984
|
-
Object.defineProperty(styles, "codes", {
|
|
2985
|
-
value: codes,
|
|
2986
|
-
enumerable: false
|
|
2987
|
-
});
|
|
2988
1113
|
}
|
|
2989
|
-
|
|
2990
|
-
|
|
1114
|
+
Object.defineProperty(styles, "codes", {
|
|
1115
|
+
value: codes,
|
|
1116
|
+
enumerable: false
|
|
1117
|
+
});
|
|
2991
1118
|
styles.color.close = "\x1B[39m";
|
|
2992
1119
|
styles.bgColor.close = "\x1B[49m";
|
|
2993
|
-
styles.color
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
styles.
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
styles.color.ansi16m = {
|
|
3000
|
-
rgb: wrapAnsi16m(rgb2rgb, 0)
|
|
3001
|
-
};
|
|
3002
|
-
styles.bgColor.ansi = {
|
|
3003
|
-
ansi: wrapAnsi16(ansi2ansi, 10)
|
|
3004
|
-
};
|
|
3005
|
-
styles.bgColor.ansi256 = {
|
|
3006
|
-
ansi256: wrapAnsi256(ansi2ansi, 10)
|
|
3007
|
-
};
|
|
3008
|
-
styles.bgColor.ansi16m = {
|
|
3009
|
-
rgb: wrapAnsi16m(rgb2rgb, 10)
|
|
3010
|
-
};
|
|
3011
|
-
for (let key of Object.keys(colorConvert)) {
|
|
3012
|
-
if (typeof colorConvert[key] !== "object") {
|
|
3013
|
-
continue;
|
|
3014
|
-
}
|
|
3015
|
-
const suite = colorConvert[key];
|
|
3016
|
-
if (key === "ansi16") {
|
|
3017
|
-
key = "ansi";
|
|
3018
|
-
}
|
|
3019
|
-
if ("ansi16" in suite) {
|
|
3020
|
-
styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
|
|
3021
|
-
styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
|
|
3022
|
-
}
|
|
3023
|
-
if ("ansi256" in suite) {
|
|
3024
|
-
styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
|
|
3025
|
-
styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
|
|
3026
|
-
}
|
|
3027
|
-
if ("rgb" in suite) {
|
|
3028
|
-
styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
|
|
3029
|
-
styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
|
|
3030
|
-
}
|
|
3031
|
-
}
|
|
1120
|
+
setLazyProperty(styles.color, "ansi", () => makeDynamicStyles(wrapAnsi16, "ansi16", ansi2ansi, false));
|
|
1121
|
+
setLazyProperty(styles.color, "ansi256", () => makeDynamicStyles(wrapAnsi256, "ansi256", ansi2ansi, false));
|
|
1122
|
+
setLazyProperty(styles.color, "ansi16m", () => makeDynamicStyles(wrapAnsi16m, "rgb", rgb2rgb, false));
|
|
1123
|
+
setLazyProperty(styles.bgColor, "ansi", () => makeDynamicStyles(wrapAnsi16, "ansi16", ansi2ansi, true));
|
|
1124
|
+
setLazyProperty(styles.bgColor, "ansi256", () => makeDynamicStyles(wrapAnsi256, "ansi256", ansi2ansi, true));
|
|
1125
|
+
setLazyProperty(styles.bgColor, "ansi16m", () => makeDynamicStyles(wrapAnsi16m, "rgb", rgb2rgb, true));
|
|
3032
1126
|
return styles;
|
|
3033
1127
|
}
|
|
3034
1128
|
Object.defineProperty(module, "exports", {
|
|
@@ -3038,35 +1132,41 @@ var require_ansi_styles = __commonJS({
|
|
|
3038
1132
|
}
|
|
3039
1133
|
});
|
|
3040
1134
|
|
|
3041
|
-
//
|
|
1135
|
+
// node_modules/has-flag/index.js
|
|
3042
1136
|
var require_has_flag = __commonJS({
|
|
3043
|
-
"
|
|
1137
|
+
"node_modules/has-flag/index.js"(exports, module) {
|
|
3044
1138
|
"use strict";
|
|
3045
|
-
module.exports = (flag, argv) => {
|
|
3046
|
-
argv = argv || process.argv;
|
|
1139
|
+
module.exports = (flag, argv = process.argv) => {
|
|
3047
1140
|
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
3048
|
-
const
|
|
3049
|
-
const
|
|
3050
|
-
return
|
|
1141
|
+
const position = argv.indexOf(prefix + flag);
|
|
1142
|
+
const terminatorPosition = argv.indexOf("--");
|
|
1143
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
3051
1144
|
};
|
|
3052
1145
|
}
|
|
3053
1146
|
});
|
|
3054
1147
|
|
|
3055
|
-
//
|
|
1148
|
+
// node_modules/supports-color/index.js
|
|
3056
1149
|
var require_supports_color = __commonJS({
|
|
3057
|
-
"
|
|
1150
|
+
"node_modules/supports-color/index.js"(exports, module) {
|
|
3058
1151
|
"use strict";
|
|
3059
1152
|
var os = __require("os");
|
|
1153
|
+
var tty = __require("tty");
|
|
3060
1154
|
var hasFlag = require_has_flag();
|
|
3061
|
-
var env = process
|
|
1155
|
+
var { env } = process;
|
|
3062
1156
|
var forceColor;
|
|
3063
|
-
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false")) {
|
|
3064
|
-
forceColor =
|
|
1157
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
1158
|
+
forceColor = 0;
|
|
3065
1159
|
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
3066
|
-
forceColor =
|
|
1160
|
+
forceColor = 1;
|
|
3067
1161
|
}
|
|
3068
1162
|
if ("FORCE_COLOR" in env) {
|
|
3069
|
-
|
|
1163
|
+
if (env.FORCE_COLOR === "true") {
|
|
1164
|
+
forceColor = 1;
|
|
1165
|
+
} else if (env.FORCE_COLOR === "false") {
|
|
1166
|
+
forceColor = 0;
|
|
1167
|
+
} else {
|
|
1168
|
+
forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
|
|
1169
|
+
}
|
|
3070
1170
|
}
|
|
3071
1171
|
function translateLevel(level) {
|
|
3072
1172
|
if (level === 0) {
|
|
@@ -3079,8 +1179,8 @@ var require_supports_color = __commonJS({
|
|
|
3079
1179
|
has16m: level >= 3
|
|
3080
1180
|
};
|
|
3081
1181
|
}
|
|
3082
|
-
function supportsColor(
|
|
3083
|
-
if (forceColor ===
|
|
1182
|
+
function supportsColor(haveStream, streamIsTTY) {
|
|
1183
|
+
if (forceColor === 0) {
|
|
3084
1184
|
return 0;
|
|
3085
1185
|
}
|
|
3086
1186
|
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
@@ -3089,19 +1189,22 @@ var require_supports_color = __commonJS({
|
|
|
3089
1189
|
if (hasFlag("color=256")) {
|
|
3090
1190
|
return 2;
|
|
3091
1191
|
}
|
|
3092
|
-
if (
|
|
1192
|
+
if (haveStream && !streamIsTTY && forceColor === void 0) {
|
|
3093
1193
|
return 0;
|
|
3094
1194
|
}
|
|
3095
|
-
const min = forceColor
|
|
1195
|
+
const min = forceColor || 0;
|
|
1196
|
+
if (env.TERM === "dumb") {
|
|
1197
|
+
return min;
|
|
1198
|
+
}
|
|
3096
1199
|
if (process.platform === "win32") {
|
|
3097
1200
|
const osRelease = os.release().split(".");
|
|
3098
|
-
if (Number(
|
|
1201
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
3099
1202
|
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
3100
1203
|
}
|
|
3101
1204
|
return 1;
|
|
3102
1205
|
}
|
|
3103
1206
|
if ("CI" in env) {
|
|
3104
|
-
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
|
1207
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
|
3105
1208
|
return 1;
|
|
3106
1209
|
}
|
|
3107
1210
|
return min;
|
|
@@ -3130,31 +1233,67 @@ var require_supports_color = __commonJS({
|
|
|
3130
1233
|
if ("COLORTERM" in env) {
|
|
3131
1234
|
return 1;
|
|
3132
1235
|
}
|
|
3133
|
-
if (env.TERM === "dumb") {
|
|
3134
|
-
return min;
|
|
3135
|
-
}
|
|
3136
1236
|
return min;
|
|
3137
1237
|
}
|
|
3138
1238
|
function getSupportLevel(stream) {
|
|
3139
|
-
const level = supportsColor(stream);
|
|
1239
|
+
const level = supportsColor(stream, stream && stream.isTTY);
|
|
3140
1240
|
return translateLevel(level);
|
|
3141
1241
|
}
|
|
3142
1242
|
module.exports = {
|
|
3143
1243
|
supportsColor: getSupportLevel,
|
|
3144
|
-
stdout:
|
|
3145
|
-
stderr:
|
|
1244
|
+
stdout: translateLevel(supportsColor(true, tty.isatty(1))),
|
|
1245
|
+
stderr: translateLevel(supportsColor(true, tty.isatty(2)))
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
1249
|
+
|
|
1250
|
+
// node_modules/chalk/source/util.js
|
|
1251
|
+
var require_util = __commonJS({
|
|
1252
|
+
"node_modules/chalk/source/util.js"(exports, module) {
|
|
1253
|
+
"use strict";
|
|
1254
|
+
var stringReplaceAll = (string, substring, replacer) => {
|
|
1255
|
+
let index = string.indexOf(substring);
|
|
1256
|
+
if (index === -1) {
|
|
1257
|
+
return string;
|
|
1258
|
+
}
|
|
1259
|
+
const substringLength = substring.length;
|
|
1260
|
+
let endIndex = 0;
|
|
1261
|
+
let returnValue = "";
|
|
1262
|
+
do {
|
|
1263
|
+
returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
|
|
1264
|
+
endIndex = index + substringLength;
|
|
1265
|
+
index = string.indexOf(substring, endIndex);
|
|
1266
|
+
} while (index !== -1);
|
|
1267
|
+
returnValue += string.substr(endIndex);
|
|
1268
|
+
return returnValue;
|
|
1269
|
+
};
|
|
1270
|
+
var stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
|
|
1271
|
+
let endIndex = 0;
|
|
1272
|
+
let returnValue = "";
|
|
1273
|
+
do {
|
|
1274
|
+
const gotCR = string[index - 1] === "\r";
|
|
1275
|
+
returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
|
|
1276
|
+
endIndex = index + 1;
|
|
1277
|
+
index = string.indexOf("\n", endIndex);
|
|
1278
|
+
} while (index !== -1);
|
|
1279
|
+
returnValue += string.substr(endIndex);
|
|
1280
|
+
return returnValue;
|
|
1281
|
+
};
|
|
1282
|
+
module.exports = {
|
|
1283
|
+
stringReplaceAll,
|
|
1284
|
+
stringEncaseCRLFWithFirstIndex
|
|
3146
1285
|
};
|
|
3147
1286
|
}
|
|
3148
1287
|
});
|
|
3149
1288
|
|
|
3150
|
-
//
|
|
1289
|
+
// node_modules/chalk/source/templates.js
|
|
3151
1290
|
var require_templates = __commonJS({
|
|
3152
|
-
"
|
|
1291
|
+
"node_modules/chalk/source/templates.js"(exports, module) {
|
|
3153
1292
|
"use strict";
|
|
3154
|
-
var TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
|
|
1293
|
+
var TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
|
|
3155
1294
|
var STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
|
|
3156
1295
|
var STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
|
|
3157
|
-
var ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
|
|
1296
|
+
var ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
|
|
3158
1297
|
var ESCAPES = /* @__PURE__ */ new Map([
|
|
3159
1298
|
["n", "\n"],
|
|
3160
1299
|
["r", "\r"],
|
|
@@ -3168,20 +1307,26 @@ var require_templates = __commonJS({
|
|
|
3168
1307
|
["a", "\x07"]
|
|
3169
1308
|
]);
|
|
3170
1309
|
function unescape(c) {
|
|
3171
|
-
|
|
1310
|
+
const u = c[0] === "u";
|
|
1311
|
+
const bracket = c[1] === "{";
|
|
1312
|
+
if (u && !bracket && c.length === 5 || c[0] === "x" && c.length === 3) {
|
|
3172
1313
|
return String.fromCharCode(parseInt(c.slice(1), 16));
|
|
3173
1314
|
}
|
|
1315
|
+
if (u && bracket) {
|
|
1316
|
+
return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
|
|
1317
|
+
}
|
|
3174
1318
|
return ESCAPES.get(c) || c;
|
|
3175
1319
|
}
|
|
3176
|
-
function parseArguments(name,
|
|
1320
|
+
function parseArguments(name, arguments_) {
|
|
3177
1321
|
const results = [];
|
|
3178
|
-
const chunks =
|
|
1322
|
+
const chunks = arguments_.trim().split(/\s*,\s*/g);
|
|
3179
1323
|
let matches;
|
|
3180
1324
|
for (const chunk of chunks) {
|
|
3181
|
-
|
|
3182
|
-
|
|
1325
|
+
const number = Number(chunk);
|
|
1326
|
+
if (!Number.isNaN(number)) {
|
|
1327
|
+
results.push(number);
|
|
3183
1328
|
} else if (matches = chunk.match(STRING_REGEX)) {
|
|
3184
|
-
results.push(matches[2].replace(ESCAPE_REGEX, (m, escape,
|
|
1329
|
+
results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, character) => escape ? unescape(escape) : character));
|
|
3185
1330
|
} else {
|
|
3186
1331
|
throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
|
|
3187
1332
|
}
|
|
@@ -3211,31 +1356,28 @@ var require_templates = __commonJS({
|
|
|
3211
1356
|
}
|
|
3212
1357
|
}
|
|
3213
1358
|
let current = chalk2;
|
|
3214
|
-
for (const styleName of Object.
|
|
3215
|
-
if (Array.isArray(
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
current = current[styleName].apply(current, enabled[styleName]);
|
|
3221
|
-
} else {
|
|
3222
|
-
current = current[styleName];
|
|
3223
|
-
}
|
|
1359
|
+
for (const [styleName, styles2] of Object.entries(enabled)) {
|
|
1360
|
+
if (!Array.isArray(styles2)) {
|
|
1361
|
+
continue;
|
|
1362
|
+
}
|
|
1363
|
+
if (!(styleName in current)) {
|
|
1364
|
+
throw new Error(`Unknown Chalk style: ${styleName}`);
|
|
3224
1365
|
}
|
|
1366
|
+
current = styles2.length > 0 ? current[styleName](...styles2) : current[styleName];
|
|
3225
1367
|
}
|
|
3226
1368
|
return current;
|
|
3227
1369
|
}
|
|
3228
|
-
module.exports = (chalk2,
|
|
1370
|
+
module.exports = (chalk2, temporary) => {
|
|
3229
1371
|
const styles = [];
|
|
3230
1372
|
const chunks = [];
|
|
3231
1373
|
let chunk = [];
|
|
3232
|
-
|
|
3233
|
-
if (
|
|
3234
|
-
chunk.push(unescape(
|
|
1374
|
+
temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
|
|
1375
|
+
if (escapeCharacter) {
|
|
1376
|
+
chunk.push(unescape(escapeCharacter));
|
|
3235
1377
|
} else if (style) {
|
|
3236
|
-
const
|
|
1378
|
+
const string = chunk.join("");
|
|
3237
1379
|
chunk = [];
|
|
3238
|
-
chunks.push(styles.length === 0 ?
|
|
1380
|
+
chunks.push(styles.length === 0 ? string : buildStyle(chalk2, styles)(string));
|
|
3239
1381
|
styles.push({ inverse, styles: parseStyle(style) });
|
|
3240
1382
|
} else if (close) {
|
|
3241
1383
|
if (styles.length === 0) {
|
|
@@ -3245,189 +1387,200 @@ var require_templates = __commonJS({
|
|
|
3245
1387
|
chunk = [];
|
|
3246
1388
|
styles.pop();
|
|
3247
1389
|
} else {
|
|
3248
|
-
chunk.push(
|
|
1390
|
+
chunk.push(character);
|
|
3249
1391
|
}
|
|
3250
1392
|
});
|
|
3251
1393
|
chunks.push(chunk.join(""));
|
|
3252
1394
|
if (styles.length > 0) {
|
|
3253
|
-
const
|
|
3254
|
-
throw new Error(
|
|
1395
|
+
const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`;
|
|
1396
|
+
throw new Error(errMessage);
|
|
3255
1397
|
}
|
|
3256
1398
|
return chunks.join("");
|
|
3257
1399
|
};
|
|
3258
1400
|
}
|
|
3259
1401
|
});
|
|
3260
1402
|
|
|
3261
|
-
//
|
|
3262
|
-
var
|
|
3263
|
-
"
|
|
1403
|
+
// node_modules/chalk/source/index.js
|
|
1404
|
+
var require_source = __commonJS({
|
|
1405
|
+
"node_modules/chalk/source/index.js"(exports, module) {
|
|
3264
1406
|
"use strict";
|
|
3265
|
-
var escapeStringRegexp = require_escape_string_regexp();
|
|
3266
1407
|
var ansiStyles = require_ansi_styles();
|
|
3267
|
-
var stdoutColor = require_supports_color()
|
|
3268
|
-
var
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
1408
|
+
var { stdout: stdoutColor, stderr: stderrColor } = require_supports_color();
|
|
1409
|
+
var {
|
|
1410
|
+
stringReplaceAll,
|
|
1411
|
+
stringEncaseCRLFWithFirstIndex
|
|
1412
|
+
} = require_util();
|
|
1413
|
+
var { isArray } = Array;
|
|
1414
|
+
var levelMapping = [
|
|
1415
|
+
"ansi",
|
|
1416
|
+
"ansi",
|
|
1417
|
+
"ansi256",
|
|
1418
|
+
"ansi16m"
|
|
1419
|
+
];
|
|
3272
1420
|
var styles = /* @__PURE__ */ Object.create(null);
|
|
3273
|
-
|
|
3274
|
-
options
|
|
3275
|
-
|
|
3276
|
-
obj.level = options.level === void 0 ? scLevel : options.level;
|
|
3277
|
-
obj.enabled = "enabled" in options ? options.enabled : obj.level > 0;
|
|
3278
|
-
}
|
|
3279
|
-
function Chalk(options) {
|
|
3280
|
-
if (!this || !(this instanceof Chalk) || this.template) {
|
|
3281
|
-
const chalk2 = {};
|
|
3282
|
-
applyOptions(chalk2, options);
|
|
3283
|
-
chalk2.template = function() {
|
|
3284
|
-
const args = [].slice.call(arguments);
|
|
3285
|
-
return chalkTag.apply(null, [chalk2.template].concat(args));
|
|
3286
|
-
};
|
|
3287
|
-
Object.setPrototypeOf(chalk2, Chalk.prototype);
|
|
3288
|
-
Object.setPrototypeOf(chalk2.template, chalk2);
|
|
3289
|
-
chalk2.template.constructor = Chalk;
|
|
3290
|
-
return chalk2.template;
|
|
1421
|
+
var applyOptions = (object, options = {}) => {
|
|
1422
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
1423
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
3291
1424
|
}
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
1425
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
1426
|
+
object.level = options.level === void 0 ? colorLevel : options.level;
|
|
1427
|
+
};
|
|
1428
|
+
var ChalkClass = class {
|
|
1429
|
+
constructor(options) {
|
|
1430
|
+
return chalkFactory(options);
|
|
1431
|
+
}
|
|
1432
|
+
};
|
|
1433
|
+
var chalkFactory = (options) => {
|
|
1434
|
+
const chalk3 = {};
|
|
1435
|
+
applyOptions(chalk3, options);
|
|
1436
|
+
chalk3.template = (...arguments_) => chalkTag(chalk3.template, ...arguments_);
|
|
1437
|
+
Object.setPrototypeOf(chalk3, Chalk.prototype);
|
|
1438
|
+
Object.setPrototypeOf(chalk3.template, chalk3);
|
|
1439
|
+
chalk3.template.constructor = () => {
|
|
1440
|
+
throw new Error("`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.");
|
|
1441
|
+
};
|
|
1442
|
+
chalk3.template.Instance = ChalkClass;
|
|
1443
|
+
return chalk3.template;
|
|
1444
|
+
};
|
|
1445
|
+
function Chalk(options) {
|
|
1446
|
+
return chalkFactory(options);
|
|
3296
1447
|
}
|
|
3297
|
-
for (const
|
|
3298
|
-
|
|
3299
|
-
styles[key] = {
|
|
1448
|
+
for (const [styleName, style] of Object.entries(ansiStyles)) {
|
|
1449
|
+
styles[styleName] = {
|
|
3300
1450
|
get() {
|
|
3301
|
-
const
|
|
3302
|
-
|
|
1451
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
|
|
1452
|
+
Object.defineProperty(this, styleName, { value: builder });
|
|
1453
|
+
return builder;
|
|
3303
1454
|
}
|
|
3304
1455
|
};
|
|
3305
1456
|
}
|
|
3306
1457
|
styles.visible = {
|
|
3307
1458
|
get() {
|
|
3308
|
-
|
|
1459
|
+
const builder = createBuilder(this, this._styler, true);
|
|
1460
|
+
Object.defineProperty(this, "visible", { value: builder });
|
|
1461
|
+
return builder;
|
|
3309
1462
|
}
|
|
3310
1463
|
};
|
|
3311
|
-
|
|
3312
|
-
for (const model of
|
|
3313
|
-
if (skipModels.has(model)) {
|
|
3314
|
-
continue;
|
|
3315
|
-
}
|
|
1464
|
+
var usedModels = ["rgb", "hex", "keyword", "hsl", "hsv", "hwb", "ansi", "ansi256"];
|
|
1465
|
+
for (const model of usedModels) {
|
|
3316
1466
|
styles[model] = {
|
|
3317
1467
|
get() {
|
|
3318
|
-
const level = this
|
|
3319
|
-
return function() {
|
|
3320
|
-
const
|
|
3321
|
-
|
|
3322
|
-
open,
|
|
3323
|
-
close: ansiStyles.color.close,
|
|
3324
|
-
closeRe: ansiStyles.color.closeRe
|
|
3325
|
-
};
|
|
3326
|
-
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
|
|
1468
|
+
const { level } = this;
|
|
1469
|
+
return function(...arguments_) {
|
|
1470
|
+
const styler = createStyler(ansiStyles.color[levelMapping[level]][model](...arguments_), ansiStyles.color.close, this._styler);
|
|
1471
|
+
return createBuilder(this, styler, this._isEmpty);
|
|
3327
1472
|
};
|
|
3328
1473
|
}
|
|
3329
1474
|
};
|
|
3330
1475
|
}
|
|
3331
|
-
|
|
3332
|
-
for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
|
|
3333
|
-
if (skipModels.has(model)) {
|
|
3334
|
-
continue;
|
|
3335
|
-
}
|
|
1476
|
+
for (const model of usedModels) {
|
|
3336
1477
|
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
3337
1478
|
styles[bgModel] = {
|
|
3338
1479
|
get() {
|
|
3339
|
-
const level = this
|
|
3340
|
-
return function() {
|
|
3341
|
-
const
|
|
3342
|
-
|
|
3343
|
-
open,
|
|
3344
|
-
close: ansiStyles.bgColor.close,
|
|
3345
|
-
closeRe: ansiStyles.bgColor.closeRe
|
|
3346
|
-
};
|
|
3347
|
-
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
|
|
1480
|
+
const { level } = this;
|
|
1481
|
+
return function(...arguments_) {
|
|
1482
|
+
const styler = createStyler(ansiStyles.bgColor[levelMapping[level]][model](...arguments_), ansiStyles.bgColor.close, this._styler);
|
|
1483
|
+
return createBuilder(this, styler, this._isEmpty);
|
|
3348
1484
|
};
|
|
3349
1485
|
}
|
|
3350
1486
|
};
|
|
3351
1487
|
}
|
|
3352
1488
|
var proto = Object.defineProperties(() => {
|
|
3353
|
-
},
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
return applyStyle.apply(builder, arguments);
|
|
3357
|
-
};
|
|
3358
|
-
builder._styles = _styles;
|
|
3359
|
-
builder._empty = _empty;
|
|
3360
|
-
const self = this;
|
|
3361
|
-
Object.defineProperty(builder, "level", {
|
|
1489
|
+
}, {
|
|
1490
|
+
...styles,
|
|
1491
|
+
level: {
|
|
3362
1492
|
enumerable: true,
|
|
3363
1493
|
get() {
|
|
3364
|
-
return
|
|
1494
|
+
return this._generator.level;
|
|
3365
1495
|
},
|
|
3366
1496
|
set(level) {
|
|
3367
|
-
|
|
1497
|
+
this._generator.level = level;
|
|
3368
1498
|
}
|
|
3369
|
-
}
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
1499
|
+
}
|
|
1500
|
+
});
|
|
1501
|
+
var createStyler = (open, close, parent) => {
|
|
1502
|
+
let openAll;
|
|
1503
|
+
let closeAll;
|
|
1504
|
+
if (parent === void 0) {
|
|
1505
|
+
openAll = open;
|
|
1506
|
+
closeAll = close;
|
|
1507
|
+
} else {
|
|
1508
|
+
openAll = parent.openAll + open;
|
|
1509
|
+
closeAll = close + parent.closeAll;
|
|
1510
|
+
}
|
|
1511
|
+
return {
|
|
1512
|
+
open,
|
|
1513
|
+
close,
|
|
1514
|
+
openAll,
|
|
1515
|
+
closeAll,
|
|
1516
|
+
parent
|
|
1517
|
+
};
|
|
1518
|
+
};
|
|
1519
|
+
var createBuilder = (self, _styler, _isEmpty) => {
|
|
1520
|
+
const builder = (...arguments_) => {
|
|
1521
|
+
if (isArray(arguments_[0]) && isArray(arguments_[0].raw)) {
|
|
1522
|
+
return applyStyle(builder, chalkTag(builder, ...arguments_));
|
|
3377
1523
|
}
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
builder
|
|
1524
|
+
return applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
1525
|
+
};
|
|
1526
|
+
Object.setPrototypeOf(builder, proto);
|
|
1527
|
+
builder._generator = self;
|
|
1528
|
+
builder._styler = _styler;
|
|
1529
|
+
builder._isEmpty = _isEmpty;
|
|
3381
1530
|
return builder;
|
|
3382
|
-
}
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
let str = String(arguments[0]);
|
|
3387
|
-
if (argsLen === 0) {
|
|
3388
|
-
return "";
|
|
3389
|
-
}
|
|
3390
|
-
if (argsLen > 1) {
|
|
3391
|
-
for (let a = 1; a < argsLen; a++) {
|
|
3392
|
-
str += " " + args[a];
|
|
3393
|
-
}
|
|
1531
|
+
};
|
|
1532
|
+
var applyStyle = (self, string) => {
|
|
1533
|
+
if (self.level <= 0 || !string) {
|
|
1534
|
+
return self._isEmpty ? "" : string;
|
|
3394
1535
|
}
|
|
3395
|
-
|
|
3396
|
-
|
|
1536
|
+
let styler = self._styler;
|
|
1537
|
+
if (styler === void 0) {
|
|
1538
|
+
return string;
|
|
3397
1539
|
}
|
|
3398
|
-
const
|
|
3399
|
-
if (
|
|
3400
|
-
|
|
1540
|
+
const { openAll, closeAll } = styler;
|
|
1541
|
+
if (string.indexOf("\x1B") !== -1) {
|
|
1542
|
+
while (styler !== void 0) {
|
|
1543
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
1544
|
+
styler = styler.parent;
|
|
1545
|
+
}
|
|
3401
1546
|
}
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
1547
|
+
const lfIndex = string.indexOf("\n");
|
|
1548
|
+
if (lfIndex !== -1) {
|
|
1549
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
3405
1550
|
}
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
1551
|
+
return openAll + string + closeAll;
|
|
1552
|
+
};
|
|
1553
|
+
var template;
|
|
1554
|
+
var chalkTag = (chalk3, ...strings) => {
|
|
1555
|
+
const [firstString] = strings;
|
|
1556
|
+
if (!isArray(firstString) || !isArray(firstString.raw)) {
|
|
1557
|
+
return strings.join(" ");
|
|
1558
|
+
}
|
|
1559
|
+
const arguments_ = strings.slice(1);
|
|
1560
|
+
const parts = [firstString.raw[0]];
|
|
1561
|
+
for (let i = 1; i < firstString.length; i++) {
|
|
1562
|
+
parts.push(
|
|
1563
|
+
String(arguments_[i - 1]).replace(/[{}\\]/g, "\\$&"),
|
|
1564
|
+
String(firstString.raw[i])
|
|
1565
|
+
);
|
|
3412
1566
|
}
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
for (let i = 1; i < strings.length; i++) {
|
|
3416
|
-
parts.push(String(args[i - 1]).replace(/[{}\\]/g, "\\$&"));
|
|
3417
|
-
parts.push(String(strings.raw[i]));
|
|
1567
|
+
if (template === void 0) {
|
|
1568
|
+
template = require_templates();
|
|
3418
1569
|
}
|
|
3419
|
-
return template(
|
|
3420
|
-
}
|
|
1570
|
+
return template(chalk3, parts.join(""));
|
|
1571
|
+
};
|
|
3421
1572
|
Object.defineProperties(Chalk.prototype, styles);
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
1573
|
+
var chalk2 = Chalk();
|
|
1574
|
+
chalk2.supportsColor = stdoutColor;
|
|
1575
|
+
chalk2.stderr = Chalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
1576
|
+
chalk2.stderr.supportsColor = stderrColor;
|
|
1577
|
+
module.exports = chalk2;
|
|
3425
1578
|
}
|
|
3426
1579
|
});
|
|
3427
1580
|
|
|
3428
1581
|
// src/index.ts
|
|
3429
|
-
var
|
|
3430
|
-
|
|
1582
|
+
var import_chalk = __toESM(require_source(), 1);
|
|
1583
|
+
import { Command } from "commander";
|
|
3431
1584
|
import semver from "semver";
|
|
3432
1585
|
import {
|
|
3433
1586
|
createNodeApp,
|
|
@@ -3464,7 +1617,10 @@ var getTemplateData = async () => {
|
|
|
3464
1617
|
}
|
|
3465
1618
|
return templateDataCache.data;
|
|
3466
1619
|
};
|
|
3467
|
-
var getTemplateCategories = async () => {
|
|
1620
|
+
var getTemplateCategories = async (cliArgs) => {
|
|
1621
|
+
if (cliArgs == null ? void 0 : cliArgs.category) {
|
|
1622
|
+
return [cliArgs.category];
|
|
1623
|
+
}
|
|
3468
1624
|
const templateData = await getTemplateData();
|
|
3469
1625
|
const categories = /* @__PURE__ */ new Set();
|
|
3470
1626
|
templateData.templates.forEach((template) => {
|
|
@@ -3472,15 +1628,20 @@ var getTemplateCategories = async () => {
|
|
|
3472
1628
|
});
|
|
3473
1629
|
return Array.from(categories);
|
|
3474
1630
|
};
|
|
3475
|
-
var getTemplatesForCategory = async (category) => {
|
|
1631
|
+
var getTemplatesForCategory = async (category, cliArgs) => {
|
|
1632
|
+
const selectedCategory = (cliArgs == null ? void 0 : cliArgs.category) || category;
|
|
1633
|
+
if (!selectedCategory) {
|
|
1634
|
+
throw new Error("Category is required in non-interactive mode.");
|
|
1635
|
+
}
|
|
3476
1636
|
const templateData = await getTemplateData();
|
|
3477
1637
|
const templates = templateData.templates.filter(
|
|
3478
|
-
(template) => template.category ===
|
|
1638
|
+
(template) => template.category === selectedCategory
|
|
3479
1639
|
);
|
|
3480
1640
|
return templates;
|
|
3481
1641
|
};
|
|
3482
|
-
var getExtensionsGroupedByCategory = async (type) => {
|
|
3483
|
-
const
|
|
1642
|
+
var getExtensionsGroupedByCategory = async (type, cliArgs) => {
|
|
1643
|
+
const selectedType = (cliArgs == null ? void 0 : cliArgs.type) ? cliArgs.type.split(",") : type;
|
|
1644
|
+
const safeType = Array.isArray(selectedType) ? selectedType : [selectedType];
|
|
3484
1645
|
const templateData = await getTemplateData();
|
|
3485
1646
|
const extensions = templateData.extensions.filter((extension) => {
|
|
3486
1647
|
const safeExtensionType = Array.isArray(extension.type) ? extension.type : [extension.type];
|
|
@@ -3502,14 +1663,67 @@ var getExtensionsGroupedByCategory = async (type) => {
|
|
|
3502
1663
|
// src/options.ts
|
|
3503
1664
|
prompts.override(yargs.argv);
|
|
3504
1665
|
var PACKAGE_MANAGERS = ["npm", "yarn", "pnpm"];
|
|
1666
|
+
var isValidUrl = (url) => {
|
|
1667
|
+
try {
|
|
1668
|
+
new URL(url);
|
|
1669
|
+
return true;
|
|
1670
|
+
} catch {
|
|
1671
|
+
return false;
|
|
1672
|
+
}
|
|
1673
|
+
};
|
|
3505
1674
|
var getCnaOptions = async (options) => {
|
|
3506
|
-
|
|
1675
|
+
const categories = await getTemplateCategories();
|
|
1676
|
+
if (isCI || !options.interactive) {
|
|
1677
|
+
let matchedTemplate;
|
|
1678
|
+
if (options.template && !isValidUrl(options.template)) {
|
|
1679
|
+
const allTemplates = (await Promise.all(
|
|
1680
|
+
categories.map((category) => getTemplatesForCategory(category))
|
|
1681
|
+
)).flat();
|
|
1682
|
+
matchedTemplate = allTemplates.find(
|
|
1683
|
+
(template) => template.slug === options.template
|
|
1684
|
+
);
|
|
1685
|
+
if (matchedTemplate) {
|
|
1686
|
+
options.template = matchedTemplate.url;
|
|
1687
|
+
if (matchedTemplate.customOptions) {
|
|
1688
|
+
matchedTemplate.customOptions.forEach((customOption) => {
|
|
1689
|
+
if (customOption.name && customOption.initial !== void 0) {
|
|
1690
|
+
options[customOption.name] = customOption.initial;
|
|
1691
|
+
}
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1694
|
+
} else {
|
|
1695
|
+
throw new Error(
|
|
1696
|
+
`Invalid template slug: '${options.template}'. Please provide a valid template slug.`
|
|
1697
|
+
);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
if (options.addons && Array.isArray(options.addons)) {
|
|
1701
|
+
const extensionsGroupedByCategory2 = await getExtensionsGroupedByCategory([
|
|
1702
|
+
(matchedTemplate == null ? void 0 : matchedTemplate.type) || "custom",
|
|
1703
|
+
"all"
|
|
1704
|
+
]);
|
|
1705
|
+
options.addons = options.addons.map((addon) => {
|
|
1706
|
+
if (!isValidUrl(addon)) {
|
|
1707
|
+
for (const extensions of Object.values(extensionsGroupedByCategory2)) {
|
|
1708
|
+
const matchedExtension = extensions.find(
|
|
1709
|
+
(extension) => extension.slug === addon
|
|
1710
|
+
);
|
|
1711
|
+
if (matchedExtension) {
|
|
1712
|
+
return matchedExtension.url;
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
throw new Error(
|
|
1716
|
+
`Invalid extension slug: '${addon}'. Please provide a valid extension slug.`
|
|
1717
|
+
);
|
|
1718
|
+
}
|
|
1719
|
+
return addon;
|
|
1720
|
+
});
|
|
1721
|
+
}
|
|
3507
1722
|
if (options.verbose) {
|
|
3508
1723
|
console.log(JSON.stringify(options, null, 2));
|
|
3509
1724
|
}
|
|
3510
1725
|
return options;
|
|
3511
1726
|
}
|
|
3512
|
-
const categories = await getTemplateCategories();
|
|
3513
1727
|
const categoriesOptions = [
|
|
3514
1728
|
...categories.map((category) => ({
|
|
3515
1729
|
title: category,
|
|
@@ -3668,7 +1882,7 @@ var getCnaOptions = async (options) => {
|
|
|
3668
1882
|
// package.json
|
|
3669
1883
|
var package_default = {
|
|
3670
1884
|
name: "create-awesome-node-app",
|
|
3671
|
-
version: "0.4.
|
|
1885
|
+
version: "0.4.26",
|
|
3672
1886
|
type: "module",
|
|
3673
1887
|
description: "Command line tool to create Node apps with a lot of different templates and extensions.",
|
|
3674
1888
|
license: "MIT",
|
|
@@ -3715,36 +1929,42 @@ var package_default = {
|
|
|
3715
1929
|
dependencies: {
|
|
3716
1930
|
"@create-node-app/core": "*",
|
|
3717
1931
|
axios: "^1.6.0",
|
|
3718
|
-
"ci-info": "^
|
|
1932
|
+
"ci-info": "^4.0.0",
|
|
1933
|
+
commander: "^13.1.0",
|
|
3719
1934
|
prompts: "^2.4.1",
|
|
3720
|
-
semver: "^5.
|
|
1935
|
+
semver: "^7.5.2",
|
|
3721
1936
|
yargs: "^17.0.1"
|
|
3722
1937
|
},
|
|
3723
1938
|
devDependencies: {
|
|
3724
1939
|
"@create-node-app/eslint-config-ts": "*",
|
|
3725
1940
|
"@types/node": "^18.14.6",
|
|
3726
|
-
"@types/prompts": "^2.4.
|
|
1941
|
+
"@types/prompts": "^2.4.9",
|
|
3727
1942
|
"@types/yargs": "^17.0.22",
|
|
3728
|
-
eslint: "^7.
|
|
3729
|
-
|
|
1943
|
+
eslint: "^7.23.0",
|
|
1944
|
+
"eslint-config-turbo": "^0.0.4",
|
|
1945
|
+
tsup: "^6.2.3",
|
|
1946
|
+
"eslint-plugin-turbo": "^0.0.4"
|
|
3730
1947
|
}
|
|
3731
1948
|
};
|
|
3732
1949
|
|
|
3733
1950
|
// src/index.ts
|
|
1951
|
+
var program = new Command();
|
|
3734
1952
|
var main = async () => {
|
|
3735
1953
|
let projectName = "my-project";
|
|
3736
|
-
|
|
3737
|
-
projectName = name || projectName;
|
|
3738
|
-
}).option("--verbose", "print additional logs").option("--info", "print environment debug info").option(
|
|
1954
|
+
program.version(package_default.version).arguments("[project-directory]").usage(`${import_chalk.default.green("[project-directory]")} [options]`).option("-v, --verbose", "print additional logs").option("-i, --info", "print environment debug info").option(
|
|
3739
1955
|
"--no-install",
|
|
3740
1956
|
"Generate package.json without installing dependencies"
|
|
3741
1957
|
).option(
|
|
3742
|
-
"--template <template>",
|
|
1958
|
+
"-t, --template <template>",
|
|
3743
1959
|
"specify a template for the created project"
|
|
3744
1960
|
).option(
|
|
3745
|
-
"--
|
|
1961
|
+
"--addons [extensions...]",
|
|
3746
1962
|
"specify extensions to apply for the boilerplate generation"
|
|
3747
|
-
).option("--use-yarn", "use yarn instead of npm or pnpm").option("--use-pnpm", "use pnpm instead of yarn or npm").
|
|
1963
|
+
).option("--use-yarn", "use yarn instead of npm or pnpm").option("--use-pnpm", "use pnpm instead of yarn or npm").option("--interactive", "run in interactive mode to select options", false).action((providedProjectName) => {
|
|
1964
|
+
projectName = providedProjectName || projectName;
|
|
1965
|
+
});
|
|
1966
|
+
program.parse(process.argv);
|
|
1967
|
+
const opts = program.opts();
|
|
3748
1968
|
checkNodeVersion(package_default.engines.node, package_default.name);
|
|
3749
1969
|
const latest = await checkForLatestVersion("create-awesome-node-app");
|
|
3750
1970
|
if (latest && semver.lt(package_default.version, latest)) {
|
|
@@ -3758,14 +1978,20 @@ We recommend always using the latest version of create-awesome-node-app if possi
|
|
|
3758
1978
|
);
|
|
3759
1979
|
return;
|
|
3760
1980
|
}
|
|
3761
|
-
const
|
|
1981
|
+
const options = await getCnaOptions({ ...opts, projectName });
|
|
1982
|
+
const { useYarn, usePnpm, ...restOptions } = options;
|
|
3762
1983
|
const packageManager = useYarn ? "yarn" : usePnpm ? "pnpm" : "npm";
|
|
3763
|
-
const templatesOrExtensions = [
|
|
3764
|
-
|
|
3765
|
-
|
|
1984
|
+
const templatesOrExtensions = [restOptions.template].concat(Array.isArray(restOptions.addons) ? restOptions.addons : []).concat(Array.isArray(restOptions.extend) ? restOptions.extend : []).reduce((acc, templateOrExtension) => {
|
|
1985
|
+
if (!templateOrExtension) {
|
|
1986
|
+
return acc;
|
|
1987
|
+
}
|
|
1988
|
+
return acc.concat({
|
|
1989
|
+
url: templateOrExtension
|
|
1990
|
+
});
|
|
1991
|
+
}, []);
|
|
3766
1992
|
return createNodeApp(
|
|
3767
1993
|
projectName,
|
|
3768
|
-
{ ...
|
|
1994
|
+
{ ...restOptions, packageManager, templatesOrExtensions, projectName },
|
|
3769
1995
|
getCnaOptions
|
|
3770
1996
|
);
|
|
3771
1997
|
};
|