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