@abelionorg/tagger-public 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -0
- package/TUTORIAL.md +41 -0
- package/dist/benchmark.d.ts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +3778 -0
- package/dist/commands/keygen.d.ts +1 -0
- package/dist/commands/tag.d.ts +1 -0
- package/dist/commands/verify.d.ts +1 -0
- package/dist/crypto.d.ts +21 -0
- package/dist/drivers/cpp.d.ts +1 -0
- package/dist/drivers/css.d.ts +1 -0
- package/dist/drivers/html.d.ts +6 -0
- package/dist/drivers/javascript.d.ts +6 -0
- package/dist/drivers/php.d.ts +6 -0
- package/dist/drivers/python.d.ts +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +260 -0
- package/dist/logger.d.ts +1 -0
- package/dist/stealth.d.ts +21 -0
- package/dist/stealth.test.d.ts +1 -0
- package/dist/utils.d.ts +4 -0
- package/package.json +63 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,3778 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
20
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
for (let key of __getOwnPropNames(mod))
|
|
23
|
+
if (!__hasOwnProp.call(to, key))
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
26
|
+
enumerable: true
|
|
27
|
+
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
33
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
34
|
+
|
|
35
|
+
// ../../node_modules/commander/lib/error.js
|
|
36
|
+
var require_error = __commonJS((exports) => {
|
|
37
|
+
class CommanderError extends Error {
|
|
38
|
+
constructor(exitCode, code, message) {
|
|
39
|
+
super(message);
|
|
40
|
+
Error.captureStackTrace(this, this.constructor);
|
|
41
|
+
this.name = this.constructor.name;
|
|
42
|
+
this.code = code;
|
|
43
|
+
this.exitCode = exitCode;
|
|
44
|
+
this.nestedError = undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
class InvalidArgumentError extends CommanderError {
|
|
49
|
+
constructor(message) {
|
|
50
|
+
super(1, "commander.invalidArgument", message);
|
|
51
|
+
Error.captureStackTrace(this, this.constructor);
|
|
52
|
+
this.name = this.constructor.name;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.CommanderError = CommanderError;
|
|
56
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// ../../node_modules/commander/lib/argument.js
|
|
60
|
+
var require_argument = __commonJS((exports) => {
|
|
61
|
+
var { InvalidArgumentError } = require_error();
|
|
62
|
+
|
|
63
|
+
class Argument {
|
|
64
|
+
constructor(name, description) {
|
|
65
|
+
this.description = description || "";
|
|
66
|
+
this.variadic = false;
|
|
67
|
+
this.parseArg = undefined;
|
|
68
|
+
this.defaultValue = undefined;
|
|
69
|
+
this.defaultValueDescription = undefined;
|
|
70
|
+
this.argChoices = undefined;
|
|
71
|
+
switch (name[0]) {
|
|
72
|
+
case "<":
|
|
73
|
+
this.required = true;
|
|
74
|
+
this._name = name.slice(1, -1);
|
|
75
|
+
break;
|
|
76
|
+
case "[":
|
|
77
|
+
this.required = false;
|
|
78
|
+
this._name = name.slice(1, -1);
|
|
79
|
+
break;
|
|
80
|
+
default:
|
|
81
|
+
this.required = true;
|
|
82
|
+
this._name = name;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
if (this._name.length > 3 && this._name.slice(-3) === "...") {
|
|
86
|
+
this.variadic = true;
|
|
87
|
+
this._name = this._name.slice(0, -3);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
name() {
|
|
91
|
+
return this._name;
|
|
92
|
+
}
|
|
93
|
+
_concatValue(value, previous) {
|
|
94
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
95
|
+
return [value];
|
|
96
|
+
}
|
|
97
|
+
return previous.concat(value);
|
|
98
|
+
}
|
|
99
|
+
default(value, description) {
|
|
100
|
+
this.defaultValue = value;
|
|
101
|
+
this.defaultValueDescription = description;
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
argParser(fn) {
|
|
105
|
+
this.parseArg = fn;
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
choices(values) {
|
|
109
|
+
this.argChoices = values.slice();
|
|
110
|
+
this.parseArg = (arg, previous) => {
|
|
111
|
+
if (!this.argChoices.includes(arg)) {
|
|
112
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
113
|
+
}
|
|
114
|
+
if (this.variadic) {
|
|
115
|
+
return this._concatValue(arg, previous);
|
|
116
|
+
}
|
|
117
|
+
return arg;
|
|
118
|
+
};
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
argRequired() {
|
|
122
|
+
this.required = true;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
argOptional() {
|
|
126
|
+
this.required = false;
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function humanReadableArgName(arg) {
|
|
131
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
132
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
133
|
+
}
|
|
134
|
+
exports.Argument = Argument;
|
|
135
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// ../../node_modules/commander/lib/help.js
|
|
139
|
+
var require_help = __commonJS((exports) => {
|
|
140
|
+
var { humanReadableArgName } = require_argument();
|
|
141
|
+
|
|
142
|
+
class Help {
|
|
143
|
+
constructor() {
|
|
144
|
+
this.helpWidth = undefined;
|
|
145
|
+
this.sortSubcommands = false;
|
|
146
|
+
this.sortOptions = false;
|
|
147
|
+
this.showGlobalOptions = false;
|
|
148
|
+
}
|
|
149
|
+
visibleCommands(cmd) {
|
|
150
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
151
|
+
const helpCommand = cmd._getHelpCommand();
|
|
152
|
+
if (helpCommand && !helpCommand._hidden) {
|
|
153
|
+
visibleCommands.push(helpCommand);
|
|
154
|
+
}
|
|
155
|
+
if (this.sortSubcommands) {
|
|
156
|
+
visibleCommands.sort((a, b) => {
|
|
157
|
+
return a.name().localeCompare(b.name());
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return visibleCommands;
|
|
161
|
+
}
|
|
162
|
+
compareOptions(a, b) {
|
|
163
|
+
const getSortKey = (option) => {
|
|
164
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
165
|
+
};
|
|
166
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
167
|
+
}
|
|
168
|
+
visibleOptions(cmd) {
|
|
169
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
170
|
+
const helpOption = cmd._getHelpOption();
|
|
171
|
+
if (helpOption && !helpOption.hidden) {
|
|
172
|
+
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
173
|
+
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
174
|
+
if (!removeShort && !removeLong) {
|
|
175
|
+
visibleOptions.push(helpOption);
|
|
176
|
+
} else if (helpOption.long && !removeLong) {
|
|
177
|
+
visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
|
|
178
|
+
} else if (helpOption.short && !removeShort) {
|
|
179
|
+
visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (this.sortOptions) {
|
|
183
|
+
visibleOptions.sort(this.compareOptions);
|
|
184
|
+
}
|
|
185
|
+
return visibleOptions;
|
|
186
|
+
}
|
|
187
|
+
visibleGlobalOptions(cmd) {
|
|
188
|
+
if (!this.showGlobalOptions)
|
|
189
|
+
return [];
|
|
190
|
+
const globalOptions = [];
|
|
191
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
192
|
+
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
|
|
193
|
+
globalOptions.push(...visibleOptions);
|
|
194
|
+
}
|
|
195
|
+
if (this.sortOptions) {
|
|
196
|
+
globalOptions.sort(this.compareOptions);
|
|
197
|
+
}
|
|
198
|
+
return globalOptions;
|
|
199
|
+
}
|
|
200
|
+
visibleArguments(cmd) {
|
|
201
|
+
if (cmd._argsDescription) {
|
|
202
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
203
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
207
|
+
return cmd.registeredArguments;
|
|
208
|
+
}
|
|
209
|
+
return [];
|
|
210
|
+
}
|
|
211
|
+
subcommandTerm(cmd) {
|
|
212
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
213
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
214
|
+
}
|
|
215
|
+
optionTerm(option) {
|
|
216
|
+
return option.flags;
|
|
217
|
+
}
|
|
218
|
+
argumentTerm(argument) {
|
|
219
|
+
return argument.name();
|
|
220
|
+
}
|
|
221
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
222
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
223
|
+
return Math.max(max, helper.subcommandTerm(command).length);
|
|
224
|
+
}, 0);
|
|
225
|
+
}
|
|
226
|
+
longestOptionTermLength(cmd, helper) {
|
|
227
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
228
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
229
|
+
}, 0);
|
|
230
|
+
}
|
|
231
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
232
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
233
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
234
|
+
}, 0);
|
|
235
|
+
}
|
|
236
|
+
longestArgumentTermLength(cmd, helper) {
|
|
237
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
238
|
+
return Math.max(max, helper.argumentTerm(argument).length);
|
|
239
|
+
}, 0);
|
|
240
|
+
}
|
|
241
|
+
commandUsage(cmd) {
|
|
242
|
+
let cmdName = cmd._name;
|
|
243
|
+
if (cmd._aliases[0]) {
|
|
244
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
245
|
+
}
|
|
246
|
+
let ancestorCmdNames = "";
|
|
247
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
248
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
249
|
+
}
|
|
250
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
251
|
+
}
|
|
252
|
+
commandDescription(cmd) {
|
|
253
|
+
return cmd.description();
|
|
254
|
+
}
|
|
255
|
+
subcommandDescription(cmd) {
|
|
256
|
+
return cmd.summary() || cmd.description();
|
|
257
|
+
}
|
|
258
|
+
optionDescription(option) {
|
|
259
|
+
const extraInfo = [];
|
|
260
|
+
if (option.argChoices) {
|
|
261
|
+
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
262
|
+
}
|
|
263
|
+
if (option.defaultValue !== undefined) {
|
|
264
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
265
|
+
if (showDefault) {
|
|
266
|
+
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (option.presetArg !== undefined && option.optional) {
|
|
270
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
271
|
+
}
|
|
272
|
+
if (option.envVar !== undefined) {
|
|
273
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
274
|
+
}
|
|
275
|
+
if (extraInfo.length > 0) {
|
|
276
|
+
return `${option.description} (${extraInfo.join(", ")})`;
|
|
277
|
+
}
|
|
278
|
+
return option.description;
|
|
279
|
+
}
|
|
280
|
+
argumentDescription(argument) {
|
|
281
|
+
const extraInfo = [];
|
|
282
|
+
if (argument.argChoices) {
|
|
283
|
+
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
284
|
+
}
|
|
285
|
+
if (argument.defaultValue !== undefined) {
|
|
286
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
287
|
+
}
|
|
288
|
+
if (extraInfo.length > 0) {
|
|
289
|
+
const extraDescripton = `(${extraInfo.join(", ")})`;
|
|
290
|
+
if (argument.description) {
|
|
291
|
+
return `${argument.description} ${extraDescripton}`;
|
|
292
|
+
}
|
|
293
|
+
return extraDescripton;
|
|
294
|
+
}
|
|
295
|
+
return argument.description;
|
|
296
|
+
}
|
|
297
|
+
formatHelp(cmd, helper) {
|
|
298
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
299
|
+
const helpWidth = helper.helpWidth || 80;
|
|
300
|
+
const itemIndentWidth = 2;
|
|
301
|
+
const itemSeparatorWidth = 2;
|
|
302
|
+
function formatItem(term, description) {
|
|
303
|
+
if (description) {
|
|
304
|
+
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
305
|
+
return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
|
|
306
|
+
}
|
|
307
|
+
return term;
|
|
308
|
+
}
|
|
309
|
+
function formatList(textArray) {
|
|
310
|
+
return textArray.join(`
|
|
311
|
+
`).replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
312
|
+
}
|
|
313
|
+
let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
|
|
314
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
315
|
+
if (commandDescription.length > 0) {
|
|
316
|
+
output = output.concat([
|
|
317
|
+
helper.wrap(commandDescription, helpWidth, 0),
|
|
318
|
+
""
|
|
319
|
+
]);
|
|
320
|
+
}
|
|
321
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
322
|
+
return formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument));
|
|
323
|
+
});
|
|
324
|
+
if (argumentList.length > 0) {
|
|
325
|
+
output = output.concat(["Arguments:", formatList(argumentList), ""]);
|
|
326
|
+
}
|
|
327
|
+
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
328
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
329
|
+
});
|
|
330
|
+
if (optionList.length > 0) {
|
|
331
|
+
output = output.concat(["Options:", formatList(optionList), ""]);
|
|
332
|
+
}
|
|
333
|
+
if (this.showGlobalOptions) {
|
|
334
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
335
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
336
|
+
});
|
|
337
|
+
if (globalOptionList.length > 0) {
|
|
338
|
+
output = output.concat([
|
|
339
|
+
"Global Options:",
|
|
340
|
+
formatList(globalOptionList),
|
|
341
|
+
""
|
|
342
|
+
]);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
346
|
+
return formatItem(helper.subcommandTerm(cmd2), helper.subcommandDescription(cmd2));
|
|
347
|
+
});
|
|
348
|
+
if (commandList.length > 0) {
|
|
349
|
+
output = output.concat(["Commands:", formatList(commandList), ""]);
|
|
350
|
+
}
|
|
351
|
+
return output.join(`
|
|
352
|
+
`);
|
|
353
|
+
}
|
|
354
|
+
padWidth(cmd, helper) {
|
|
355
|
+
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
356
|
+
}
|
|
357
|
+
wrap(str, width, indent, minColumnWidth = 40) {
|
|
358
|
+
const indents = " \\f\\t\\v - \uFEFF";
|
|
359
|
+
const manualIndent = new RegExp(`[\\n][${indents}]+`);
|
|
360
|
+
if (str.match(manualIndent))
|
|
361
|
+
return str;
|
|
362
|
+
const columnWidth = width - indent;
|
|
363
|
+
if (columnWidth < minColumnWidth)
|
|
364
|
+
return str;
|
|
365
|
+
const leadingStr = str.slice(0, indent);
|
|
366
|
+
const columnText = str.slice(indent).replace(`\r
|
|
367
|
+
`, `
|
|
368
|
+
`);
|
|
369
|
+
const indentString = " ".repeat(indent);
|
|
370
|
+
const zeroWidthSpace = "";
|
|
371
|
+
const breaks = `\\s${zeroWidthSpace}`;
|
|
372
|
+
const regex = new RegExp(`
|
|
373
|
+
|.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`, "g");
|
|
374
|
+
const lines = columnText.match(regex) || [];
|
|
375
|
+
return leadingStr + lines.map((line, i) => {
|
|
376
|
+
if (line === `
|
|
377
|
+
`)
|
|
378
|
+
return "";
|
|
379
|
+
return (i > 0 ? indentString : "") + line.trimEnd();
|
|
380
|
+
}).join(`
|
|
381
|
+
`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
exports.Help = Help;
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
// ../../node_modules/commander/lib/option.js
|
|
388
|
+
var require_option = __commonJS((exports) => {
|
|
389
|
+
var { InvalidArgumentError } = require_error();
|
|
390
|
+
|
|
391
|
+
class Option {
|
|
392
|
+
constructor(flags, description) {
|
|
393
|
+
this.flags = flags;
|
|
394
|
+
this.description = description || "";
|
|
395
|
+
this.required = flags.includes("<");
|
|
396
|
+
this.optional = flags.includes("[");
|
|
397
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
398
|
+
this.mandatory = false;
|
|
399
|
+
const optionFlags = splitOptionFlags(flags);
|
|
400
|
+
this.short = optionFlags.shortFlag;
|
|
401
|
+
this.long = optionFlags.longFlag;
|
|
402
|
+
this.negate = false;
|
|
403
|
+
if (this.long) {
|
|
404
|
+
this.negate = this.long.startsWith("--no-");
|
|
405
|
+
}
|
|
406
|
+
this.defaultValue = undefined;
|
|
407
|
+
this.defaultValueDescription = undefined;
|
|
408
|
+
this.presetArg = undefined;
|
|
409
|
+
this.envVar = undefined;
|
|
410
|
+
this.parseArg = undefined;
|
|
411
|
+
this.hidden = false;
|
|
412
|
+
this.argChoices = undefined;
|
|
413
|
+
this.conflictsWith = [];
|
|
414
|
+
this.implied = undefined;
|
|
415
|
+
}
|
|
416
|
+
default(value, description) {
|
|
417
|
+
this.defaultValue = value;
|
|
418
|
+
this.defaultValueDescription = description;
|
|
419
|
+
return this;
|
|
420
|
+
}
|
|
421
|
+
preset(arg) {
|
|
422
|
+
this.presetArg = arg;
|
|
423
|
+
return this;
|
|
424
|
+
}
|
|
425
|
+
conflicts(names) {
|
|
426
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
427
|
+
return this;
|
|
428
|
+
}
|
|
429
|
+
implies(impliedOptionValues) {
|
|
430
|
+
let newImplied = impliedOptionValues;
|
|
431
|
+
if (typeof impliedOptionValues === "string") {
|
|
432
|
+
newImplied = { [impliedOptionValues]: true };
|
|
433
|
+
}
|
|
434
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
435
|
+
return this;
|
|
436
|
+
}
|
|
437
|
+
env(name) {
|
|
438
|
+
this.envVar = name;
|
|
439
|
+
return this;
|
|
440
|
+
}
|
|
441
|
+
argParser(fn) {
|
|
442
|
+
this.parseArg = fn;
|
|
443
|
+
return this;
|
|
444
|
+
}
|
|
445
|
+
makeOptionMandatory(mandatory = true) {
|
|
446
|
+
this.mandatory = !!mandatory;
|
|
447
|
+
return this;
|
|
448
|
+
}
|
|
449
|
+
hideHelp(hide = true) {
|
|
450
|
+
this.hidden = !!hide;
|
|
451
|
+
return this;
|
|
452
|
+
}
|
|
453
|
+
_concatValue(value, previous) {
|
|
454
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
455
|
+
return [value];
|
|
456
|
+
}
|
|
457
|
+
return previous.concat(value);
|
|
458
|
+
}
|
|
459
|
+
choices(values) {
|
|
460
|
+
this.argChoices = values.slice();
|
|
461
|
+
this.parseArg = (arg, previous) => {
|
|
462
|
+
if (!this.argChoices.includes(arg)) {
|
|
463
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
464
|
+
}
|
|
465
|
+
if (this.variadic) {
|
|
466
|
+
return this._concatValue(arg, previous);
|
|
467
|
+
}
|
|
468
|
+
return arg;
|
|
469
|
+
};
|
|
470
|
+
return this;
|
|
471
|
+
}
|
|
472
|
+
name() {
|
|
473
|
+
if (this.long) {
|
|
474
|
+
return this.long.replace(/^--/, "");
|
|
475
|
+
}
|
|
476
|
+
return this.short.replace(/^-/, "");
|
|
477
|
+
}
|
|
478
|
+
attributeName() {
|
|
479
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
480
|
+
}
|
|
481
|
+
is(arg) {
|
|
482
|
+
return this.short === arg || this.long === arg;
|
|
483
|
+
}
|
|
484
|
+
isBoolean() {
|
|
485
|
+
return !this.required && !this.optional && !this.negate;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
class DualOptions {
|
|
490
|
+
constructor(options) {
|
|
491
|
+
this.positiveOptions = new Map;
|
|
492
|
+
this.negativeOptions = new Map;
|
|
493
|
+
this.dualOptions = new Set;
|
|
494
|
+
options.forEach((option) => {
|
|
495
|
+
if (option.negate) {
|
|
496
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
497
|
+
} else {
|
|
498
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
this.negativeOptions.forEach((value, key) => {
|
|
502
|
+
if (this.positiveOptions.has(key)) {
|
|
503
|
+
this.dualOptions.add(key);
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
valueFromOption(value, option) {
|
|
508
|
+
const optionKey = option.attributeName();
|
|
509
|
+
if (!this.dualOptions.has(optionKey))
|
|
510
|
+
return true;
|
|
511
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
512
|
+
const negativeValue = preset !== undefined ? preset : false;
|
|
513
|
+
return option.negate === (negativeValue === value);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
function camelcase(str) {
|
|
517
|
+
return str.split("-").reduce((str2, word) => {
|
|
518
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
function splitOptionFlags(flags) {
|
|
522
|
+
let shortFlag;
|
|
523
|
+
let longFlag;
|
|
524
|
+
const flagParts = flags.split(/[ |,]+/);
|
|
525
|
+
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
526
|
+
shortFlag = flagParts.shift();
|
|
527
|
+
longFlag = flagParts.shift();
|
|
528
|
+
if (!shortFlag && /^-[^-]$/.test(longFlag)) {
|
|
529
|
+
shortFlag = longFlag;
|
|
530
|
+
longFlag = undefined;
|
|
531
|
+
}
|
|
532
|
+
return { shortFlag, longFlag };
|
|
533
|
+
}
|
|
534
|
+
exports.Option = Option;
|
|
535
|
+
exports.DualOptions = DualOptions;
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
// ../../node_modules/commander/lib/suggestSimilar.js
|
|
539
|
+
var require_suggestSimilar = __commonJS((exports) => {
|
|
540
|
+
var maxDistance = 3;
|
|
541
|
+
function editDistance(a, b) {
|
|
542
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
543
|
+
return Math.max(a.length, b.length);
|
|
544
|
+
const d = [];
|
|
545
|
+
for (let i = 0;i <= a.length; i++) {
|
|
546
|
+
d[i] = [i];
|
|
547
|
+
}
|
|
548
|
+
for (let j = 0;j <= b.length; j++) {
|
|
549
|
+
d[0][j] = j;
|
|
550
|
+
}
|
|
551
|
+
for (let j = 1;j <= b.length; j++) {
|
|
552
|
+
for (let i = 1;i <= a.length; i++) {
|
|
553
|
+
let cost = 1;
|
|
554
|
+
if (a[i - 1] === b[j - 1]) {
|
|
555
|
+
cost = 0;
|
|
556
|
+
} else {
|
|
557
|
+
cost = 1;
|
|
558
|
+
}
|
|
559
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
560
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
561
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return d[a.length][b.length];
|
|
566
|
+
}
|
|
567
|
+
function suggestSimilar(word, candidates) {
|
|
568
|
+
if (!candidates || candidates.length === 0)
|
|
569
|
+
return "";
|
|
570
|
+
candidates = Array.from(new Set(candidates));
|
|
571
|
+
const searchingOptions = word.startsWith("--");
|
|
572
|
+
if (searchingOptions) {
|
|
573
|
+
word = word.slice(2);
|
|
574
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
575
|
+
}
|
|
576
|
+
let similar = [];
|
|
577
|
+
let bestDistance = maxDistance;
|
|
578
|
+
const minSimilarity = 0.4;
|
|
579
|
+
candidates.forEach((candidate) => {
|
|
580
|
+
if (candidate.length <= 1)
|
|
581
|
+
return;
|
|
582
|
+
const distance = editDistance(word, candidate);
|
|
583
|
+
const length = Math.max(word.length, candidate.length);
|
|
584
|
+
const similarity = (length - distance) / length;
|
|
585
|
+
if (similarity > minSimilarity) {
|
|
586
|
+
if (distance < bestDistance) {
|
|
587
|
+
bestDistance = distance;
|
|
588
|
+
similar = [candidate];
|
|
589
|
+
} else if (distance === bestDistance) {
|
|
590
|
+
similar.push(candidate);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
595
|
+
if (searchingOptions) {
|
|
596
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
597
|
+
}
|
|
598
|
+
if (similar.length > 1) {
|
|
599
|
+
return `
|
|
600
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
601
|
+
}
|
|
602
|
+
if (similar.length === 1) {
|
|
603
|
+
return `
|
|
604
|
+
(Did you mean ${similar[0]}?)`;
|
|
605
|
+
}
|
|
606
|
+
return "";
|
|
607
|
+
}
|
|
608
|
+
exports.suggestSimilar = suggestSimilar;
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
// ../../node_modules/commander/lib/command.js
|
|
612
|
+
var require_command = __commonJS((exports) => {
|
|
613
|
+
var EventEmitter = __require("node:events").EventEmitter;
|
|
614
|
+
var childProcess = __require("node:child_process");
|
|
615
|
+
var path = __require("node:path");
|
|
616
|
+
var fs = __require("node:fs");
|
|
617
|
+
var process2 = __require("node:process");
|
|
618
|
+
var { Argument, humanReadableArgName } = require_argument();
|
|
619
|
+
var { CommanderError } = require_error();
|
|
620
|
+
var { Help } = require_help();
|
|
621
|
+
var { Option, DualOptions } = require_option();
|
|
622
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
623
|
+
|
|
624
|
+
class Command extends EventEmitter {
|
|
625
|
+
constructor(name) {
|
|
626
|
+
super();
|
|
627
|
+
this.commands = [];
|
|
628
|
+
this.options = [];
|
|
629
|
+
this.parent = null;
|
|
630
|
+
this._allowUnknownOption = false;
|
|
631
|
+
this._allowExcessArguments = true;
|
|
632
|
+
this.registeredArguments = [];
|
|
633
|
+
this._args = this.registeredArguments;
|
|
634
|
+
this.args = [];
|
|
635
|
+
this.rawArgs = [];
|
|
636
|
+
this.processedArgs = [];
|
|
637
|
+
this._scriptPath = null;
|
|
638
|
+
this._name = name || "";
|
|
639
|
+
this._optionValues = {};
|
|
640
|
+
this._optionValueSources = {};
|
|
641
|
+
this._storeOptionsAsProperties = false;
|
|
642
|
+
this._actionHandler = null;
|
|
643
|
+
this._executableHandler = false;
|
|
644
|
+
this._executableFile = null;
|
|
645
|
+
this._executableDir = null;
|
|
646
|
+
this._defaultCommandName = null;
|
|
647
|
+
this._exitCallback = null;
|
|
648
|
+
this._aliases = [];
|
|
649
|
+
this._combineFlagAndOptionalValue = true;
|
|
650
|
+
this._description = "";
|
|
651
|
+
this._summary = "";
|
|
652
|
+
this._argsDescription = undefined;
|
|
653
|
+
this._enablePositionalOptions = false;
|
|
654
|
+
this._passThroughOptions = false;
|
|
655
|
+
this._lifeCycleHooks = {};
|
|
656
|
+
this._showHelpAfterError = false;
|
|
657
|
+
this._showSuggestionAfterError = true;
|
|
658
|
+
this._outputConfiguration = {
|
|
659
|
+
writeOut: (str) => process2.stdout.write(str),
|
|
660
|
+
writeErr: (str) => process2.stderr.write(str),
|
|
661
|
+
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
|
|
662
|
+
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
|
|
663
|
+
outputError: (str, write) => write(str)
|
|
664
|
+
};
|
|
665
|
+
this._hidden = false;
|
|
666
|
+
this._helpOption = undefined;
|
|
667
|
+
this._addImplicitHelpCommand = undefined;
|
|
668
|
+
this._helpCommand = undefined;
|
|
669
|
+
this._helpConfiguration = {};
|
|
670
|
+
}
|
|
671
|
+
copyInheritedSettings(sourceCommand) {
|
|
672
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
673
|
+
this._helpOption = sourceCommand._helpOption;
|
|
674
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
675
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
676
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
677
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
678
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
679
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
680
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
681
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
682
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
683
|
+
return this;
|
|
684
|
+
}
|
|
685
|
+
_getCommandAndAncestors() {
|
|
686
|
+
const result = [];
|
|
687
|
+
for (let command = this;command; command = command.parent) {
|
|
688
|
+
result.push(command);
|
|
689
|
+
}
|
|
690
|
+
return result;
|
|
691
|
+
}
|
|
692
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
693
|
+
let desc = actionOptsOrExecDesc;
|
|
694
|
+
let opts = execOpts;
|
|
695
|
+
if (typeof desc === "object" && desc !== null) {
|
|
696
|
+
opts = desc;
|
|
697
|
+
desc = null;
|
|
698
|
+
}
|
|
699
|
+
opts = opts || {};
|
|
700
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
701
|
+
const cmd = this.createCommand(name);
|
|
702
|
+
if (desc) {
|
|
703
|
+
cmd.description(desc);
|
|
704
|
+
cmd._executableHandler = true;
|
|
705
|
+
}
|
|
706
|
+
if (opts.isDefault)
|
|
707
|
+
this._defaultCommandName = cmd._name;
|
|
708
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
709
|
+
cmd._executableFile = opts.executableFile || null;
|
|
710
|
+
if (args)
|
|
711
|
+
cmd.arguments(args);
|
|
712
|
+
this._registerCommand(cmd);
|
|
713
|
+
cmd.parent = this;
|
|
714
|
+
cmd.copyInheritedSettings(this);
|
|
715
|
+
if (desc)
|
|
716
|
+
return this;
|
|
717
|
+
return cmd;
|
|
718
|
+
}
|
|
719
|
+
createCommand(name) {
|
|
720
|
+
return new Command(name);
|
|
721
|
+
}
|
|
722
|
+
createHelp() {
|
|
723
|
+
return Object.assign(new Help, this.configureHelp());
|
|
724
|
+
}
|
|
725
|
+
configureHelp(configuration) {
|
|
726
|
+
if (configuration === undefined)
|
|
727
|
+
return this._helpConfiguration;
|
|
728
|
+
this._helpConfiguration = configuration;
|
|
729
|
+
return this;
|
|
730
|
+
}
|
|
731
|
+
configureOutput(configuration) {
|
|
732
|
+
if (configuration === undefined)
|
|
733
|
+
return this._outputConfiguration;
|
|
734
|
+
Object.assign(this._outputConfiguration, configuration);
|
|
735
|
+
return this;
|
|
736
|
+
}
|
|
737
|
+
showHelpAfterError(displayHelp = true) {
|
|
738
|
+
if (typeof displayHelp !== "string")
|
|
739
|
+
displayHelp = !!displayHelp;
|
|
740
|
+
this._showHelpAfterError = displayHelp;
|
|
741
|
+
return this;
|
|
742
|
+
}
|
|
743
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
744
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
745
|
+
return this;
|
|
746
|
+
}
|
|
747
|
+
addCommand(cmd, opts) {
|
|
748
|
+
if (!cmd._name) {
|
|
749
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
750
|
+
- specify the name in Command constructor or using .name()`);
|
|
751
|
+
}
|
|
752
|
+
opts = opts || {};
|
|
753
|
+
if (opts.isDefault)
|
|
754
|
+
this._defaultCommandName = cmd._name;
|
|
755
|
+
if (opts.noHelp || opts.hidden)
|
|
756
|
+
cmd._hidden = true;
|
|
757
|
+
this._registerCommand(cmd);
|
|
758
|
+
cmd.parent = this;
|
|
759
|
+
cmd._checkForBrokenPassThrough();
|
|
760
|
+
return this;
|
|
761
|
+
}
|
|
762
|
+
createArgument(name, description) {
|
|
763
|
+
return new Argument(name, description);
|
|
764
|
+
}
|
|
765
|
+
argument(name, description, fn, defaultValue) {
|
|
766
|
+
const argument = this.createArgument(name, description);
|
|
767
|
+
if (typeof fn === "function") {
|
|
768
|
+
argument.default(defaultValue).argParser(fn);
|
|
769
|
+
} else {
|
|
770
|
+
argument.default(fn);
|
|
771
|
+
}
|
|
772
|
+
this.addArgument(argument);
|
|
773
|
+
return this;
|
|
774
|
+
}
|
|
775
|
+
arguments(names) {
|
|
776
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
777
|
+
this.argument(detail);
|
|
778
|
+
});
|
|
779
|
+
return this;
|
|
780
|
+
}
|
|
781
|
+
addArgument(argument) {
|
|
782
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
783
|
+
if (previousArgument && previousArgument.variadic) {
|
|
784
|
+
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
785
|
+
}
|
|
786
|
+
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
787
|
+
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
788
|
+
}
|
|
789
|
+
this.registeredArguments.push(argument);
|
|
790
|
+
return this;
|
|
791
|
+
}
|
|
792
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
793
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
794
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
795
|
+
return this;
|
|
796
|
+
}
|
|
797
|
+
enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
798
|
+
const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
|
|
799
|
+
const helpDescription = description ?? "display help for command";
|
|
800
|
+
const helpCommand = this.createCommand(helpName);
|
|
801
|
+
helpCommand.helpOption(false);
|
|
802
|
+
if (helpArgs)
|
|
803
|
+
helpCommand.arguments(helpArgs);
|
|
804
|
+
if (helpDescription)
|
|
805
|
+
helpCommand.description(helpDescription);
|
|
806
|
+
this._addImplicitHelpCommand = true;
|
|
807
|
+
this._helpCommand = helpCommand;
|
|
808
|
+
return this;
|
|
809
|
+
}
|
|
810
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
811
|
+
if (typeof helpCommand !== "object") {
|
|
812
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
813
|
+
return this;
|
|
814
|
+
}
|
|
815
|
+
this._addImplicitHelpCommand = true;
|
|
816
|
+
this._helpCommand = helpCommand;
|
|
817
|
+
return this;
|
|
818
|
+
}
|
|
819
|
+
_getHelpCommand() {
|
|
820
|
+
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
821
|
+
if (hasImplicitHelpCommand) {
|
|
822
|
+
if (this._helpCommand === undefined) {
|
|
823
|
+
this.helpCommand(undefined, undefined);
|
|
824
|
+
}
|
|
825
|
+
return this._helpCommand;
|
|
826
|
+
}
|
|
827
|
+
return null;
|
|
828
|
+
}
|
|
829
|
+
hook(event, listener) {
|
|
830
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
831
|
+
if (!allowedValues.includes(event)) {
|
|
832
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
833
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
834
|
+
}
|
|
835
|
+
if (this._lifeCycleHooks[event]) {
|
|
836
|
+
this._lifeCycleHooks[event].push(listener);
|
|
837
|
+
} else {
|
|
838
|
+
this._lifeCycleHooks[event] = [listener];
|
|
839
|
+
}
|
|
840
|
+
return this;
|
|
841
|
+
}
|
|
842
|
+
exitOverride(fn) {
|
|
843
|
+
if (fn) {
|
|
844
|
+
this._exitCallback = fn;
|
|
845
|
+
} else {
|
|
846
|
+
this._exitCallback = (err) => {
|
|
847
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
848
|
+
throw err;
|
|
849
|
+
} else {}
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
return this;
|
|
853
|
+
}
|
|
854
|
+
_exit(exitCode, code, message) {
|
|
855
|
+
if (this._exitCallback) {
|
|
856
|
+
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
857
|
+
}
|
|
858
|
+
process2.exit(exitCode);
|
|
859
|
+
}
|
|
860
|
+
action(fn) {
|
|
861
|
+
const listener = (args) => {
|
|
862
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
863
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
864
|
+
if (this._storeOptionsAsProperties) {
|
|
865
|
+
actionArgs[expectedArgsCount] = this;
|
|
866
|
+
} else {
|
|
867
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
868
|
+
}
|
|
869
|
+
actionArgs.push(this);
|
|
870
|
+
return fn.apply(this, actionArgs);
|
|
871
|
+
};
|
|
872
|
+
this._actionHandler = listener;
|
|
873
|
+
return this;
|
|
874
|
+
}
|
|
875
|
+
createOption(flags, description) {
|
|
876
|
+
return new Option(flags, description);
|
|
877
|
+
}
|
|
878
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
879
|
+
try {
|
|
880
|
+
return target.parseArg(value, previous);
|
|
881
|
+
} catch (err) {
|
|
882
|
+
if (err.code === "commander.invalidArgument") {
|
|
883
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
884
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
885
|
+
}
|
|
886
|
+
throw err;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
_registerOption(option) {
|
|
890
|
+
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
891
|
+
if (matchingOption) {
|
|
892
|
+
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
893
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
894
|
+
- already used by option '${matchingOption.flags}'`);
|
|
895
|
+
}
|
|
896
|
+
this.options.push(option);
|
|
897
|
+
}
|
|
898
|
+
_registerCommand(command) {
|
|
899
|
+
const knownBy = (cmd) => {
|
|
900
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
901
|
+
};
|
|
902
|
+
const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
|
|
903
|
+
if (alreadyUsed) {
|
|
904
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
905
|
+
const newCmd = knownBy(command).join("|");
|
|
906
|
+
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
907
|
+
}
|
|
908
|
+
this.commands.push(command);
|
|
909
|
+
}
|
|
910
|
+
addOption(option) {
|
|
911
|
+
this._registerOption(option);
|
|
912
|
+
const oname = option.name();
|
|
913
|
+
const name = option.attributeName();
|
|
914
|
+
if (option.negate) {
|
|
915
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
916
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
917
|
+
this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
|
|
918
|
+
}
|
|
919
|
+
} else if (option.defaultValue !== undefined) {
|
|
920
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
921
|
+
}
|
|
922
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
923
|
+
if (val == null && option.presetArg !== undefined) {
|
|
924
|
+
val = option.presetArg;
|
|
925
|
+
}
|
|
926
|
+
const oldValue = this.getOptionValue(name);
|
|
927
|
+
if (val !== null && option.parseArg) {
|
|
928
|
+
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
929
|
+
} else if (val !== null && option.variadic) {
|
|
930
|
+
val = option._concatValue(val, oldValue);
|
|
931
|
+
}
|
|
932
|
+
if (val == null) {
|
|
933
|
+
if (option.negate) {
|
|
934
|
+
val = false;
|
|
935
|
+
} else if (option.isBoolean() || option.optional) {
|
|
936
|
+
val = true;
|
|
937
|
+
} else {
|
|
938
|
+
val = "";
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
942
|
+
};
|
|
943
|
+
this.on("option:" + oname, (val) => {
|
|
944
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
945
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
946
|
+
});
|
|
947
|
+
if (option.envVar) {
|
|
948
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
949
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
950
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
return this;
|
|
954
|
+
}
|
|
955
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
956
|
+
if (typeof flags === "object" && flags instanceof Option) {
|
|
957
|
+
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
958
|
+
}
|
|
959
|
+
const option = this.createOption(flags, description);
|
|
960
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
961
|
+
if (typeof fn === "function") {
|
|
962
|
+
option.default(defaultValue).argParser(fn);
|
|
963
|
+
} else if (fn instanceof RegExp) {
|
|
964
|
+
const regex = fn;
|
|
965
|
+
fn = (val, def) => {
|
|
966
|
+
const m = regex.exec(val);
|
|
967
|
+
return m ? m[0] : def;
|
|
968
|
+
};
|
|
969
|
+
option.default(defaultValue).argParser(fn);
|
|
970
|
+
} else {
|
|
971
|
+
option.default(fn);
|
|
972
|
+
}
|
|
973
|
+
return this.addOption(option);
|
|
974
|
+
}
|
|
975
|
+
option(flags, description, parseArg, defaultValue) {
|
|
976
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
977
|
+
}
|
|
978
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
979
|
+
return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
|
|
980
|
+
}
|
|
981
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
982
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
983
|
+
return this;
|
|
984
|
+
}
|
|
985
|
+
allowUnknownOption(allowUnknown = true) {
|
|
986
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
987
|
+
return this;
|
|
988
|
+
}
|
|
989
|
+
allowExcessArguments(allowExcess = true) {
|
|
990
|
+
this._allowExcessArguments = !!allowExcess;
|
|
991
|
+
return this;
|
|
992
|
+
}
|
|
993
|
+
enablePositionalOptions(positional = true) {
|
|
994
|
+
this._enablePositionalOptions = !!positional;
|
|
995
|
+
return this;
|
|
996
|
+
}
|
|
997
|
+
passThroughOptions(passThrough = true) {
|
|
998
|
+
this._passThroughOptions = !!passThrough;
|
|
999
|
+
this._checkForBrokenPassThrough();
|
|
1000
|
+
return this;
|
|
1001
|
+
}
|
|
1002
|
+
_checkForBrokenPassThrough() {
|
|
1003
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
1004
|
+
throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
1008
|
+
if (this.options.length) {
|
|
1009
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
1010
|
+
}
|
|
1011
|
+
if (Object.keys(this._optionValues).length) {
|
|
1012
|
+
throw new Error("call .storeOptionsAsProperties() before setting option values");
|
|
1013
|
+
}
|
|
1014
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
1015
|
+
return this;
|
|
1016
|
+
}
|
|
1017
|
+
getOptionValue(key) {
|
|
1018
|
+
if (this._storeOptionsAsProperties) {
|
|
1019
|
+
return this[key];
|
|
1020
|
+
}
|
|
1021
|
+
return this._optionValues[key];
|
|
1022
|
+
}
|
|
1023
|
+
setOptionValue(key, value) {
|
|
1024
|
+
return this.setOptionValueWithSource(key, value, undefined);
|
|
1025
|
+
}
|
|
1026
|
+
setOptionValueWithSource(key, value, source) {
|
|
1027
|
+
if (this._storeOptionsAsProperties) {
|
|
1028
|
+
this[key] = value;
|
|
1029
|
+
} else {
|
|
1030
|
+
this._optionValues[key] = value;
|
|
1031
|
+
}
|
|
1032
|
+
this._optionValueSources[key] = source;
|
|
1033
|
+
return this;
|
|
1034
|
+
}
|
|
1035
|
+
getOptionValueSource(key) {
|
|
1036
|
+
return this._optionValueSources[key];
|
|
1037
|
+
}
|
|
1038
|
+
getOptionValueSourceWithGlobals(key) {
|
|
1039
|
+
let source;
|
|
1040
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1041
|
+
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
1042
|
+
source = cmd.getOptionValueSource(key);
|
|
1043
|
+
}
|
|
1044
|
+
});
|
|
1045
|
+
return source;
|
|
1046
|
+
}
|
|
1047
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
1048
|
+
if (argv !== undefined && !Array.isArray(argv)) {
|
|
1049
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
1050
|
+
}
|
|
1051
|
+
parseOptions = parseOptions || {};
|
|
1052
|
+
if (argv === undefined && parseOptions.from === undefined) {
|
|
1053
|
+
if (process2.versions?.electron) {
|
|
1054
|
+
parseOptions.from = "electron";
|
|
1055
|
+
}
|
|
1056
|
+
const execArgv = process2.execArgv ?? [];
|
|
1057
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
1058
|
+
parseOptions.from = "eval";
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
if (argv === undefined) {
|
|
1062
|
+
argv = process2.argv;
|
|
1063
|
+
}
|
|
1064
|
+
this.rawArgs = argv.slice();
|
|
1065
|
+
let userArgs;
|
|
1066
|
+
switch (parseOptions.from) {
|
|
1067
|
+
case undefined:
|
|
1068
|
+
case "node":
|
|
1069
|
+
this._scriptPath = argv[1];
|
|
1070
|
+
userArgs = argv.slice(2);
|
|
1071
|
+
break;
|
|
1072
|
+
case "electron":
|
|
1073
|
+
if (process2.defaultApp) {
|
|
1074
|
+
this._scriptPath = argv[1];
|
|
1075
|
+
userArgs = argv.slice(2);
|
|
1076
|
+
} else {
|
|
1077
|
+
userArgs = argv.slice(1);
|
|
1078
|
+
}
|
|
1079
|
+
break;
|
|
1080
|
+
case "user":
|
|
1081
|
+
userArgs = argv.slice(0);
|
|
1082
|
+
break;
|
|
1083
|
+
case "eval":
|
|
1084
|
+
userArgs = argv.slice(1);
|
|
1085
|
+
break;
|
|
1086
|
+
default:
|
|
1087
|
+
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
1088
|
+
}
|
|
1089
|
+
if (!this._name && this._scriptPath)
|
|
1090
|
+
this.nameFromFilename(this._scriptPath);
|
|
1091
|
+
this._name = this._name || "program";
|
|
1092
|
+
return userArgs;
|
|
1093
|
+
}
|
|
1094
|
+
parse(argv, parseOptions) {
|
|
1095
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1096
|
+
this._parseCommand([], userArgs);
|
|
1097
|
+
return this;
|
|
1098
|
+
}
|
|
1099
|
+
async parseAsync(argv, parseOptions) {
|
|
1100
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1101
|
+
await this._parseCommand([], userArgs);
|
|
1102
|
+
return this;
|
|
1103
|
+
}
|
|
1104
|
+
_executeSubCommand(subcommand, args) {
|
|
1105
|
+
args = args.slice();
|
|
1106
|
+
let launchWithNode = false;
|
|
1107
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1108
|
+
function findFile(baseDir, baseName) {
|
|
1109
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
1110
|
+
if (fs.existsSync(localBin))
|
|
1111
|
+
return localBin;
|
|
1112
|
+
if (sourceExt.includes(path.extname(baseName)))
|
|
1113
|
+
return;
|
|
1114
|
+
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
1115
|
+
if (foundExt)
|
|
1116
|
+
return `${localBin}${foundExt}`;
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
this._checkForMissingMandatoryOptions();
|
|
1120
|
+
this._checkForConflictingOptions();
|
|
1121
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
1122
|
+
let executableDir = this._executableDir || "";
|
|
1123
|
+
if (this._scriptPath) {
|
|
1124
|
+
let resolvedScriptPath;
|
|
1125
|
+
try {
|
|
1126
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1127
|
+
} catch (err) {
|
|
1128
|
+
resolvedScriptPath = this._scriptPath;
|
|
1129
|
+
}
|
|
1130
|
+
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
1131
|
+
}
|
|
1132
|
+
if (executableDir) {
|
|
1133
|
+
let localFile = findFile(executableDir, executableFile);
|
|
1134
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1135
|
+
const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
1136
|
+
if (legacyName !== this._name) {
|
|
1137
|
+
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
executableFile = localFile || executableFile;
|
|
1141
|
+
}
|
|
1142
|
+
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
1143
|
+
let proc;
|
|
1144
|
+
if (process2.platform !== "win32") {
|
|
1145
|
+
if (launchWithNode) {
|
|
1146
|
+
args.unshift(executableFile);
|
|
1147
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1148
|
+
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
1149
|
+
} else {
|
|
1150
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1151
|
+
}
|
|
1152
|
+
} else {
|
|
1153
|
+
args.unshift(executableFile);
|
|
1154
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1155
|
+
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
1156
|
+
}
|
|
1157
|
+
if (!proc.killed) {
|
|
1158
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
1159
|
+
signals.forEach((signal) => {
|
|
1160
|
+
process2.on(signal, () => {
|
|
1161
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
1162
|
+
proc.kill(signal);
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
const exitCallback = this._exitCallback;
|
|
1168
|
+
proc.on("close", (code) => {
|
|
1169
|
+
code = code ?? 1;
|
|
1170
|
+
if (!exitCallback) {
|
|
1171
|
+
process2.exit(code);
|
|
1172
|
+
} else {
|
|
1173
|
+
exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
|
|
1174
|
+
}
|
|
1175
|
+
});
|
|
1176
|
+
proc.on("error", (err) => {
|
|
1177
|
+
if (err.code === "ENOENT") {
|
|
1178
|
+
const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
1179
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
1180
|
+
- if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1181
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1182
|
+
- ${executableDirMessage}`;
|
|
1183
|
+
throw new Error(executableMissing);
|
|
1184
|
+
} else if (err.code === "EACCES") {
|
|
1185
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
1186
|
+
}
|
|
1187
|
+
if (!exitCallback) {
|
|
1188
|
+
process2.exit(1);
|
|
1189
|
+
} else {
|
|
1190
|
+
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
1191
|
+
wrappedError.nestedError = err;
|
|
1192
|
+
exitCallback(wrappedError);
|
|
1193
|
+
}
|
|
1194
|
+
});
|
|
1195
|
+
this.runningCommand = proc;
|
|
1196
|
+
}
|
|
1197
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
1198
|
+
const subCommand = this._findCommand(commandName);
|
|
1199
|
+
if (!subCommand)
|
|
1200
|
+
this.help({ error: true });
|
|
1201
|
+
let promiseChain;
|
|
1202
|
+
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
|
|
1203
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1204
|
+
if (subCommand._executableHandler) {
|
|
1205
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
1206
|
+
} else {
|
|
1207
|
+
return subCommand._parseCommand(operands, unknown);
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
return promiseChain;
|
|
1211
|
+
}
|
|
1212
|
+
_dispatchHelpCommand(subcommandName) {
|
|
1213
|
+
if (!subcommandName) {
|
|
1214
|
+
this.help();
|
|
1215
|
+
}
|
|
1216
|
+
const subCommand = this._findCommand(subcommandName);
|
|
1217
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
1218
|
+
subCommand.help();
|
|
1219
|
+
}
|
|
1220
|
+
return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
|
|
1221
|
+
}
|
|
1222
|
+
_checkNumberOfArguments() {
|
|
1223
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
1224
|
+
if (arg.required && this.args[i] == null) {
|
|
1225
|
+
this.missingArgument(arg.name());
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
1232
|
+
this._excessArguments(this.args);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
_processArguments() {
|
|
1236
|
+
const myParseArg = (argument, value, previous) => {
|
|
1237
|
+
let parsedValue = value;
|
|
1238
|
+
if (value !== null && argument.parseArg) {
|
|
1239
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
1240
|
+
parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
|
|
1241
|
+
}
|
|
1242
|
+
return parsedValue;
|
|
1243
|
+
};
|
|
1244
|
+
this._checkNumberOfArguments();
|
|
1245
|
+
const processedArgs = [];
|
|
1246
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
1247
|
+
let value = declaredArg.defaultValue;
|
|
1248
|
+
if (declaredArg.variadic) {
|
|
1249
|
+
if (index < this.args.length) {
|
|
1250
|
+
value = this.args.slice(index);
|
|
1251
|
+
if (declaredArg.parseArg) {
|
|
1252
|
+
value = value.reduce((processed, v) => {
|
|
1253
|
+
return myParseArg(declaredArg, v, processed);
|
|
1254
|
+
}, declaredArg.defaultValue);
|
|
1255
|
+
}
|
|
1256
|
+
} else if (value === undefined) {
|
|
1257
|
+
value = [];
|
|
1258
|
+
}
|
|
1259
|
+
} else if (index < this.args.length) {
|
|
1260
|
+
value = this.args[index];
|
|
1261
|
+
if (declaredArg.parseArg) {
|
|
1262
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
processedArgs[index] = value;
|
|
1266
|
+
});
|
|
1267
|
+
this.processedArgs = processedArgs;
|
|
1268
|
+
}
|
|
1269
|
+
_chainOrCall(promise, fn) {
|
|
1270
|
+
if (promise && promise.then && typeof promise.then === "function") {
|
|
1271
|
+
return promise.then(() => fn());
|
|
1272
|
+
}
|
|
1273
|
+
return fn();
|
|
1274
|
+
}
|
|
1275
|
+
_chainOrCallHooks(promise, event) {
|
|
1276
|
+
let result = promise;
|
|
1277
|
+
const hooks = [];
|
|
1278
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
|
|
1279
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
1280
|
+
hooks.push({ hookedCommand, callback });
|
|
1281
|
+
});
|
|
1282
|
+
});
|
|
1283
|
+
if (event === "postAction") {
|
|
1284
|
+
hooks.reverse();
|
|
1285
|
+
}
|
|
1286
|
+
hooks.forEach((hookDetail) => {
|
|
1287
|
+
result = this._chainOrCall(result, () => {
|
|
1288
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
1289
|
+
});
|
|
1290
|
+
});
|
|
1291
|
+
return result;
|
|
1292
|
+
}
|
|
1293
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
1294
|
+
let result = promise;
|
|
1295
|
+
if (this._lifeCycleHooks[event] !== undefined) {
|
|
1296
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
1297
|
+
result = this._chainOrCall(result, () => {
|
|
1298
|
+
return hook(this, subCommand);
|
|
1299
|
+
});
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
return result;
|
|
1303
|
+
}
|
|
1304
|
+
_parseCommand(operands, unknown) {
|
|
1305
|
+
const parsed = this.parseOptions(unknown);
|
|
1306
|
+
this._parseOptionsEnv();
|
|
1307
|
+
this._parseOptionsImplied();
|
|
1308
|
+
operands = operands.concat(parsed.operands);
|
|
1309
|
+
unknown = parsed.unknown;
|
|
1310
|
+
this.args = operands.concat(unknown);
|
|
1311
|
+
if (operands && this._findCommand(operands[0])) {
|
|
1312
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
1313
|
+
}
|
|
1314
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
1315
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
1316
|
+
}
|
|
1317
|
+
if (this._defaultCommandName) {
|
|
1318
|
+
this._outputHelpIfRequested(unknown);
|
|
1319
|
+
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
1320
|
+
}
|
|
1321
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
1322
|
+
this.help({ error: true });
|
|
1323
|
+
}
|
|
1324
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
1325
|
+
this._checkForMissingMandatoryOptions();
|
|
1326
|
+
this._checkForConflictingOptions();
|
|
1327
|
+
const checkForUnknownOptions = () => {
|
|
1328
|
+
if (parsed.unknown.length > 0) {
|
|
1329
|
+
this.unknownOption(parsed.unknown[0]);
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
const commandEvent = `command:${this.name()}`;
|
|
1333
|
+
if (this._actionHandler) {
|
|
1334
|
+
checkForUnknownOptions();
|
|
1335
|
+
this._processArguments();
|
|
1336
|
+
let promiseChain;
|
|
1337
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
1338
|
+
promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
|
|
1339
|
+
if (this.parent) {
|
|
1340
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1341
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
1345
|
+
return promiseChain;
|
|
1346
|
+
}
|
|
1347
|
+
if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
1348
|
+
checkForUnknownOptions();
|
|
1349
|
+
this._processArguments();
|
|
1350
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1351
|
+
} else if (operands.length) {
|
|
1352
|
+
if (this._findCommand("*")) {
|
|
1353
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
1354
|
+
}
|
|
1355
|
+
if (this.listenerCount("command:*")) {
|
|
1356
|
+
this.emit("command:*", operands, unknown);
|
|
1357
|
+
} else if (this.commands.length) {
|
|
1358
|
+
this.unknownCommand();
|
|
1359
|
+
} else {
|
|
1360
|
+
checkForUnknownOptions();
|
|
1361
|
+
this._processArguments();
|
|
1362
|
+
}
|
|
1363
|
+
} else if (this.commands.length) {
|
|
1364
|
+
checkForUnknownOptions();
|
|
1365
|
+
this.help({ error: true });
|
|
1366
|
+
} else {
|
|
1367
|
+
checkForUnknownOptions();
|
|
1368
|
+
this._processArguments();
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
_findCommand(name) {
|
|
1372
|
+
if (!name)
|
|
1373
|
+
return;
|
|
1374
|
+
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
1375
|
+
}
|
|
1376
|
+
_findOption(arg) {
|
|
1377
|
+
return this.options.find((option) => option.is(arg));
|
|
1378
|
+
}
|
|
1379
|
+
_checkForMissingMandatoryOptions() {
|
|
1380
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1381
|
+
cmd.options.forEach((anOption) => {
|
|
1382
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
|
|
1383
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
1384
|
+
}
|
|
1385
|
+
});
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
_checkForConflictingLocalOptions() {
|
|
1389
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
1390
|
+
const optionKey = option.attributeName();
|
|
1391
|
+
if (this.getOptionValue(optionKey) === undefined) {
|
|
1392
|
+
return false;
|
|
1393
|
+
}
|
|
1394
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
1395
|
+
});
|
|
1396
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
1397
|
+
optionsWithConflicting.forEach((option) => {
|
|
1398
|
+
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
1399
|
+
if (conflictingAndDefined) {
|
|
1400
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
1401
|
+
}
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
_checkForConflictingOptions() {
|
|
1405
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1406
|
+
cmd._checkForConflictingLocalOptions();
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
parseOptions(argv) {
|
|
1410
|
+
const operands = [];
|
|
1411
|
+
const unknown = [];
|
|
1412
|
+
let dest = operands;
|
|
1413
|
+
const args = argv.slice();
|
|
1414
|
+
function maybeOption(arg) {
|
|
1415
|
+
return arg.length > 1 && arg[0] === "-";
|
|
1416
|
+
}
|
|
1417
|
+
let activeVariadicOption = null;
|
|
1418
|
+
while (args.length) {
|
|
1419
|
+
const arg = args.shift();
|
|
1420
|
+
if (arg === "--") {
|
|
1421
|
+
if (dest === unknown)
|
|
1422
|
+
dest.push(arg);
|
|
1423
|
+
dest.push(...args);
|
|
1424
|
+
break;
|
|
1425
|
+
}
|
|
1426
|
+
if (activeVariadicOption && !maybeOption(arg)) {
|
|
1427
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1428
|
+
continue;
|
|
1429
|
+
}
|
|
1430
|
+
activeVariadicOption = null;
|
|
1431
|
+
if (maybeOption(arg)) {
|
|
1432
|
+
const option = this._findOption(arg);
|
|
1433
|
+
if (option) {
|
|
1434
|
+
if (option.required) {
|
|
1435
|
+
const value = args.shift();
|
|
1436
|
+
if (value === undefined)
|
|
1437
|
+
this.optionMissingArgument(option);
|
|
1438
|
+
this.emit(`option:${option.name()}`, value);
|
|
1439
|
+
} else if (option.optional) {
|
|
1440
|
+
let value = null;
|
|
1441
|
+
if (args.length > 0 && !maybeOption(args[0])) {
|
|
1442
|
+
value = args.shift();
|
|
1443
|
+
}
|
|
1444
|
+
this.emit(`option:${option.name()}`, value);
|
|
1445
|
+
} else {
|
|
1446
|
+
this.emit(`option:${option.name()}`);
|
|
1447
|
+
}
|
|
1448
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
1449
|
+
continue;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1453
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
1454
|
+
if (option) {
|
|
1455
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
1456
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1457
|
+
} else {
|
|
1458
|
+
this.emit(`option:${option.name()}`);
|
|
1459
|
+
args.unshift(`-${arg.slice(2)}`);
|
|
1460
|
+
}
|
|
1461
|
+
continue;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
1465
|
+
const index = arg.indexOf("=");
|
|
1466
|
+
const option = this._findOption(arg.slice(0, index));
|
|
1467
|
+
if (option && (option.required || option.optional)) {
|
|
1468
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1469
|
+
continue;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
if (maybeOption(arg)) {
|
|
1473
|
+
dest = unknown;
|
|
1474
|
+
}
|
|
1475
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1476
|
+
if (this._findCommand(arg)) {
|
|
1477
|
+
operands.push(arg);
|
|
1478
|
+
if (args.length > 0)
|
|
1479
|
+
unknown.push(...args);
|
|
1480
|
+
break;
|
|
1481
|
+
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
1482
|
+
operands.push(arg);
|
|
1483
|
+
if (args.length > 0)
|
|
1484
|
+
operands.push(...args);
|
|
1485
|
+
break;
|
|
1486
|
+
} else if (this._defaultCommandName) {
|
|
1487
|
+
unknown.push(arg);
|
|
1488
|
+
if (args.length > 0)
|
|
1489
|
+
unknown.push(...args);
|
|
1490
|
+
break;
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
if (this._passThroughOptions) {
|
|
1494
|
+
dest.push(arg);
|
|
1495
|
+
if (args.length > 0)
|
|
1496
|
+
dest.push(...args);
|
|
1497
|
+
break;
|
|
1498
|
+
}
|
|
1499
|
+
dest.push(arg);
|
|
1500
|
+
}
|
|
1501
|
+
return { operands, unknown };
|
|
1502
|
+
}
|
|
1503
|
+
opts() {
|
|
1504
|
+
if (this._storeOptionsAsProperties) {
|
|
1505
|
+
const result = {};
|
|
1506
|
+
const len = this.options.length;
|
|
1507
|
+
for (let i = 0;i < len; i++) {
|
|
1508
|
+
const key = this.options[i].attributeName();
|
|
1509
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
1510
|
+
}
|
|
1511
|
+
return result;
|
|
1512
|
+
}
|
|
1513
|
+
return this._optionValues;
|
|
1514
|
+
}
|
|
1515
|
+
optsWithGlobals() {
|
|
1516
|
+
return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
1517
|
+
}
|
|
1518
|
+
error(message, errorOptions) {
|
|
1519
|
+
this._outputConfiguration.outputError(`${message}
|
|
1520
|
+
`, this._outputConfiguration.writeErr);
|
|
1521
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
1522
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
1523
|
+
`);
|
|
1524
|
+
} else if (this._showHelpAfterError) {
|
|
1525
|
+
this._outputConfiguration.writeErr(`
|
|
1526
|
+
`);
|
|
1527
|
+
this.outputHelp({ error: true });
|
|
1528
|
+
}
|
|
1529
|
+
const config = errorOptions || {};
|
|
1530
|
+
const exitCode = config.exitCode || 1;
|
|
1531
|
+
const code = config.code || "commander.error";
|
|
1532
|
+
this._exit(exitCode, code, message);
|
|
1533
|
+
}
|
|
1534
|
+
_parseOptionsEnv() {
|
|
1535
|
+
this.options.forEach((option) => {
|
|
1536
|
+
if (option.envVar && option.envVar in process2.env) {
|
|
1537
|
+
const optionKey = option.attributeName();
|
|
1538
|
+
if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
1539
|
+
if (option.required || option.optional) {
|
|
1540
|
+
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
1541
|
+
} else {
|
|
1542
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
_parseOptionsImplied() {
|
|
1549
|
+
const dualHelper = new DualOptions(this.options);
|
|
1550
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
1551
|
+
return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
1552
|
+
};
|
|
1553
|
+
this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
1554
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
1555
|
+
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
1556
|
+
});
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
missingArgument(name) {
|
|
1560
|
+
const message = `error: missing required argument '${name}'`;
|
|
1561
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
1562
|
+
}
|
|
1563
|
+
optionMissingArgument(option) {
|
|
1564
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
1565
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
1566
|
+
}
|
|
1567
|
+
missingMandatoryOptionValue(option) {
|
|
1568
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
1569
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
1570
|
+
}
|
|
1571
|
+
_conflictingOption(option, conflictingOption) {
|
|
1572
|
+
const findBestOptionFromValue = (option2) => {
|
|
1573
|
+
const optionKey = option2.attributeName();
|
|
1574
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
1575
|
+
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
1576
|
+
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
1577
|
+
if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
|
|
1578
|
+
return negativeOption;
|
|
1579
|
+
}
|
|
1580
|
+
return positiveOption || option2;
|
|
1581
|
+
};
|
|
1582
|
+
const getErrorMessage = (option2) => {
|
|
1583
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
1584
|
+
const optionKey = bestOption.attributeName();
|
|
1585
|
+
const source = this.getOptionValueSource(optionKey);
|
|
1586
|
+
if (source === "env") {
|
|
1587
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
1588
|
+
}
|
|
1589
|
+
return `option '${bestOption.flags}'`;
|
|
1590
|
+
};
|
|
1591
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
1592
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
1593
|
+
}
|
|
1594
|
+
unknownOption(flag) {
|
|
1595
|
+
if (this._allowUnknownOption)
|
|
1596
|
+
return;
|
|
1597
|
+
let suggestion = "";
|
|
1598
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
1599
|
+
let candidateFlags = [];
|
|
1600
|
+
let command = this;
|
|
1601
|
+
do {
|
|
1602
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
1603
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
1604
|
+
command = command.parent;
|
|
1605
|
+
} while (command && !command._enablePositionalOptions);
|
|
1606
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
1607
|
+
}
|
|
1608
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
1609
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
1610
|
+
}
|
|
1611
|
+
_excessArguments(receivedArgs) {
|
|
1612
|
+
if (this._allowExcessArguments)
|
|
1613
|
+
return;
|
|
1614
|
+
const expected = this.registeredArguments.length;
|
|
1615
|
+
const s = expected === 1 ? "" : "s";
|
|
1616
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
1617
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
1618
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
1619
|
+
}
|
|
1620
|
+
unknownCommand() {
|
|
1621
|
+
const unknownName = this.args[0];
|
|
1622
|
+
let suggestion = "";
|
|
1623
|
+
if (this._showSuggestionAfterError) {
|
|
1624
|
+
const candidateNames = [];
|
|
1625
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
1626
|
+
candidateNames.push(command.name());
|
|
1627
|
+
if (command.alias())
|
|
1628
|
+
candidateNames.push(command.alias());
|
|
1629
|
+
});
|
|
1630
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
1631
|
+
}
|
|
1632
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
1633
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
1634
|
+
}
|
|
1635
|
+
version(str, flags, description) {
|
|
1636
|
+
if (str === undefined)
|
|
1637
|
+
return this._version;
|
|
1638
|
+
this._version = str;
|
|
1639
|
+
flags = flags || "-V, --version";
|
|
1640
|
+
description = description || "output the version number";
|
|
1641
|
+
const versionOption = this.createOption(flags, description);
|
|
1642
|
+
this._versionOptionName = versionOption.attributeName();
|
|
1643
|
+
this._registerOption(versionOption);
|
|
1644
|
+
this.on("option:" + versionOption.name(), () => {
|
|
1645
|
+
this._outputConfiguration.writeOut(`${str}
|
|
1646
|
+
`);
|
|
1647
|
+
this._exit(0, "commander.version", str);
|
|
1648
|
+
});
|
|
1649
|
+
return this;
|
|
1650
|
+
}
|
|
1651
|
+
description(str, argsDescription) {
|
|
1652
|
+
if (str === undefined && argsDescription === undefined)
|
|
1653
|
+
return this._description;
|
|
1654
|
+
this._description = str;
|
|
1655
|
+
if (argsDescription) {
|
|
1656
|
+
this._argsDescription = argsDescription;
|
|
1657
|
+
}
|
|
1658
|
+
return this;
|
|
1659
|
+
}
|
|
1660
|
+
summary(str) {
|
|
1661
|
+
if (str === undefined)
|
|
1662
|
+
return this._summary;
|
|
1663
|
+
this._summary = str;
|
|
1664
|
+
return this;
|
|
1665
|
+
}
|
|
1666
|
+
alias(alias) {
|
|
1667
|
+
if (alias === undefined)
|
|
1668
|
+
return this._aliases[0];
|
|
1669
|
+
let command = this;
|
|
1670
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
1671
|
+
command = this.commands[this.commands.length - 1];
|
|
1672
|
+
}
|
|
1673
|
+
if (alias === command._name)
|
|
1674
|
+
throw new Error("Command alias can't be the same as its name");
|
|
1675
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
1676
|
+
if (matchingCommand) {
|
|
1677
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
1678
|
+
throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
|
|
1679
|
+
}
|
|
1680
|
+
command._aliases.push(alias);
|
|
1681
|
+
return this;
|
|
1682
|
+
}
|
|
1683
|
+
aliases(aliases) {
|
|
1684
|
+
if (aliases === undefined)
|
|
1685
|
+
return this._aliases;
|
|
1686
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
1687
|
+
return this;
|
|
1688
|
+
}
|
|
1689
|
+
usage(str) {
|
|
1690
|
+
if (str === undefined) {
|
|
1691
|
+
if (this._usage)
|
|
1692
|
+
return this._usage;
|
|
1693
|
+
const args = this.registeredArguments.map((arg) => {
|
|
1694
|
+
return humanReadableArgName(arg);
|
|
1695
|
+
});
|
|
1696
|
+
return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
|
|
1697
|
+
}
|
|
1698
|
+
this._usage = str;
|
|
1699
|
+
return this;
|
|
1700
|
+
}
|
|
1701
|
+
name(str) {
|
|
1702
|
+
if (str === undefined)
|
|
1703
|
+
return this._name;
|
|
1704
|
+
this._name = str;
|
|
1705
|
+
return this;
|
|
1706
|
+
}
|
|
1707
|
+
nameFromFilename(filename) {
|
|
1708
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
1709
|
+
return this;
|
|
1710
|
+
}
|
|
1711
|
+
executableDir(path2) {
|
|
1712
|
+
if (path2 === undefined)
|
|
1713
|
+
return this._executableDir;
|
|
1714
|
+
this._executableDir = path2;
|
|
1715
|
+
return this;
|
|
1716
|
+
}
|
|
1717
|
+
helpInformation(contextOptions) {
|
|
1718
|
+
const helper = this.createHelp();
|
|
1719
|
+
if (helper.helpWidth === undefined) {
|
|
1720
|
+
helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
|
|
1721
|
+
}
|
|
1722
|
+
return helper.formatHelp(this, helper);
|
|
1723
|
+
}
|
|
1724
|
+
_getHelpContext(contextOptions) {
|
|
1725
|
+
contextOptions = contextOptions || {};
|
|
1726
|
+
const context = { error: !!contextOptions.error };
|
|
1727
|
+
let write;
|
|
1728
|
+
if (context.error) {
|
|
1729
|
+
write = (arg) => this._outputConfiguration.writeErr(arg);
|
|
1730
|
+
} else {
|
|
1731
|
+
write = (arg) => this._outputConfiguration.writeOut(arg);
|
|
1732
|
+
}
|
|
1733
|
+
context.write = contextOptions.write || write;
|
|
1734
|
+
context.command = this;
|
|
1735
|
+
return context;
|
|
1736
|
+
}
|
|
1737
|
+
outputHelp(contextOptions) {
|
|
1738
|
+
let deprecatedCallback;
|
|
1739
|
+
if (typeof contextOptions === "function") {
|
|
1740
|
+
deprecatedCallback = contextOptions;
|
|
1741
|
+
contextOptions = undefined;
|
|
1742
|
+
}
|
|
1743
|
+
const context = this._getHelpContext(contextOptions);
|
|
1744
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", context));
|
|
1745
|
+
this.emit("beforeHelp", context);
|
|
1746
|
+
let helpInformation = this.helpInformation(context);
|
|
1747
|
+
if (deprecatedCallback) {
|
|
1748
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
1749
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
1750
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
context.write(helpInformation);
|
|
1754
|
+
if (this._getHelpOption()?.long) {
|
|
1755
|
+
this.emit(this._getHelpOption().long);
|
|
1756
|
+
}
|
|
1757
|
+
this.emit("afterHelp", context);
|
|
1758
|
+
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", context));
|
|
1759
|
+
}
|
|
1760
|
+
helpOption(flags, description) {
|
|
1761
|
+
if (typeof flags === "boolean") {
|
|
1762
|
+
if (flags) {
|
|
1763
|
+
this._helpOption = this._helpOption ?? undefined;
|
|
1764
|
+
} else {
|
|
1765
|
+
this._helpOption = null;
|
|
1766
|
+
}
|
|
1767
|
+
return this;
|
|
1768
|
+
}
|
|
1769
|
+
flags = flags ?? "-h, --help";
|
|
1770
|
+
description = description ?? "display help for command";
|
|
1771
|
+
this._helpOption = this.createOption(flags, description);
|
|
1772
|
+
return this;
|
|
1773
|
+
}
|
|
1774
|
+
_getHelpOption() {
|
|
1775
|
+
if (this._helpOption === undefined) {
|
|
1776
|
+
this.helpOption(undefined, undefined);
|
|
1777
|
+
}
|
|
1778
|
+
return this._helpOption;
|
|
1779
|
+
}
|
|
1780
|
+
addHelpOption(option) {
|
|
1781
|
+
this._helpOption = option;
|
|
1782
|
+
return this;
|
|
1783
|
+
}
|
|
1784
|
+
help(contextOptions) {
|
|
1785
|
+
this.outputHelp(contextOptions);
|
|
1786
|
+
let exitCode = process2.exitCode || 0;
|
|
1787
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
1788
|
+
exitCode = 1;
|
|
1789
|
+
}
|
|
1790
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
1791
|
+
}
|
|
1792
|
+
addHelpText(position, text) {
|
|
1793
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
1794
|
+
if (!allowedValues.includes(position)) {
|
|
1795
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
1796
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1797
|
+
}
|
|
1798
|
+
const helpEvent = `${position}Help`;
|
|
1799
|
+
this.on(helpEvent, (context) => {
|
|
1800
|
+
let helpStr;
|
|
1801
|
+
if (typeof text === "function") {
|
|
1802
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
1803
|
+
} else {
|
|
1804
|
+
helpStr = text;
|
|
1805
|
+
}
|
|
1806
|
+
if (helpStr) {
|
|
1807
|
+
context.write(`${helpStr}
|
|
1808
|
+
`);
|
|
1809
|
+
}
|
|
1810
|
+
});
|
|
1811
|
+
return this;
|
|
1812
|
+
}
|
|
1813
|
+
_outputHelpIfRequested(args) {
|
|
1814
|
+
const helpOption = this._getHelpOption();
|
|
1815
|
+
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
1816
|
+
if (helpRequested) {
|
|
1817
|
+
this.outputHelp();
|
|
1818
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
function incrementNodeInspectorPort(args) {
|
|
1823
|
+
return args.map((arg) => {
|
|
1824
|
+
if (!arg.startsWith("--inspect")) {
|
|
1825
|
+
return arg;
|
|
1826
|
+
}
|
|
1827
|
+
let debugOption;
|
|
1828
|
+
let debugHost = "127.0.0.1";
|
|
1829
|
+
let debugPort = "9229";
|
|
1830
|
+
let match;
|
|
1831
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
1832
|
+
debugOption = match[1];
|
|
1833
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
1834
|
+
debugOption = match[1];
|
|
1835
|
+
if (/^\d+$/.test(match[3])) {
|
|
1836
|
+
debugPort = match[3];
|
|
1837
|
+
} else {
|
|
1838
|
+
debugHost = match[3];
|
|
1839
|
+
}
|
|
1840
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
1841
|
+
debugOption = match[1];
|
|
1842
|
+
debugHost = match[3];
|
|
1843
|
+
debugPort = match[4];
|
|
1844
|
+
}
|
|
1845
|
+
if (debugOption && debugPort !== "0") {
|
|
1846
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
1847
|
+
}
|
|
1848
|
+
return arg;
|
|
1849
|
+
});
|
|
1850
|
+
}
|
|
1851
|
+
exports.Command = Command;
|
|
1852
|
+
});
|
|
1853
|
+
|
|
1854
|
+
// ../../node_modules/commander/index.js
|
|
1855
|
+
var require_commander = __commonJS((exports) => {
|
|
1856
|
+
var { Argument } = require_argument();
|
|
1857
|
+
var { Command } = require_command();
|
|
1858
|
+
var { CommanderError, InvalidArgumentError } = require_error();
|
|
1859
|
+
var { Help } = require_help();
|
|
1860
|
+
var { Option } = require_option();
|
|
1861
|
+
exports.program = new Command;
|
|
1862
|
+
exports.createCommand = (name) => new Command(name);
|
|
1863
|
+
exports.createOption = (flags, description) => new Option(flags, description);
|
|
1864
|
+
exports.createArgument = (name, description) => new Argument(name, description);
|
|
1865
|
+
exports.Command = Command;
|
|
1866
|
+
exports.Option = Option;
|
|
1867
|
+
exports.Argument = Argument;
|
|
1868
|
+
exports.Help = Help;
|
|
1869
|
+
exports.CommanderError = CommanderError;
|
|
1870
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
1871
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
1872
|
+
});
|
|
1873
|
+
|
|
1874
|
+
// ../../node_modules/color-name/index.js
|
|
1875
|
+
var require_color_name = __commonJS((exports, module) => {
|
|
1876
|
+
module.exports = {
|
|
1877
|
+
aliceblue: [240, 248, 255],
|
|
1878
|
+
antiquewhite: [250, 235, 215],
|
|
1879
|
+
aqua: [0, 255, 255],
|
|
1880
|
+
aquamarine: [127, 255, 212],
|
|
1881
|
+
azure: [240, 255, 255],
|
|
1882
|
+
beige: [245, 245, 220],
|
|
1883
|
+
bisque: [255, 228, 196],
|
|
1884
|
+
black: [0, 0, 0],
|
|
1885
|
+
blanchedalmond: [255, 235, 205],
|
|
1886
|
+
blue: [0, 0, 255],
|
|
1887
|
+
blueviolet: [138, 43, 226],
|
|
1888
|
+
brown: [165, 42, 42],
|
|
1889
|
+
burlywood: [222, 184, 135],
|
|
1890
|
+
cadetblue: [95, 158, 160],
|
|
1891
|
+
chartreuse: [127, 255, 0],
|
|
1892
|
+
chocolate: [210, 105, 30],
|
|
1893
|
+
coral: [255, 127, 80],
|
|
1894
|
+
cornflowerblue: [100, 149, 237],
|
|
1895
|
+
cornsilk: [255, 248, 220],
|
|
1896
|
+
crimson: [220, 20, 60],
|
|
1897
|
+
cyan: [0, 255, 255],
|
|
1898
|
+
darkblue: [0, 0, 139],
|
|
1899
|
+
darkcyan: [0, 139, 139],
|
|
1900
|
+
darkgoldenrod: [184, 134, 11],
|
|
1901
|
+
darkgray: [169, 169, 169],
|
|
1902
|
+
darkgreen: [0, 100, 0],
|
|
1903
|
+
darkgrey: [169, 169, 169],
|
|
1904
|
+
darkkhaki: [189, 183, 107],
|
|
1905
|
+
darkmagenta: [139, 0, 139],
|
|
1906
|
+
darkolivegreen: [85, 107, 47],
|
|
1907
|
+
darkorange: [255, 140, 0],
|
|
1908
|
+
darkorchid: [153, 50, 204],
|
|
1909
|
+
darkred: [139, 0, 0],
|
|
1910
|
+
darksalmon: [233, 150, 122],
|
|
1911
|
+
darkseagreen: [143, 188, 143],
|
|
1912
|
+
darkslateblue: [72, 61, 139],
|
|
1913
|
+
darkslategray: [47, 79, 79],
|
|
1914
|
+
darkslategrey: [47, 79, 79],
|
|
1915
|
+
darkturquoise: [0, 206, 209],
|
|
1916
|
+
darkviolet: [148, 0, 211],
|
|
1917
|
+
deeppink: [255, 20, 147],
|
|
1918
|
+
deepskyblue: [0, 191, 255],
|
|
1919
|
+
dimgray: [105, 105, 105],
|
|
1920
|
+
dimgrey: [105, 105, 105],
|
|
1921
|
+
dodgerblue: [30, 144, 255],
|
|
1922
|
+
firebrick: [178, 34, 34],
|
|
1923
|
+
floralwhite: [255, 250, 240],
|
|
1924
|
+
forestgreen: [34, 139, 34],
|
|
1925
|
+
fuchsia: [255, 0, 255],
|
|
1926
|
+
gainsboro: [220, 220, 220],
|
|
1927
|
+
ghostwhite: [248, 248, 255],
|
|
1928
|
+
gold: [255, 215, 0],
|
|
1929
|
+
goldenrod: [218, 165, 32],
|
|
1930
|
+
gray: [128, 128, 128],
|
|
1931
|
+
green: [0, 128, 0],
|
|
1932
|
+
greenyellow: [173, 255, 47],
|
|
1933
|
+
grey: [128, 128, 128],
|
|
1934
|
+
honeydew: [240, 255, 240],
|
|
1935
|
+
hotpink: [255, 105, 180],
|
|
1936
|
+
indianred: [205, 92, 92],
|
|
1937
|
+
indigo: [75, 0, 130],
|
|
1938
|
+
ivory: [255, 255, 240],
|
|
1939
|
+
khaki: [240, 230, 140],
|
|
1940
|
+
lavender: [230, 230, 250],
|
|
1941
|
+
lavenderblush: [255, 240, 245],
|
|
1942
|
+
lawngreen: [124, 252, 0],
|
|
1943
|
+
lemonchiffon: [255, 250, 205],
|
|
1944
|
+
lightblue: [173, 216, 230],
|
|
1945
|
+
lightcoral: [240, 128, 128],
|
|
1946
|
+
lightcyan: [224, 255, 255],
|
|
1947
|
+
lightgoldenrodyellow: [250, 250, 210],
|
|
1948
|
+
lightgray: [211, 211, 211],
|
|
1949
|
+
lightgreen: [144, 238, 144],
|
|
1950
|
+
lightgrey: [211, 211, 211],
|
|
1951
|
+
lightpink: [255, 182, 193],
|
|
1952
|
+
lightsalmon: [255, 160, 122],
|
|
1953
|
+
lightseagreen: [32, 178, 170],
|
|
1954
|
+
lightskyblue: [135, 206, 250],
|
|
1955
|
+
lightslategray: [119, 136, 153],
|
|
1956
|
+
lightslategrey: [119, 136, 153],
|
|
1957
|
+
lightsteelblue: [176, 196, 222],
|
|
1958
|
+
lightyellow: [255, 255, 224],
|
|
1959
|
+
lime: [0, 255, 0],
|
|
1960
|
+
limegreen: [50, 205, 50],
|
|
1961
|
+
linen: [250, 240, 230],
|
|
1962
|
+
magenta: [255, 0, 255],
|
|
1963
|
+
maroon: [128, 0, 0],
|
|
1964
|
+
mediumaquamarine: [102, 205, 170],
|
|
1965
|
+
mediumblue: [0, 0, 205],
|
|
1966
|
+
mediumorchid: [186, 85, 211],
|
|
1967
|
+
mediumpurple: [147, 112, 219],
|
|
1968
|
+
mediumseagreen: [60, 179, 113],
|
|
1969
|
+
mediumslateblue: [123, 104, 238],
|
|
1970
|
+
mediumspringgreen: [0, 250, 154],
|
|
1971
|
+
mediumturquoise: [72, 209, 204],
|
|
1972
|
+
mediumvioletred: [199, 21, 133],
|
|
1973
|
+
midnightblue: [25, 25, 112],
|
|
1974
|
+
mintcream: [245, 255, 250],
|
|
1975
|
+
mistyrose: [255, 228, 225],
|
|
1976
|
+
moccasin: [255, 228, 181],
|
|
1977
|
+
navajowhite: [255, 222, 173],
|
|
1978
|
+
navy: [0, 0, 128],
|
|
1979
|
+
oldlace: [253, 245, 230],
|
|
1980
|
+
olive: [128, 128, 0],
|
|
1981
|
+
olivedrab: [107, 142, 35],
|
|
1982
|
+
orange: [255, 165, 0],
|
|
1983
|
+
orangered: [255, 69, 0],
|
|
1984
|
+
orchid: [218, 112, 214],
|
|
1985
|
+
palegoldenrod: [238, 232, 170],
|
|
1986
|
+
palegreen: [152, 251, 152],
|
|
1987
|
+
paleturquoise: [175, 238, 238],
|
|
1988
|
+
palevioletred: [219, 112, 147],
|
|
1989
|
+
papayawhip: [255, 239, 213],
|
|
1990
|
+
peachpuff: [255, 218, 185],
|
|
1991
|
+
peru: [205, 133, 63],
|
|
1992
|
+
pink: [255, 192, 203],
|
|
1993
|
+
plum: [221, 160, 221],
|
|
1994
|
+
powderblue: [176, 224, 230],
|
|
1995
|
+
purple: [128, 0, 128],
|
|
1996
|
+
rebeccapurple: [102, 51, 153],
|
|
1997
|
+
red: [255, 0, 0],
|
|
1998
|
+
rosybrown: [188, 143, 143],
|
|
1999
|
+
royalblue: [65, 105, 225],
|
|
2000
|
+
saddlebrown: [139, 69, 19],
|
|
2001
|
+
salmon: [250, 128, 114],
|
|
2002
|
+
sandybrown: [244, 164, 96],
|
|
2003
|
+
seagreen: [46, 139, 87],
|
|
2004
|
+
seashell: [255, 245, 238],
|
|
2005
|
+
sienna: [160, 82, 45],
|
|
2006
|
+
silver: [192, 192, 192],
|
|
2007
|
+
skyblue: [135, 206, 235],
|
|
2008
|
+
slateblue: [106, 90, 205],
|
|
2009
|
+
slategray: [112, 128, 144],
|
|
2010
|
+
slategrey: [112, 128, 144],
|
|
2011
|
+
snow: [255, 250, 250],
|
|
2012
|
+
springgreen: [0, 255, 127],
|
|
2013
|
+
steelblue: [70, 130, 180],
|
|
2014
|
+
tan: [210, 180, 140],
|
|
2015
|
+
teal: [0, 128, 128],
|
|
2016
|
+
thistle: [216, 191, 216],
|
|
2017
|
+
tomato: [255, 99, 71],
|
|
2018
|
+
turquoise: [64, 224, 208],
|
|
2019
|
+
violet: [238, 130, 238],
|
|
2020
|
+
wheat: [245, 222, 179],
|
|
2021
|
+
white: [255, 255, 255],
|
|
2022
|
+
whitesmoke: [245, 245, 245],
|
|
2023
|
+
yellow: [255, 255, 0],
|
|
2024
|
+
yellowgreen: [154, 205, 50]
|
|
2025
|
+
};
|
|
2026
|
+
});
|
|
2027
|
+
|
|
2028
|
+
// ../../node_modules/color-convert/conversions.js
|
|
2029
|
+
var require_conversions = __commonJS((exports, module) => {
|
|
2030
|
+
var cssKeywords = require_color_name();
|
|
2031
|
+
var reverseKeywords = {};
|
|
2032
|
+
for (const key of Object.keys(cssKeywords)) {
|
|
2033
|
+
reverseKeywords[cssKeywords[key]] = key;
|
|
2034
|
+
}
|
|
2035
|
+
var convert = {
|
|
2036
|
+
rgb: { channels: 3, labels: "rgb" },
|
|
2037
|
+
hsl: { channels: 3, labels: "hsl" },
|
|
2038
|
+
hsv: { channels: 3, labels: "hsv" },
|
|
2039
|
+
hwb: { channels: 3, labels: "hwb" },
|
|
2040
|
+
cmyk: { channels: 4, labels: "cmyk" },
|
|
2041
|
+
xyz: { channels: 3, labels: "xyz" },
|
|
2042
|
+
lab: { channels: 3, labels: "lab" },
|
|
2043
|
+
lch: { channels: 3, labels: "lch" },
|
|
2044
|
+
hex: { channels: 1, labels: ["hex"] },
|
|
2045
|
+
keyword: { channels: 1, labels: ["keyword"] },
|
|
2046
|
+
ansi16: { channels: 1, labels: ["ansi16"] },
|
|
2047
|
+
ansi256: { channels: 1, labels: ["ansi256"] },
|
|
2048
|
+
hcg: { channels: 3, labels: ["h", "c", "g"] },
|
|
2049
|
+
apple: { channels: 3, labels: ["r16", "g16", "b16"] },
|
|
2050
|
+
gray: { channels: 1, labels: ["gray"] }
|
|
2051
|
+
};
|
|
2052
|
+
module.exports = convert;
|
|
2053
|
+
for (const model of Object.keys(convert)) {
|
|
2054
|
+
if (!("channels" in convert[model])) {
|
|
2055
|
+
throw new Error("missing channels property: " + model);
|
|
2056
|
+
}
|
|
2057
|
+
if (!("labels" in convert[model])) {
|
|
2058
|
+
throw new Error("missing channel labels property: " + model);
|
|
2059
|
+
}
|
|
2060
|
+
if (convert[model].labels.length !== convert[model].channels) {
|
|
2061
|
+
throw new Error("channel and label counts mismatch: " + model);
|
|
2062
|
+
}
|
|
2063
|
+
const { channels, labels } = convert[model];
|
|
2064
|
+
delete convert[model].channels;
|
|
2065
|
+
delete convert[model].labels;
|
|
2066
|
+
Object.defineProperty(convert[model], "channels", { value: channels });
|
|
2067
|
+
Object.defineProperty(convert[model], "labels", { value: labels });
|
|
2068
|
+
}
|
|
2069
|
+
convert.rgb.hsl = function(rgb) {
|
|
2070
|
+
const r = rgb[0] / 255;
|
|
2071
|
+
const g = rgb[1] / 255;
|
|
2072
|
+
const b = rgb[2] / 255;
|
|
2073
|
+
const min = Math.min(r, g, b);
|
|
2074
|
+
const max = Math.max(r, g, b);
|
|
2075
|
+
const delta = max - min;
|
|
2076
|
+
let h;
|
|
2077
|
+
let s;
|
|
2078
|
+
if (max === min) {
|
|
2079
|
+
h = 0;
|
|
2080
|
+
} else if (r === max) {
|
|
2081
|
+
h = (g - b) / delta;
|
|
2082
|
+
} else if (g === max) {
|
|
2083
|
+
h = 2 + (b - r) / delta;
|
|
2084
|
+
} else if (b === max) {
|
|
2085
|
+
h = 4 + (r - g) / delta;
|
|
2086
|
+
}
|
|
2087
|
+
h = Math.min(h * 60, 360);
|
|
2088
|
+
if (h < 0) {
|
|
2089
|
+
h += 360;
|
|
2090
|
+
}
|
|
2091
|
+
const l = (min + max) / 2;
|
|
2092
|
+
if (max === min) {
|
|
2093
|
+
s = 0;
|
|
2094
|
+
} else if (l <= 0.5) {
|
|
2095
|
+
s = delta / (max + min);
|
|
2096
|
+
} else {
|
|
2097
|
+
s = delta / (2 - max - min);
|
|
2098
|
+
}
|
|
2099
|
+
return [h, s * 100, l * 100];
|
|
2100
|
+
};
|
|
2101
|
+
convert.rgb.hsv = function(rgb) {
|
|
2102
|
+
let rdif;
|
|
2103
|
+
let gdif;
|
|
2104
|
+
let bdif;
|
|
2105
|
+
let h;
|
|
2106
|
+
let s;
|
|
2107
|
+
const r = rgb[0] / 255;
|
|
2108
|
+
const g = rgb[1] / 255;
|
|
2109
|
+
const b = rgb[2] / 255;
|
|
2110
|
+
const v = Math.max(r, g, b);
|
|
2111
|
+
const diff = v - Math.min(r, g, b);
|
|
2112
|
+
const diffc = function(c) {
|
|
2113
|
+
return (v - c) / 6 / diff + 1 / 2;
|
|
2114
|
+
};
|
|
2115
|
+
if (diff === 0) {
|
|
2116
|
+
h = 0;
|
|
2117
|
+
s = 0;
|
|
2118
|
+
} else {
|
|
2119
|
+
s = diff / v;
|
|
2120
|
+
rdif = diffc(r);
|
|
2121
|
+
gdif = diffc(g);
|
|
2122
|
+
bdif = diffc(b);
|
|
2123
|
+
if (r === v) {
|
|
2124
|
+
h = bdif - gdif;
|
|
2125
|
+
} else if (g === v) {
|
|
2126
|
+
h = 1 / 3 + rdif - bdif;
|
|
2127
|
+
} else if (b === v) {
|
|
2128
|
+
h = 2 / 3 + gdif - rdif;
|
|
2129
|
+
}
|
|
2130
|
+
if (h < 0) {
|
|
2131
|
+
h += 1;
|
|
2132
|
+
} else if (h > 1) {
|
|
2133
|
+
h -= 1;
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
return [
|
|
2137
|
+
h * 360,
|
|
2138
|
+
s * 100,
|
|
2139
|
+
v * 100
|
|
2140
|
+
];
|
|
2141
|
+
};
|
|
2142
|
+
convert.rgb.hwb = function(rgb) {
|
|
2143
|
+
const r = rgb[0];
|
|
2144
|
+
const g = rgb[1];
|
|
2145
|
+
let b = rgb[2];
|
|
2146
|
+
const h = convert.rgb.hsl(rgb)[0];
|
|
2147
|
+
const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
|
2148
|
+
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
|
2149
|
+
return [h, w * 100, b * 100];
|
|
2150
|
+
};
|
|
2151
|
+
convert.rgb.cmyk = function(rgb) {
|
|
2152
|
+
const r = rgb[0] / 255;
|
|
2153
|
+
const g = rgb[1] / 255;
|
|
2154
|
+
const b = rgb[2] / 255;
|
|
2155
|
+
const k = Math.min(1 - r, 1 - g, 1 - b);
|
|
2156
|
+
const c = (1 - r - k) / (1 - k) || 0;
|
|
2157
|
+
const m = (1 - g - k) / (1 - k) || 0;
|
|
2158
|
+
const y = (1 - b - k) / (1 - k) || 0;
|
|
2159
|
+
return [c * 100, m * 100, y * 100, k * 100];
|
|
2160
|
+
};
|
|
2161
|
+
function comparativeDistance(x, y) {
|
|
2162
|
+
return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
|
|
2163
|
+
}
|
|
2164
|
+
convert.rgb.keyword = function(rgb) {
|
|
2165
|
+
const reversed = reverseKeywords[rgb];
|
|
2166
|
+
if (reversed) {
|
|
2167
|
+
return reversed;
|
|
2168
|
+
}
|
|
2169
|
+
let currentClosestDistance = Infinity;
|
|
2170
|
+
let currentClosestKeyword;
|
|
2171
|
+
for (const keyword of Object.keys(cssKeywords)) {
|
|
2172
|
+
const value = cssKeywords[keyword];
|
|
2173
|
+
const distance = comparativeDistance(rgb, value);
|
|
2174
|
+
if (distance < currentClosestDistance) {
|
|
2175
|
+
currentClosestDistance = distance;
|
|
2176
|
+
currentClosestKeyword = keyword;
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
return currentClosestKeyword;
|
|
2180
|
+
};
|
|
2181
|
+
convert.keyword.rgb = function(keyword) {
|
|
2182
|
+
return cssKeywords[keyword];
|
|
2183
|
+
};
|
|
2184
|
+
convert.rgb.xyz = function(rgb) {
|
|
2185
|
+
let r = rgb[0] / 255;
|
|
2186
|
+
let g = rgb[1] / 255;
|
|
2187
|
+
let b = rgb[2] / 255;
|
|
2188
|
+
r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
|
|
2189
|
+
g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
|
|
2190
|
+
b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
|
|
2191
|
+
const x = r * 0.4124 + g * 0.3576 + b * 0.1805;
|
|
2192
|
+
const y = r * 0.2126 + g * 0.7152 + b * 0.0722;
|
|
2193
|
+
const z = r * 0.0193 + g * 0.1192 + b * 0.9505;
|
|
2194
|
+
return [x * 100, y * 100, z * 100];
|
|
2195
|
+
};
|
|
2196
|
+
convert.rgb.lab = function(rgb) {
|
|
2197
|
+
const xyz = convert.rgb.xyz(rgb);
|
|
2198
|
+
let x = xyz[0];
|
|
2199
|
+
let y = xyz[1];
|
|
2200
|
+
let z = xyz[2];
|
|
2201
|
+
x /= 95.047;
|
|
2202
|
+
y /= 100;
|
|
2203
|
+
z /= 108.883;
|
|
2204
|
+
x = x > 0.008856 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
|
2205
|
+
y = y > 0.008856 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
|
2206
|
+
z = z > 0.008856 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
|
2207
|
+
const l = 116 * y - 16;
|
|
2208
|
+
const a = 500 * (x - y);
|
|
2209
|
+
const b = 200 * (y - z);
|
|
2210
|
+
return [l, a, b];
|
|
2211
|
+
};
|
|
2212
|
+
convert.hsl.rgb = function(hsl) {
|
|
2213
|
+
const h = hsl[0] / 360;
|
|
2214
|
+
const s = hsl[1] / 100;
|
|
2215
|
+
const l = hsl[2] / 100;
|
|
2216
|
+
let t2;
|
|
2217
|
+
let t3;
|
|
2218
|
+
let val;
|
|
2219
|
+
if (s === 0) {
|
|
2220
|
+
val = l * 255;
|
|
2221
|
+
return [val, val, val];
|
|
2222
|
+
}
|
|
2223
|
+
if (l < 0.5) {
|
|
2224
|
+
t2 = l * (1 + s);
|
|
2225
|
+
} else {
|
|
2226
|
+
t2 = l + s - l * s;
|
|
2227
|
+
}
|
|
2228
|
+
const t1 = 2 * l - t2;
|
|
2229
|
+
const rgb = [0, 0, 0];
|
|
2230
|
+
for (let i = 0;i < 3; i++) {
|
|
2231
|
+
t3 = h + 1 / 3 * -(i - 1);
|
|
2232
|
+
if (t3 < 0) {
|
|
2233
|
+
t3++;
|
|
2234
|
+
}
|
|
2235
|
+
if (t3 > 1) {
|
|
2236
|
+
t3--;
|
|
2237
|
+
}
|
|
2238
|
+
if (6 * t3 < 1) {
|
|
2239
|
+
val = t1 + (t2 - t1) * 6 * t3;
|
|
2240
|
+
} else if (2 * t3 < 1) {
|
|
2241
|
+
val = t2;
|
|
2242
|
+
} else if (3 * t3 < 2) {
|
|
2243
|
+
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
2244
|
+
} else {
|
|
2245
|
+
val = t1;
|
|
2246
|
+
}
|
|
2247
|
+
rgb[i] = val * 255;
|
|
2248
|
+
}
|
|
2249
|
+
return rgb;
|
|
2250
|
+
};
|
|
2251
|
+
convert.hsl.hsv = function(hsl) {
|
|
2252
|
+
const h = hsl[0];
|
|
2253
|
+
let s = hsl[1] / 100;
|
|
2254
|
+
let l = hsl[2] / 100;
|
|
2255
|
+
let smin = s;
|
|
2256
|
+
const lmin = Math.max(l, 0.01);
|
|
2257
|
+
l *= 2;
|
|
2258
|
+
s *= l <= 1 ? l : 2 - l;
|
|
2259
|
+
smin *= lmin <= 1 ? lmin : 2 - lmin;
|
|
2260
|
+
const v = (l + s) / 2;
|
|
2261
|
+
const sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
|
|
2262
|
+
return [h, sv * 100, v * 100];
|
|
2263
|
+
};
|
|
2264
|
+
convert.hsv.rgb = function(hsv) {
|
|
2265
|
+
const h = hsv[0] / 60;
|
|
2266
|
+
const s = hsv[1] / 100;
|
|
2267
|
+
let v = hsv[2] / 100;
|
|
2268
|
+
const hi = Math.floor(h) % 6;
|
|
2269
|
+
const f = h - Math.floor(h);
|
|
2270
|
+
const p = 255 * v * (1 - s);
|
|
2271
|
+
const q = 255 * v * (1 - s * f);
|
|
2272
|
+
const t = 255 * v * (1 - s * (1 - f));
|
|
2273
|
+
v *= 255;
|
|
2274
|
+
switch (hi) {
|
|
2275
|
+
case 0:
|
|
2276
|
+
return [v, t, p];
|
|
2277
|
+
case 1:
|
|
2278
|
+
return [q, v, p];
|
|
2279
|
+
case 2:
|
|
2280
|
+
return [p, v, t];
|
|
2281
|
+
case 3:
|
|
2282
|
+
return [p, q, v];
|
|
2283
|
+
case 4:
|
|
2284
|
+
return [t, p, v];
|
|
2285
|
+
case 5:
|
|
2286
|
+
return [v, p, q];
|
|
2287
|
+
}
|
|
2288
|
+
};
|
|
2289
|
+
convert.hsv.hsl = function(hsv) {
|
|
2290
|
+
const h = hsv[0];
|
|
2291
|
+
const s = hsv[1] / 100;
|
|
2292
|
+
const v = hsv[2] / 100;
|
|
2293
|
+
const vmin = Math.max(v, 0.01);
|
|
2294
|
+
let sl;
|
|
2295
|
+
let l;
|
|
2296
|
+
l = (2 - s) * v;
|
|
2297
|
+
const lmin = (2 - s) * vmin;
|
|
2298
|
+
sl = s * vmin;
|
|
2299
|
+
sl /= lmin <= 1 ? lmin : 2 - lmin;
|
|
2300
|
+
sl = sl || 0;
|
|
2301
|
+
l /= 2;
|
|
2302
|
+
return [h, sl * 100, l * 100];
|
|
2303
|
+
};
|
|
2304
|
+
convert.hwb.rgb = function(hwb) {
|
|
2305
|
+
const h = hwb[0] / 360;
|
|
2306
|
+
let wh = hwb[1] / 100;
|
|
2307
|
+
let bl = hwb[2] / 100;
|
|
2308
|
+
const ratio = wh + bl;
|
|
2309
|
+
let f;
|
|
2310
|
+
if (ratio > 1) {
|
|
2311
|
+
wh /= ratio;
|
|
2312
|
+
bl /= ratio;
|
|
2313
|
+
}
|
|
2314
|
+
const i = Math.floor(6 * h);
|
|
2315
|
+
const v = 1 - bl;
|
|
2316
|
+
f = 6 * h - i;
|
|
2317
|
+
if ((i & 1) !== 0) {
|
|
2318
|
+
f = 1 - f;
|
|
2319
|
+
}
|
|
2320
|
+
const n = wh + f * (v - wh);
|
|
2321
|
+
let r;
|
|
2322
|
+
let g;
|
|
2323
|
+
let b;
|
|
2324
|
+
switch (i) {
|
|
2325
|
+
default:
|
|
2326
|
+
case 6:
|
|
2327
|
+
case 0:
|
|
2328
|
+
r = v;
|
|
2329
|
+
g = n;
|
|
2330
|
+
b = wh;
|
|
2331
|
+
break;
|
|
2332
|
+
case 1:
|
|
2333
|
+
r = n;
|
|
2334
|
+
g = v;
|
|
2335
|
+
b = wh;
|
|
2336
|
+
break;
|
|
2337
|
+
case 2:
|
|
2338
|
+
r = wh;
|
|
2339
|
+
g = v;
|
|
2340
|
+
b = n;
|
|
2341
|
+
break;
|
|
2342
|
+
case 3:
|
|
2343
|
+
r = wh;
|
|
2344
|
+
g = n;
|
|
2345
|
+
b = v;
|
|
2346
|
+
break;
|
|
2347
|
+
case 4:
|
|
2348
|
+
r = n;
|
|
2349
|
+
g = wh;
|
|
2350
|
+
b = v;
|
|
2351
|
+
break;
|
|
2352
|
+
case 5:
|
|
2353
|
+
r = v;
|
|
2354
|
+
g = wh;
|
|
2355
|
+
b = n;
|
|
2356
|
+
break;
|
|
2357
|
+
}
|
|
2358
|
+
return [r * 255, g * 255, b * 255];
|
|
2359
|
+
};
|
|
2360
|
+
convert.cmyk.rgb = function(cmyk) {
|
|
2361
|
+
const c = cmyk[0] / 100;
|
|
2362
|
+
const m = cmyk[1] / 100;
|
|
2363
|
+
const y = cmyk[2] / 100;
|
|
2364
|
+
const k = cmyk[3] / 100;
|
|
2365
|
+
const r = 1 - Math.min(1, c * (1 - k) + k);
|
|
2366
|
+
const g = 1 - Math.min(1, m * (1 - k) + k);
|
|
2367
|
+
const b = 1 - Math.min(1, y * (1 - k) + k);
|
|
2368
|
+
return [r * 255, g * 255, b * 255];
|
|
2369
|
+
};
|
|
2370
|
+
convert.xyz.rgb = function(xyz) {
|
|
2371
|
+
const x = xyz[0] / 100;
|
|
2372
|
+
const y = xyz[1] / 100;
|
|
2373
|
+
const z = xyz[2] / 100;
|
|
2374
|
+
let r;
|
|
2375
|
+
let g;
|
|
2376
|
+
let b;
|
|
2377
|
+
r = x * 3.2406 + y * -1.5372 + z * -0.4986;
|
|
2378
|
+
g = x * -0.9689 + y * 1.8758 + z * 0.0415;
|
|
2379
|
+
b = x * 0.0557 + y * -0.204 + z * 1.057;
|
|
2380
|
+
r = r > 0.0031308 ? 1.055 * r ** (1 / 2.4) - 0.055 : r * 12.92;
|
|
2381
|
+
g = g > 0.0031308 ? 1.055 * g ** (1 / 2.4) - 0.055 : g * 12.92;
|
|
2382
|
+
b = b > 0.0031308 ? 1.055 * b ** (1 / 2.4) - 0.055 : b * 12.92;
|
|
2383
|
+
r = Math.min(Math.max(0, r), 1);
|
|
2384
|
+
g = Math.min(Math.max(0, g), 1);
|
|
2385
|
+
b = Math.min(Math.max(0, b), 1);
|
|
2386
|
+
return [r * 255, g * 255, b * 255];
|
|
2387
|
+
};
|
|
2388
|
+
convert.xyz.lab = function(xyz) {
|
|
2389
|
+
let x = xyz[0];
|
|
2390
|
+
let y = xyz[1];
|
|
2391
|
+
let z = xyz[2];
|
|
2392
|
+
x /= 95.047;
|
|
2393
|
+
y /= 100;
|
|
2394
|
+
z /= 108.883;
|
|
2395
|
+
x = x > 0.008856 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
|
2396
|
+
y = y > 0.008856 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
|
2397
|
+
z = z > 0.008856 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
|
2398
|
+
const l = 116 * y - 16;
|
|
2399
|
+
const a = 500 * (x - y);
|
|
2400
|
+
const b = 200 * (y - z);
|
|
2401
|
+
return [l, a, b];
|
|
2402
|
+
};
|
|
2403
|
+
convert.lab.xyz = function(lab) {
|
|
2404
|
+
const l = lab[0];
|
|
2405
|
+
const a = lab[1];
|
|
2406
|
+
const b = lab[2];
|
|
2407
|
+
let x;
|
|
2408
|
+
let y;
|
|
2409
|
+
let z;
|
|
2410
|
+
y = (l + 16) / 116;
|
|
2411
|
+
x = a / 500 + y;
|
|
2412
|
+
z = y - b / 200;
|
|
2413
|
+
const y2 = y ** 3;
|
|
2414
|
+
const x2 = x ** 3;
|
|
2415
|
+
const z2 = z ** 3;
|
|
2416
|
+
y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
|
|
2417
|
+
x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
|
|
2418
|
+
z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
|
|
2419
|
+
x *= 95.047;
|
|
2420
|
+
y *= 100;
|
|
2421
|
+
z *= 108.883;
|
|
2422
|
+
return [x, y, z];
|
|
2423
|
+
};
|
|
2424
|
+
convert.lab.lch = function(lab) {
|
|
2425
|
+
const l = lab[0];
|
|
2426
|
+
const a = lab[1];
|
|
2427
|
+
const b = lab[2];
|
|
2428
|
+
let h;
|
|
2429
|
+
const hr = Math.atan2(b, a);
|
|
2430
|
+
h = hr * 360 / 2 / Math.PI;
|
|
2431
|
+
if (h < 0) {
|
|
2432
|
+
h += 360;
|
|
2433
|
+
}
|
|
2434
|
+
const c = Math.sqrt(a * a + b * b);
|
|
2435
|
+
return [l, c, h];
|
|
2436
|
+
};
|
|
2437
|
+
convert.lch.lab = function(lch) {
|
|
2438
|
+
const l = lch[0];
|
|
2439
|
+
const c = lch[1];
|
|
2440
|
+
const h = lch[2];
|
|
2441
|
+
const hr = h / 360 * 2 * Math.PI;
|
|
2442
|
+
const a = c * Math.cos(hr);
|
|
2443
|
+
const b = c * Math.sin(hr);
|
|
2444
|
+
return [l, a, b];
|
|
2445
|
+
};
|
|
2446
|
+
convert.rgb.ansi16 = function(args, saturation = null) {
|
|
2447
|
+
const [r, g, b] = args;
|
|
2448
|
+
let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation;
|
|
2449
|
+
value = Math.round(value / 50);
|
|
2450
|
+
if (value === 0) {
|
|
2451
|
+
return 30;
|
|
2452
|
+
}
|
|
2453
|
+
let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
|
|
2454
|
+
if (value === 2) {
|
|
2455
|
+
ansi += 60;
|
|
2456
|
+
}
|
|
2457
|
+
return ansi;
|
|
2458
|
+
};
|
|
2459
|
+
convert.hsv.ansi16 = function(args) {
|
|
2460
|
+
return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
|
|
2461
|
+
};
|
|
2462
|
+
convert.rgb.ansi256 = function(args) {
|
|
2463
|
+
const r = args[0];
|
|
2464
|
+
const g = args[1];
|
|
2465
|
+
const b = args[2];
|
|
2466
|
+
if (r === g && g === b) {
|
|
2467
|
+
if (r < 8) {
|
|
2468
|
+
return 16;
|
|
2469
|
+
}
|
|
2470
|
+
if (r > 248) {
|
|
2471
|
+
return 231;
|
|
2472
|
+
}
|
|
2473
|
+
return Math.round((r - 8) / 247 * 24) + 232;
|
|
2474
|
+
}
|
|
2475
|
+
const ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
|
|
2476
|
+
return ansi;
|
|
2477
|
+
};
|
|
2478
|
+
convert.ansi16.rgb = function(args) {
|
|
2479
|
+
let color = args % 10;
|
|
2480
|
+
if (color === 0 || color === 7) {
|
|
2481
|
+
if (args > 50) {
|
|
2482
|
+
color += 3.5;
|
|
2483
|
+
}
|
|
2484
|
+
color = color / 10.5 * 255;
|
|
2485
|
+
return [color, color, color];
|
|
2486
|
+
}
|
|
2487
|
+
const mult = (~~(args > 50) + 1) * 0.5;
|
|
2488
|
+
const r = (color & 1) * mult * 255;
|
|
2489
|
+
const g = (color >> 1 & 1) * mult * 255;
|
|
2490
|
+
const b = (color >> 2 & 1) * mult * 255;
|
|
2491
|
+
return [r, g, b];
|
|
2492
|
+
};
|
|
2493
|
+
convert.ansi256.rgb = function(args) {
|
|
2494
|
+
if (args >= 232) {
|
|
2495
|
+
const c = (args - 232) * 10 + 8;
|
|
2496
|
+
return [c, c, c];
|
|
2497
|
+
}
|
|
2498
|
+
args -= 16;
|
|
2499
|
+
let rem;
|
|
2500
|
+
const r = Math.floor(args / 36) / 5 * 255;
|
|
2501
|
+
const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
|
2502
|
+
const b = rem % 6 / 5 * 255;
|
|
2503
|
+
return [r, g, b];
|
|
2504
|
+
};
|
|
2505
|
+
convert.rgb.hex = function(args) {
|
|
2506
|
+
const integer = ((Math.round(args[0]) & 255) << 16) + ((Math.round(args[1]) & 255) << 8) + (Math.round(args[2]) & 255);
|
|
2507
|
+
const string = integer.toString(16).toUpperCase();
|
|
2508
|
+
return "000000".substring(string.length) + string;
|
|
2509
|
+
};
|
|
2510
|
+
convert.hex.rgb = function(args) {
|
|
2511
|
+
const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
2512
|
+
if (!match) {
|
|
2513
|
+
return [0, 0, 0];
|
|
2514
|
+
}
|
|
2515
|
+
let colorString = match[0];
|
|
2516
|
+
if (match[0].length === 3) {
|
|
2517
|
+
colorString = colorString.split("").map((char) => {
|
|
2518
|
+
return char + char;
|
|
2519
|
+
}).join("");
|
|
2520
|
+
}
|
|
2521
|
+
const integer = parseInt(colorString, 16);
|
|
2522
|
+
const r = integer >> 16 & 255;
|
|
2523
|
+
const g = integer >> 8 & 255;
|
|
2524
|
+
const b = integer & 255;
|
|
2525
|
+
return [r, g, b];
|
|
2526
|
+
};
|
|
2527
|
+
convert.rgb.hcg = function(rgb) {
|
|
2528
|
+
const r = rgb[0] / 255;
|
|
2529
|
+
const g = rgb[1] / 255;
|
|
2530
|
+
const b = rgb[2] / 255;
|
|
2531
|
+
const max = Math.max(Math.max(r, g), b);
|
|
2532
|
+
const min = Math.min(Math.min(r, g), b);
|
|
2533
|
+
const chroma = max - min;
|
|
2534
|
+
let grayscale;
|
|
2535
|
+
let hue;
|
|
2536
|
+
if (chroma < 1) {
|
|
2537
|
+
grayscale = min / (1 - chroma);
|
|
2538
|
+
} else {
|
|
2539
|
+
grayscale = 0;
|
|
2540
|
+
}
|
|
2541
|
+
if (chroma <= 0) {
|
|
2542
|
+
hue = 0;
|
|
2543
|
+
} else if (max === r) {
|
|
2544
|
+
hue = (g - b) / chroma % 6;
|
|
2545
|
+
} else if (max === g) {
|
|
2546
|
+
hue = 2 + (b - r) / chroma;
|
|
2547
|
+
} else {
|
|
2548
|
+
hue = 4 + (r - g) / chroma;
|
|
2549
|
+
}
|
|
2550
|
+
hue /= 6;
|
|
2551
|
+
hue %= 1;
|
|
2552
|
+
return [hue * 360, chroma * 100, grayscale * 100];
|
|
2553
|
+
};
|
|
2554
|
+
convert.hsl.hcg = function(hsl) {
|
|
2555
|
+
const s = hsl[1] / 100;
|
|
2556
|
+
const l = hsl[2] / 100;
|
|
2557
|
+
const c = l < 0.5 ? 2 * s * l : 2 * s * (1 - l);
|
|
2558
|
+
let f = 0;
|
|
2559
|
+
if (c < 1) {
|
|
2560
|
+
f = (l - 0.5 * c) / (1 - c);
|
|
2561
|
+
}
|
|
2562
|
+
return [hsl[0], c * 100, f * 100];
|
|
2563
|
+
};
|
|
2564
|
+
convert.hsv.hcg = function(hsv) {
|
|
2565
|
+
const s = hsv[1] / 100;
|
|
2566
|
+
const v = hsv[2] / 100;
|
|
2567
|
+
const c = s * v;
|
|
2568
|
+
let f = 0;
|
|
2569
|
+
if (c < 1) {
|
|
2570
|
+
f = (v - c) / (1 - c);
|
|
2571
|
+
}
|
|
2572
|
+
return [hsv[0], c * 100, f * 100];
|
|
2573
|
+
};
|
|
2574
|
+
convert.hcg.rgb = function(hcg) {
|
|
2575
|
+
const h = hcg[0] / 360;
|
|
2576
|
+
const c = hcg[1] / 100;
|
|
2577
|
+
const g = hcg[2] / 100;
|
|
2578
|
+
if (c === 0) {
|
|
2579
|
+
return [g * 255, g * 255, g * 255];
|
|
2580
|
+
}
|
|
2581
|
+
const pure = [0, 0, 0];
|
|
2582
|
+
const hi = h % 1 * 6;
|
|
2583
|
+
const v = hi % 1;
|
|
2584
|
+
const w = 1 - v;
|
|
2585
|
+
let mg = 0;
|
|
2586
|
+
switch (Math.floor(hi)) {
|
|
2587
|
+
case 0:
|
|
2588
|
+
pure[0] = 1;
|
|
2589
|
+
pure[1] = v;
|
|
2590
|
+
pure[2] = 0;
|
|
2591
|
+
break;
|
|
2592
|
+
case 1:
|
|
2593
|
+
pure[0] = w;
|
|
2594
|
+
pure[1] = 1;
|
|
2595
|
+
pure[2] = 0;
|
|
2596
|
+
break;
|
|
2597
|
+
case 2:
|
|
2598
|
+
pure[0] = 0;
|
|
2599
|
+
pure[1] = 1;
|
|
2600
|
+
pure[2] = v;
|
|
2601
|
+
break;
|
|
2602
|
+
case 3:
|
|
2603
|
+
pure[0] = 0;
|
|
2604
|
+
pure[1] = w;
|
|
2605
|
+
pure[2] = 1;
|
|
2606
|
+
break;
|
|
2607
|
+
case 4:
|
|
2608
|
+
pure[0] = v;
|
|
2609
|
+
pure[1] = 0;
|
|
2610
|
+
pure[2] = 1;
|
|
2611
|
+
break;
|
|
2612
|
+
default:
|
|
2613
|
+
pure[0] = 1;
|
|
2614
|
+
pure[1] = 0;
|
|
2615
|
+
pure[2] = w;
|
|
2616
|
+
}
|
|
2617
|
+
mg = (1 - c) * g;
|
|
2618
|
+
return [
|
|
2619
|
+
(c * pure[0] + mg) * 255,
|
|
2620
|
+
(c * pure[1] + mg) * 255,
|
|
2621
|
+
(c * pure[2] + mg) * 255
|
|
2622
|
+
];
|
|
2623
|
+
};
|
|
2624
|
+
convert.hcg.hsv = function(hcg) {
|
|
2625
|
+
const c = hcg[1] / 100;
|
|
2626
|
+
const g = hcg[2] / 100;
|
|
2627
|
+
const v = c + g * (1 - c);
|
|
2628
|
+
let f = 0;
|
|
2629
|
+
if (v > 0) {
|
|
2630
|
+
f = c / v;
|
|
2631
|
+
}
|
|
2632
|
+
return [hcg[0], f * 100, v * 100];
|
|
2633
|
+
};
|
|
2634
|
+
convert.hcg.hsl = function(hcg) {
|
|
2635
|
+
const c = hcg[1] / 100;
|
|
2636
|
+
const g = hcg[2] / 100;
|
|
2637
|
+
const l = g * (1 - c) + 0.5 * c;
|
|
2638
|
+
let s = 0;
|
|
2639
|
+
if (l > 0 && l < 0.5) {
|
|
2640
|
+
s = c / (2 * l);
|
|
2641
|
+
} else if (l >= 0.5 && l < 1) {
|
|
2642
|
+
s = c / (2 * (1 - l));
|
|
2643
|
+
}
|
|
2644
|
+
return [hcg[0], s * 100, l * 100];
|
|
2645
|
+
};
|
|
2646
|
+
convert.hcg.hwb = function(hcg) {
|
|
2647
|
+
const c = hcg[1] / 100;
|
|
2648
|
+
const g = hcg[2] / 100;
|
|
2649
|
+
const v = c + g * (1 - c);
|
|
2650
|
+
return [hcg[0], (v - c) * 100, (1 - v) * 100];
|
|
2651
|
+
};
|
|
2652
|
+
convert.hwb.hcg = function(hwb) {
|
|
2653
|
+
const w = hwb[1] / 100;
|
|
2654
|
+
const b = hwb[2] / 100;
|
|
2655
|
+
const v = 1 - b;
|
|
2656
|
+
const c = v - w;
|
|
2657
|
+
let g = 0;
|
|
2658
|
+
if (c < 1) {
|
|
2659
|
+
g = (v - c) / (1 - c);
|
|
2660
|
+
}
|
|
2661
|
+
return [hwb[0], c * 100, g * 100];
|
|
2662
|
+
};
|
|
2663
|
+
convert.apple.rgb = function(apple) {
|
|
2664
|
+
return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
|
|
2665
|
+
};
|
|
2666
|
+
convert.rgb.apple = function(rgb) {
|
|
2667
|
+
return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
|
|
2668
|
+
};
|
|
2669
|
+
convert.gray.rgb = function(args) {
|
|
2670
|
+
return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
|
2671
|
+
};
|
|
2672
|
+
convert.gray.hsl = function(args) {
|
|
2673
|
+
return [0, 0, args[0]];
|
|
2674
|
+
};
|
|
2675
|
+
convert.gray.hsv = convert.gray.hsl;
|
|
2676
|
+
convert.gray.hwb = function(gray) {
|
|
2677
|
+
return [0, 100, gray[0]];
|
|
2678
|
+
};
|
|
2679
|
+
convert.gray.cmyk = function(gray) {
|
|
2680
|
+
return [0, 0, 0, gray[0]];
|
|
2681
|
+
};
|
|
2682
|
+
convert.gray.lab = function(gray) {
|
|
2683
|
+
return [gray[0], 0, 0];
|
|
2684
|
+
};
|
|
2685
|
+
convert.gray.hex = function(gray) {
|
|
2686
|
+
const val = Math.round(gray[0] / 100 * 255) & 255;
|
|
2687
|
+
const integer = (val << 16) + (val << 8) + val;
|
|
2688
|
+
const string = integer.toString(16).toUpperCase();
|
|
2689
|
+
return "000000".substring(string.length) + string;
|
|
2690
|
+
};
|
|
2691
|
+
convert.rgb.gray = function(rgb) {
|
|
2692
|
+
const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
|
2693
|
+
return [val / 255 * 100];
|
|
2694
|
+
};
|
|
2695
|
+
});
|
|
2696
|
+
|
|
2697
|
+
// ../../node_modules/color-convert/route.js
|
|
2698
|
+
var require_route = __commonJS((exports, module) => {
|
|
2699
|
+
var conversions = require_conversions();
|
|
2700
|
+
function buildGraph() {
|
|
2701
|
+
const graph = {};
|
|
2702
|
+
const models = Object.keys(conversions);
|
|
2703
|
+
for (let len = models.length, i = 0;i < len; i++) {
|
|
2704
|
+
graph[models[i]] = {
|
|
2705
|
+
distance: -1,
|
|
2706
|
+
parent: null
|
|
2707
|
+
};
|
|
2708
|
+
}
|
|
2709
|
+
return graph;
|
|
2710
|
+
}
|
|
2711
|
+
function deriveBFS(fromModel) {
|
|
2712
|
+
const graph = buildGraph();
|
|
2713
|
+
const queue = [fromModel];
|
|
2714
|
+
graph[fromModel].distance = 0;
|
|
2715
|
+
while (queue.length) {
|
|
2716
|
+
const current = queue.pop();
|
|
2717
|
+
const adjacents = Object.keys(conversions[current]);
|
|
2718
|
+
for (let len = adjacents.length, i = 0;i < len; i++) {
|
|
2719
|
+
const adjacent = adjacents[i];
|
|
2720
|
+
const node = graph[adjacent];
|
|
2721
|
+
if (node.distance === -1) {
|
|
2722
|
+
node.distance = graph[current].distance + 1;
|
|
2723
|
+
node.parent = current;
|
|
2724
|
+
queue.unshift(adjacent);
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
return graph;
|
|
2729
|
+
}
|
|
2730
|
+
function link(from, to) {
|
|
2731
|
+
return function(args) {
|
|
2732
|
+
return to(from(args));
|
|
2733
|
+
};
|
|
2734
|
+
}
|
|
2735
|
+
function wrapConversion(toModel, graph) {
|
|
2736
|
+
const path = [graph[toModel].parent, toModel];
|
|
2737
|
+
let fn = conversions[graph[toModel].parent][toModel];
|
|
2738
|
+
let cur = graph[toModel].parent;
|
|
2739
|
+
while (graph[cur].parent) {
|
|
2740
|
+
path.unshift(graph[cur].parent);
|
|
2741
|
+
fn = link(conversions[graph[cur].parent][cur], fn);
|
|
2742
|
+
cur = graph[cur].parent;
|
|
2743
|
+
}
|
|
2744
|
+
fn.conversion = path;
|
|
2745
|
+
return fn;
|
|
2746
|
+
}
|
|
2747
|
+
module.exports = function(fromModel) {
|
|
2748
|
+
const graph = deriveBFS(fromModel);
|
|
2749
|
+
const conversion = {};
|
|
2750
|
+
const models = Object.keys(graph);
|
|
2751
|
+
for (let len = models.length, i = 0;i < len; i++) {
|
|
2752
|
+
const toModel = models[i];
|
|
2753
|
+
const node = graph[toModel];
|
|
2754
|
+
if (node.parent === null) {
|
|
2755
|
+
continue;
|
|
2756
|
+
}
|
|
2757
|
+
conversion[toModel] = wrapConversion(toModel, graph);
|
|
2758
|
+
}
|
|
2759
|
+
return conversion;
|
|
2760
|
+
};
|
|
2761
|
+
});
|
|
2762
|
+
|
|
2763
|
+
// ../../node_modules/color-convert/index.js
|
|
2764
|
+
var require_color_convert = __commonJS((exports, module) => {
|
|
2765
|
+
var conversions = require_conversions();
|
|
2766
|
+
var route = require_route();
|
|
2767
|
+
var convert = {};
|
|
2768
|
+
var models = Object.keys(conversions);
|
|
2769
|
+
function wrapRaw(fn) {
|
|
2770
|
+
const wrappedFn = function(...args) {
|
|
2771
|
+
const arg0 = args[0];
|
|
2772
|
+
if (arg0 === undefined || arg0 === null) {
|
|
2773
|
+
return arg0;
|
|
2774
|
+
}
|
|
2775
|
+
if (arg0.length > 1) {
|
|
2776
|
+
args = arg0;
|
|
2777
|
+
}
|
|
2778
|
+
return fn(args);
|
|
2779
|
+
};
|
|
2780
|
+
if ("conversion" in fn) {
|
|
2781
|
+
wrappedFn.conversion = fn.conversion;
|
|
2782
|
+
}
|
|
2783
|
+
return wrappedFn;
|
|
2784
|
+
}
|
|
2785
|
+
function wrapRounded(fn) {
|
|
2786
|
+
const wrappedFn = function(...args) {
|
|
2787
|
+
const arg0 = args[0];
|
|
2788
|
+
if (arg0 === undefined || arg0 === null) {
|
|
2789
|
+
return arg0;
|
|
2790
|
+
}
|
|
2791
|
+
if (arg0.length > 1) {
|
|
2792
|
+
args = arg0;
|
|
2793
|
+
}
|
|
2794
|
+
const result = fn(args);
|
|
2795
|
+
if (typeof result === "object") {
|
|
2796
|
+
for (let len = result.length, i = 0;i < len; i++) {
|
|
2797
|
+
result[i] = Math.round(result[i]);
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
return result;
|
|
2801
|
+
};
|
|
2802
|
+
if ("conversion" in fn) {
|
|
2803
|
+
wrappedFn.conversion = fn.conversion;
|
|
2804
|
+
}
|
|
2805
|
+
return wrappedFn;
|
|
2806
|
+
}
|
|
2807
|
+
models.forEach((fromModel) => {
|
|
2808
|
+
convert[fromModel] = {};
|
|
2809
|
+
Object.defineProperty(convert[fromModel], "channels", { value: conversions[fromModel].channels });
|
|
2810
|
+
Object.defineProperty(convert[fromModel], "labels", { value: conversions[fromModel].labels });
|
|
2811
|
+
const routes = route(fromModel);
|
|
2812
|
+
const routeModels = Object.keys(routes);
|
|
2813
|
+
routeModels.forEach((toModel) => {
|
|
2814
|
+
const fn = routes[toModel];
|
|
2815
|
+
convert[fromModel][toModel] = wrapRounded(fn);
|
|
2816
|
+
convert[fromModel][toModel].raw = wrapRaw(fn);
|
|
2817
|
+
});
|
|
2818
|
+
});
|
|
2819
|
+
module.exports = convert;
|
|
2820
|
+
});
|
|
2821
|
+
|
|
2822
|
+
// ../../node_modules/ansi-styles/index.js
|
|
2823
|
+
var require_ansi_styles = __commonJS((exports, module) => {
|
|
2824
|
+
var wrapAnsi16 = (fn, offset) => (...args) => {
|
|
2825
|
+
const code = fn(...args);
|
|
2826
|
+
return `\x1B[${code + offset}m`;
|
|
2827
|
+
};
|
|
2828
|
+
var wrapAnsi256 = (fn, offset) => (...args) => {
|
|
2829
|
+
const code = fn(...args);
|
|
2830
|
+
return `\x1B[${38 + offset};5;${code}m`;
|
|
2831
|
+
};
|
|
2832
|
+
var wrapAnsi16m = (fn, offset) => (...args) => {
|
|
2833
|
+
const rgb = fn(...args);
|
|
2834
|
+
return `\x1B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
|
|
2835
|
+
};
|
|
2836
|
+
var ansi2ansi = (n) => n;
|
|
2837
|
+
var rgb2rgb = (r, g, b) => [r, g, b];
|
|
2838
|
+
var setLazyProperty = (object, property, get) => {
|
|
2839
|
+
Object.defineProperty(object, property, {
|
|
2840
|
+
get: () => {
|
|
2841
|
+
const value = get();
|
|
2842
|
+
Object.defineProperty(object, property, {
|
|
2843
|
+
value,
|
|
2844
|
+
enumerable: true,
|
|
2845
|
+
configurable: true
|
|
2846
|
+
});
|
|
2847
|
+
return value;
|
|
2848
|
+
},
|
|
2849
|
+
enumerable: true,
|
|
2850
|
+
configurable: true
|
|
2851
|
+
});
|
|
2852
|
+
};
|
|
2853
|
+
var colorConvert;
|
|
2854
|
+
var makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
|
|
2855
|
+
if (colorConvert === undefined) {
|
|
2856
|
+
colorConvert = require_color_convert();
|
|
2857
|
+
}
|
|
2858
|
+
const offset = isBackground ? 10 : 0;
|
|
2859
|
+
const styles = {};
|
|
2860
|
+
for (const [sourceSpace, suite] of Object.entries(colorConvert)) {
|
|
2861
|
+
const name = sourceSpace === "ansi16" ? "ansi" : sourceSpace;
|
|
2862
|
+
if (sourceSpace === targetSpace) {
|
|
2863
|
+
styles[name] = wrap(identity, offset);
|
|
2864
|
+
} else if (typeof suite === "object") {
|
|
2865
|
+
styles[name] = wrap(suite[targetSpace], offset);
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
return styles;
|
|
2869
|
+
};
|
|
2870
|
+
function assembleStyles() {
|
|
2871
|
+
const codes = new Map;
|
|
2872
|
+
const styles = {
|
|
2873
|
+
modifier: {
|
|
2874
|
+
reset: [0, 0],
|
|
2875
|
+
bold: [1, 22],
|
|
2876
|
+
dim: [2, 22],
|
|
2877
|
+
italic: [3, 23],
|
|
2878
|
+
underline: [4, 24],
|
|
2879
|
+
inverse: [7, 27],
|
|
2880
|
+
hidden: [8, 28],
|
|
2881
|
+
strikethrough: [9, 29]
|
|
2882
|
+
},
|
|
2883
|
+
color: {
|
|
2884
|
+
black: [30, 39],
|
|
2885
|
+
red: [31, 39],
|
|
2886
|
+
green: [32, 39],
|
|
2887
|
+
yellow: [33, 39],
|
|
2888
|
+
blue: [34, 39],
|
|
2889
|
+
magenta: [35, 39],
|
|
2890
|
+
cyan: [36, 39],
|
|
2891
|
+
white: [37, 39],
|
|
2892
|
+
blackBright: [90, 39],
|
|
2893
|
+
redBright: [91, 39],
|
|
2894
|
+
greenBright: [92, 39],
|
|
2895
|
+
yellowBright: [93, 39],
|
|
2896
|
+
blueBright: [94, 39],
|
|
2897
|
+
magentaBright: [95, 39],
|
|
2898
|
+
cyanBright: [96, 39],
|
|
2899
|
+
whiteBright: [97, 39]
|
|
2900
|
+
},
|
|
2901
|
+
bgColor: {
|
|
2902
|
+
bgBlack: [40, 49],
|
|
2903
|
+
bgRed: [41, 49],
|
|
2904
|
+
bgGreen: [42, 49],
|
|
2905
|
+
bgYellow: [43, 49],
|
|
2906
|
+
bgBlue: [44, 49],
|
|
2907
|
+
bgMagenta: [45, 49],
|
|
2908
|
+
bgCyan: [46, 49],
|
|
2909
|
+
bgWhite: [47, 49],
|
|
2910
|
+
bgBlackBright: [100, 49],
|
|
2911
|
+
bgRedBright: [101, 49],
|
|
2912
|
+
bgGreenBright: [102, 49],
|
|
2913
|
+
bgYellowBright: [103, 49],
|
|
2914
|
+
bgBlueBright: [104, 49],
|
|
2915
|
+
bgMagentaBright: [105, 49],
|
|
2916
|
+
bgCyanBright: [106, 49],
|
|
2917
|
+
bgWhiteBright: [107, 49]
|
|
2918
|
+
}
|
|
2919
|
+
};
|
|
2920
|
+
styles.color.gray = styles.color.blackBright;
|
|
2921
|
+
styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
|
|
2922
|
+
styles.color.grey = styles.color.blackBright;
|
|
2923
|
+
styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
|
|
2924
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
2925
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
2926
|
+
styles[styleName] = {
|
|
2927
|
+
open: `\x1B[${style[0]}m`,
|
|
2928
|
+
close: `\x1B[${style[1]}m`
|
|
2929
|
+
};
|
|
2930
|
+
group[styleName] = styles[styleName];
|
|
2931
|
+
codes.set(style[0], style[1]);
|
|
2932
|
+
}
|
|
2933
|
+
Object.defineProperty(styles, groupName, {
|
|
2934
|
+
value: group,
|
|
2935
|
+
enumerable: false
|
|
2936
|
+
});
|
|
2937
|
+
}
|
|
2938
|
+
Object.defineProperty(styles, "codes", {
|
|
2939
|
+
value: codes,
|
|
2940
|
+
enumerable: false
|
|
2941
|
+
});
|
|
2942
|
+
styles.color.close = "\x1B[39m";
|
|
2943
|
+
styles.bgColor.close = "\x1B[49m";
|
|
2944
|
+
setLazyProperty(styles.color, "ansi", () => makeDynamicStyles(wrapAnsi16, "ansi16", ansi2ansi, false));
|
|
2945
|
+
setLazyProperty(styles.color, "ansi256", () => makeDynamicStyles(wrapAnsi256, "ansi256", ansi2ansi, false));
|
|
2946
|
+
setLazyProperty(styles.color, "ansi16m", () => makeDynamicStyles(wrapAnsi16m, "rgb", rgb2rgb, false));
|
|
2947
|
+
setLazyProperty(styles.bgColor, "ansi", () => makeDynamicStyles(wrapAnsi16, "ansi16", ansi2ansi, true));
|
|
2948
|
+
setLazyProperty(styles.bgColor, "ansi256", () => makeDynamicStyles(wrapAnsi256, "ansi256", ansi2ansi, true));
|
|
2949
|
+
setLazyProperty(styles.bgColor, "ansi16m", () => makeDynamicStyles(wrapAnsi16m, "rgb", rgb2rgb, true));
|
|
2950
|
+
return styles;
|
|
2951
|
+
}
|
|
2952
|
+
Object.defineProperty(module, "exports", {
|
|
2953
|
+
enumerable: true,
|
|
2954
|
+
get: assembleStyles
|
|
2955
|
+
});
|
|
2956
|
+
});
|
|
2957
|
+
|
|
2958
|
+
// ../../node_modules/has-flag/index.js
|
|
2959
|
+
var require_has_flag = __commonJS((exports, module) => {
|
|
2960
|
+
module.exports = (flag, argv = process.argv) => {
|
|
2961
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
2962
|
+
const position = argv.indexOf(prefix + flag);
|
|
2963
|
+
const terminatorPosition = argv.indexOf("--");
|
|
2964
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
2965
|
+
};
|
|
2966
|
+
});
|
|
2967
|
+
|
|
2968
|
+
// ../../node_modules/supports-color/index.js
|
|
2969
|
+
var require_supports_color = __commonJS((exports, module) => {
|
|
2970
|
+
var os = __require("os");
|
|
2971
|
+
var tty = __require("tty");
|
|
2972
|
+
var hasFlag = require_has_flag();
|
|
2973
|
+
var { env } = process;
|
|
2974
|
+
var forceColor;
|
|
2975
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
2976
|
+
forceColor = 0;
|
|
2977
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
2978
|
+
forceColor = 1;
|
|
2979
|
+
}
|
|
2980
|
+
if ("FORCE_COLOR" in env) {
|
|
2981
|
+
if (env.FORCE_COLOR === "true") {
|
|
2982
|
+
forceColor = 1;
|
|
2983
|
+
} else if (env.FORCE_COLOR === "false") {
|
|
2984
|
+
forceColor = 0;
|
|
2985
|
+
} else {
|
|
2986
|
+
forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
function translateLevel(level) {
|
|
2990
|
+
if (level === 0) {
|
|
2991
|
+
return false;
|
|
2992
|
+
}
|
|
2993
|
+
return {
|
|
2994
|
+
level,
|
|
2995
|
+
hasBasic: true,
|
|
2996
|
+
has256: level >= 2,
|
|
2997
|
+
has16m: level >= 3
|
|
2998
|
+
};
|
|
2999
|
+
}
|
|
3000
|
+
function supportsColor(haveStream, streamIsTTY) {
|
|
3001
|
+
if (forceColor === 0) {
|
|
3002
|
+
return 0;
|
|
3003
|
+
}
|
|
3004
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
3005
|
+
return 3;
|
|
3006
|
+
}
|
|
3007
|
+
if (hasFlag("color=256")) {
|
|
3008
|
+
return 2;
|
|
3009
|
+
}
|
|
3010
|
+
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
3011
|
+
return 0;
|
|
3012
|
+
}
|
|
3013
|
+
const min = forceColor || 0;
|
|
3014
|
+
if (env.TERM === "dumb") {
|
|
3015
|
+
return min;
|
|
3016
|
+
}
|
|
3017
|
+
if (process.platform === "win32") {
|
|
3018
|
+
const osRelease = os.release().split(".");
|
|
3019
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
3020
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
3021
|
+
}
|
|
3022
|
+
return 1;
|
|
3023
|
+
}
|
|
3024
|
+
if ("CI" in env) {
|
|
3025
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => (sign in env)) || env.CI_NAME === "codeship") {
|
|
3026
|
+
return 1;
|
|
3027
|
+
}
|
|
3028
|
+
return min;
|
|
3029
|
+
}
|
|
3030
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
3031
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
3032
|
+
}
|
|
3033
|
+
if (env.COLORTERM === "truecolor") {
|
|
3034
|
+
return 3;
|
|
3035
|
+
}
|
|
3036
|
+
if ("TERM_PROGRAM" in env) {
|
|
3037
|
+
const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
3038
|
+
switch (env.TERM_PROGRAM) {
|
|
3039
|
+
case "iTerm.app":
|
|
3040
|
+
return version >= 3 ? 3 : 2;
|
|
3041
|
+
case "Apple_Terminal":
|
|
3042
|
+
return 2;
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
3046
|
+
return 2;
|
|
3047
|
+
}
|
|
3048
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
3049
|
+
return 1;
|
|
3050
|
+
}
|
|
3051
|
+
if ("COLORTERM" in env) {
|
|
3052
|
+
return 1;
|
|
3053
|
+
}
|
|
3054
|
+
return min;
|
|
3055
|
+
}
|
|
3056
|
+
function getSupportLevel(stream) {
|
|
3057
|
+
const level = supportsColor(stream, stream && stream.isTTY);
|
|
3058
|
+
return translateLevel(level);
|
|
3059
|
+
}
|
|
3060
|
+
module.exports = {
|
|
3061
|
+
supportsColor: getSupportLevel,
|
|
3062
|
+
stdout: translateLevel(supportsColor(true, tty.isatty(1))),
|
|
3063
|
+
stderr: translateLevel(supportsColor(true, tty.isatty(2)))
|
|
3064
|
+
};
|
|
3065
|
+
});
|
|
3066
|
+
|
|
3067
|
+
// ../../node_modules/chalk/source/util.js
|
|
3068
|
+
var require_util = __commonJS((exports, module) => {
|
|
3069
|
+
var stringReplaceAll = (string, substring, replacer) => {
|
|
3070
|
+
let index = string.indexOf(substring);
|
|
3071
|
+
if (index === -1) {
|
|
3072
|
+
return string;
|
|
3073
|
+
}
|
|
3074
|
+
const substringLength = substring.length;
|
|
3075
|
+
let endIndex = 0;
|
|
3076
|
+
let returnValue = "";
|
|
3077
|
+
do {
|
|
3078
|
+
returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
|
|
3079
|
+
endIndex = index + substringLength;
|
|
3080
|
+
index = string.indexOf(substring, endIndex);
|
|
3081
|
+
} while (index !== -1);
|
|
3082
|
+
returnValue += string.substr(endIndex);
|
|
3083
|
+
return returnValue;
|
|
3084
|
+
};
|
|
3085
|
+
var stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
|
|
3086
|
+
let endIndex = 0;
|
|
3087
|
+
let returnValue = "";
|
|
3088
|
+
do {
|
|
3089
|
+
const gotCR = string[index - 1] === "\r";
|
|
3090
|
+
returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? `\r
|
|
3091
|
+
` : `
|
|
3092
|
+
`) + postfix;
|
|
3093
|
+
endIndex = index + 1;
|
|
3094
|
+
index = string.indexOf(`
|
|
3095
|
+
`, endIndex);
|
|
3096
|
+
} while (index !== -1);
|
|
3097
|
+
returnValue += string.substr(endIndex);
|
|
3098
|
+
return returnValue;
|
|
3099
|
+
};
|
|
3100
|
+
module.exports = {
|
|
3101
|
+
stringReplaceAll,
|
|
3102
|
+
stringEncaseCRLFWithFirstIndex
|
|
3103
|
+
};
|
|
3104
|
+
});
|
|
3105
|
+
|
|
3106
|
+
// ../../node_modules/chalk/source/templates.js
|
|
3107
|
+
var require_templates = __commonJS((exports, module) => {
|
|
3108
|
+
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;
|
|
3109
|
+
var STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
|
|
3110
|
+
var STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
|
|
3111
|
+
var ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
|
|
3112
|
+
var ESCAPES = new Map([
|
|
3113
|
+
["n", `
|
|
3114
|
+
`],
|
|
3115
|
+
["r", "\r"],
|
|
3116
|
+
["t", "\t"],
|
|
3117
|
+
["b", "\b"],
|
|
3118
|
+
["f", "\f"],
|
|
3119
|
+
["v", "\v"],
|
|
3120
|
+
["0", "\x00"],
|
|
3121
|
+
["\\", "\\"],
|
|
3122
|
+
["e", "\x1B"],
|
|
3123
|
+
["a", "\x07"]
|
|
3124
|
+
]);
|
|
3125
|
+
function unescape(c) {
|
|
3126
|
+
const u = c[0] === "u";
|
|
3127
|
+
const bracket = c[1] === "{";
|
|
3128
|
+
if (u && !bracket && c.length === 5 || c[0] === "x" && c.length === 3) {
|
|
3129
|
+
return String.fromCharCode(parseInt(c.slice(1), 16));
|
|
3130
|
+
}
|
|
3131
|
+
if (u && bracket) {
|
|
3132
|
+
return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
|
|
3133
|
+
}
|
|
3134
|
+
return ESCAPES.get(c) || c;
|
|
3135
|
+
}
|
|
3136
|
+
function parseArguments(name, arguments_) {
|
|
3137
|
+
const results = [];
|
|
3138
|
+
const chunks = arguments_.trim().split(/\s*,\s*/g);
|
|
3139
|
+
let matches;
|
|
3140
|
+
for (const chunk of chunks) {
|
|
3141
|
+
const number = Number(chunk);
|
|
3142
|
+
if (!Number.isNaN(number)) {
|
|
3143
|
+
results.push(number);
|
|
3144
|
+
} else if (matches = chunk.match(STRING_REGEX)) {
|
|
3145
|
+
results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, character) => escape ? unescape(escape) : character));
|
|
3146
|
+
} else {
|
|
3147
|
+
throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
return results;
|
|
3151
|
+
}
|
|
3152
|
+
function parseStyle(style) {
|
|
3153
|
+
STYLE_REGEX.lastIndex = 0;
|
|
3154
|
+
const results = [];
|
|
3155
|
+
let matches;
|
|
3156
|
+
while ((matches = STYLE_REGEX.exec(style)) !== null) {
|
|
3157
|
+
const name = matches[1];
|
|
3158
|
+
if (matches[2]) {
|
|
3159
|
+
const args = parseArguments(name, matches[2]);
|
|
3160
|
+
results.push([name].concat(args));
|
|
3161
|
+
} else {
|
|
3162
|
+
results.push([name]);
|
|
3163
|
+
}
|
|
3164
|
+
}
|
|
3165
|
+
return results;
|
|
3166
|
+
}
|
|
3167
|
+
function buildStyle(chalk, styles) {
|
|
3168
|
+
const enabled = {};
|
|
3169
|
+
for (const layer of styles) {
|
|
3170
|
+
for (const style of layer.styles) {
|
|
3171
|
+
enabled[style[0]] = layer.inverse ? null : style.slice(1);
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
let current = chalk;
|
|
3175
|
+
for (const [styleName, styles2] of Object.entries(enabled)) {
|
|
3176
|
+
if (!Array.isArray(styles2)) {
|
|
3177
|
+
continue;
|
|
3178
|
+
}
|
|
3179
|
+
if (!(styleName in current)) {
|
|
3180
|
+
throw new Error(`Unknown Chalk style: ${styleName}`);
|
|
3181
|
+
}
|
|
3182
|
+
current = styles2.length > 0 ? current[styleName](...styles2) : current[styleName];
|
|
3183
|
+
}
|
|
3184
|
+
return current;
|
|
3185
|
+
}
|
|
3186
|
+
module.exports = (chalk, temporary) => {
|
|
3187
|
+
const styles = [];
|
|
3188
|
+
const chunks = [];
|
|
3189
|
+
let chunk = [];
|
|
3190
|
+
temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
|
|
3191
|
+
if (escapeCharacter) {
|
|
3192
|
+
chunk.push(unescape(escapeCharacter));
|
|
3193
|
+
} else if (style) {
|
|
3194
|
+
const string = chunk.join("");
|
|
3195
|
+
chunk = [];
|
|
3196
|
+
chunks.push(styles.length === 0 ? string : buildStyle(chalk, styles)(string));
|
|
3197
|
+
styles.push({ inverse, styles: parseStyle(style) });
|
|
3198
|
+
} else if (close) {
|
|
3199
|
+
if (styles.length === 0) {
|
|
3200
|
+
throw new Error("Found extraneous } in Chalk template literal");
|
|
3201
|
+
}
|
|
3202
|
+
chunks.push(buildStyle(chalk, styles)(chunk.join("")));
|
|
3203
|
+
chunk = [];
|
|
3204
|
+
styles.pop();
|
|
3205
|
+
} else {
|
|
3206
|
+
chunk.push(character);
|
|
3207
|
+
}
|
|
3208
|
+
});
|
|
3209
|
+
chunks.push(chunk.join(""));
|
|
3210
|
+
if (styles.length > 0) {
|
|
3211
|
+
const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`;
|
|
3212
|
+
throw new Error(errMessage);
|
|
3213
|
+
}
|
|
3214
|
+
return chunks.join("");
|
|
3215
|
+
};
|
|
3216
|
+
});
|
|
3217
|
+
|
|
3218
|
+
// ../../node_modules/chalk/source/index.js
|
|
3219
|
+
var require_source = __commonJS((exports, module) => {
|
|
3220
|
+
var ansiStyles = require_ansi_styles();
|
|
3221
|
+
var { stdout: stdoutColor, stderr: stderrColor } = require_supports_color();
|
|
3222
|
+
var {
|
|
3223
|
+
stringReplaceAll,
|
|
3224
|
+
stringEncaseCRLFWithFirstIndex
|
|
3225
|
+
} = require_util();
|
|
3226
|
+
var { isArray } = Array;
|
|
3227
|
+
var levelMapping = [
|
|
3228
|
+
"ansi",
|
|
3229
|
+
"ansi",
|
|
3230
|
+
"ansi256",
|
|
3231
|
+
"ansi16m"
|
|
3232
|
+
];
|
|
3233
|
+
var styles = Object.create(null);
|
|
3234
|
+
var applyOptions = (object, options = {}) => {
|
|
3235
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
3236
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
3237
|
+
}
|
|
3238
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
3239
|
+
object.level = options.level === undefined ? colorLevel : options.level;
|
|
3240
|
+
};
|
|
3241
|
+
|
|
3242
|
+
class ChalkClass {
|
|
3243
|
+
constructor(options) {
|
|
3244
|
+
return chalkFactory(options);
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
var chalkFactory = (options) => {
|
|
3248
|
+
const chalk2 = {};
|
|
3249
|
+
applyOptions(chalk2, options);
|
|
3250
|
+
chalk2.template = (...arguments_) => chalkTag(chalk2.template, ...arguments_);
|
|
3251
|
+
Object.setPrototypeOf(chalk2, Chalk.prototype);
|
|
3252
|
+
Object.setPrototypeOf(chalk2.template, chalk2);
|
|
3253
|
+
chalk2.template.constructor = () => {
|
|
3254
|
+
throw new Error("`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.");
|
|
3255
|
+
};
|
|
3256
|
+
chalk2.template.Instance = ChalkClass;
|
|
3257
|
+
return chalk2.template;
|
|
3258
|
+
};
|
|
3259
|
+
function Chalk(options) {
|
|
3260
|
+
return chalkFactory(options);
|
|
3261
|
+
}
|
|
3262
|
+
for (const [styleName, style] of Object.entries(ansiStyles)) {
|
|
3263
|
+
styles[styleName] = {
|
|
3264
|
+
get() {
|
|
3265
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
|
|
3266
|
+
Object.defineProperty(this, styleName, { value: builder });
|
|
3267
|
+
return builder;
|
|
3268
|
+
}
|
|
3269
|
+
};
|
|
3270
|
+
}
|
|
3271
|
+
styles.visible = {
|
|
3272
|
+
get() {
|
|
3273
|
+
const builder = createBuilder(this, this._styler, true);
|
|
3274
|
+
Object.defineProperty(this, "visible", { value: builder });
|
|
3275
|
+
return builder;
|
|
3276
|
+
}
|
|
3277
|
+
};
|
|
3278
|
+
var usedModels = ["rgb", "hex", "keyword", "hsl", "hsv", "hwb", "ansi", "ansi256"];
|
|
3279
|
+
for (const model of usedModels) {
|
|
3280
|
+
styles[model] = {
|
|
3281
|
+
get() {
|
|
3282
|
+
const { level } = this;
|
|
3283
|
+
return function(...arguments_) {
|
|
3284
|
+
const styler = createStyler(ansiStyles.color[levelMapping[level]][model](...arguments_), ansiStyles.color.close, this._styler);
|
|
3285
|
+
return createBuilder(this, styler, this._isEmpty);
|
|
3286
|
+
};
|
|
3287
|
+
}
|
|
3288
|
+
};
|
|
3289
|
+
}
|
|
3290
|
+
for (const model of usedModels) {
|
|
3291
|
+
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
3292
|
+
styles[bgModel] = {
|
|
3293
|
+
get() {
|
|
3294
|
+
const { level } = this;
|
|
3295
|
+
return function(...arguments_) {
|
|
3296
|
+
const styler = createStyler(ansiStyles.bgColor[levelMapping[level]][model](...arguments_), ansiStyles.bgColor.close, this._styler);
|
|
3297
|
+
return createBuilder(this, styler, this._isEmpty);
|
|
3298
|
+
};
|
|
3299
|
+
}
|
|
3300
|
+
};
|
|
3301
|
+
}
|
|
3302
|
+
var proto = Object.defineProperties(() => {}, {
|
|
3303
|
+
...styles,
|
|
3304
|
+
level: {
|
|
3305
|
+
enumerable: true,
|
|
3306
|
+
get() {
|
|
3307
|
+
return this._generator.level;
|
|
3308
|
+
},
|
|
3309
|
+
set(level) {
|
|
3310
|
+
this._generator.level = level;
|
|
3311
|
+
}
|
|
3312
|
+
}
|
|
3313
|
+
});
|
|
3314
|
+
var createStyler = (open, close, parent) => {
|
|
3315
|
+
let openAll;
|
|
3316
|
+
let closeAll;
|
|
3317
|
+
if (parent === undefined) {
|
|
3318
|
+
openAll = open;
|
|
3319
|
+
closeAll = close;
|
|
3320
|
+
} else {
|
|
3321
|
+
openAll = parent.openAll + open;
|
|
3322
|
+
closeAll = close + parent.closeAll;
|
|
3323
|
+
}
|
|
3324
|
+
return {
|
|
3325
|
+
open,
|
|
3326
|
+
close,
|
|
3327
|
+
openAll,
|
|
3328
|
+
closeAll,
|
|
3329
|
+
parent
|
|
3330
|
+
};
|
|
3331
|
+
};
|
|
3332
|
+
var createBuilder = (self, _styler, _isEmpty) => {
|
|
3333
|
+
const builder = (...arguments_) => {
|
|
3334
|
+
if (isArray(arguments_[0]) && isArray(arguments_[0].raw)) {
|
|
3335
|
+
return applyStyle(builder, chalkTag(builder, ...arguments_));
|
|
3336
|
+
}
|
|
3337
|
+
return applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
3338
|
+
};
|
|
3339
|
+
Object.setPrototypeOf(builder, proto);
|
|
3340
|
+
builder._generator = self;
|
|
3341
|
+
builder._styler = _styler;
|
|
3342
|
+
builder._isEmpty = _isEmpty;
|
|
3343
|
+
return builder;
|
|
3344
|
+
};
|
|
3345
|
+
var applyStyle = (self, string) => {
|
|
3346
|
+
if (self.level <= 0 || !string) {
|
|
3347
|
+
return self._isEmpty ? "" : string;
|
|
3348
|
+
}
|
|
3349
|
+
let styler = self._styler;
|
|
3350
|
+
if (styler === undefined) {
|
|
3351
|
+
return string;
|
|
3352
|
+
}
|
|
3353
|
+
const { openAll, closeAll } = styler;
|
|
3354
|
+
if (string.indexOf("\x1B") !== -1) {
|
|
3355
|
+
while (styler !== undefined) {
|
|
3356
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
3357
|
+
styler = styler.parent;
|
|
3358
|
+
}
|
|
3359
|
+
}
|
|
3360
|
+
const lfIndex = string.indexOf(`
|
|
3361
|
+
`);
|
|
3362
|
+
if (lfIndex !== -1) {
|
|
3363
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
3364
|
+
}
|
|
3365
|
+
return openAll + string + closeAll;
|
|
3366
|
+
};
|
|
3367
|
+
var template;
|
|
3368
|
+
var chalkTag = (chalk2, ...strings) => {
|
|
3369
|
+
const [firstString] = strings;
|
|
3370
|
+
if (!isArray(firstString) || !isArray(firstString.raw)) {
|
|
3371
|
+
return strings.join(" ");
|
|
3372
|
+
}
|
|
3373
|
+
const arguments_ = strings.slice(1);
|
|
3374
|
+
const parts = [firstString.raw[0]];
|
|
3375
|
+
for (let i = 1;i < firstString.length; i++) {
|
|
3376
|
+
parts.push(String(arguments_[i - 1]).replace(/[{}\\]/g, "\\$&"), String(firstString.raw[i]));
|
|
3377
|
+
}
|
|
3378
|
+
if (template === undefined) {
|
|
3379
|
+
template = require_templates();
|
|
3380
|
+
}
|
|
3381
|
+
return template(chalk2, parts.join(""));
|
|
3382
|
+
};
|
|
3383
|
+
Object.defineProperties(Chalk.prototype, styles);
|
|
3384
|
+
var chalk = Chalk();
|
|
3385
|
+
chalk.supportsColor = stdoutColor;
|
|
3386
|
+
chalk.stderr = Chalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
3387
|
+
chalk.stderr.supportsColor = stderrColor;
|
|
3388
|
+
module.exports = chalk;
|
|
3389
|
+
});
|
|
3390
|
+
|
|
3391
|
+
// src/crypto.ts
|
|
3392
|
+
import * as crypto from "crypto";
|
|
3393
|
+
function generateKeyPair() {
|
|
3394
|
+
const { publicKey, privateKey } = crypto.generateKeyPairSync("rsa", {
|
|
3395
|
+
modulusLength: 2048,
|
|
3396
|
+
publicKeyEncoding: {
|
|
3397
|
+
type: "spki",
|
|
3398
|
+
format: "pem"
|
|
3399
|
+
},
|
|
3400
|
+
privateKeyEncoding: {
|
|
3401
|
+
type: "pkcs8",
|
|
3402
|
+
format: "pem"
|
|
3403
|
+
}
|
|
3404
|
+
});
|
|
3405
|
+
return { publicKey, privateKey };
|
|
3406
|
+
}
|
|
3407
|
+
function signPayload(payload, privateKey) {
|
|
3408
|
+
const sign = crypto.createSign("SHA256");
|
|
3409
|
+
sign.update(payload);
|
|
3410
|
+
sign.end();
|
|
3411
|
+
return sign.sign(privateKey, "hex");
|
|
3412
|
+
}
|
|
3413
|
+
function verifyPayload(payload, signature, publicKey) {
|
|
3414
|
+
const verify = crypto.createVerify("SHA256");
|
|
3415
|
+
verify.update(payload);
|
|
3416
|
+
verify.end();
|
|
3417
|
+
return verify.verify(publicKey, signature, "hex");
|
|
3418
|
+
}
|
|
3419
|
+
function hashPassword(password, salt) {
|
|
3420
|
+
return crypto.createHmac("sha256", salt).update(password).digest("hex");
|
|
3421
|
+
}
|
|
3422
|
+
// src/stealth.ts
|
|
3423
|
+
var ZW0 = "";
|
|
3424
|
+
var ZW1 = "";
|
|
3425
|
+
var ZW2 = "";
|
|
3426
|
+
var ZW3 = "\uFEFF";
|
|
3427
|
+
var SEP = "";
|
|
3428
|
+
var ENCODE_LOOKUP = new Array(256);
|
|
3429
|
+
var DIGITS = [ZW0, ZW1, ZW2, ZW3];
|
|
3430
|
+
for (let i = 0;i < 256; i++) {
|
|
3431
|
+
let res = "";
|
|
3432
|
+
if (i === 0) {
|
|
3433
|
+
res = ZW0;
|
|
3434
|
+
} else {
|
|
3435
|
+
let c = i;
|
|
3436
|
+
while (c > 0) {
|
|
3437
|
+
res = DIGITS[c & 3] + res;
|
|
3438
|
+
c >>= 2;
|
|
3439
|
+
}
|
|
3440
|
+
}
|
|
3441
|
+
ENCODE_LOOKUP[i] = res;
|
|
3442
|
+
}
|
|
3443
|
+
var DECODE_LOOKUP = {
|
|
3444
|
+
[ZW0]: 0,
|
|
3445
|
+
[ZW1]: 1,
|
|
3446
|
+
[ZW2]: 2,
|
|
3447
|
+
[ZW3]: 3
|
|
3448
|
+
};
|
|
3449
|
+
function encodeStealth(data, version = "v2.3") {
|
|
3450
|
+
const salt = Math.random().toString(36).slice(2, 8);
|
|
3451
|
+
const payload = version + "|" + salt + "|" + data;
|
|
3452
|
+
let result = "";
|
|
3453
|
+
for (let i = 0;i < payload.length; i++) {
|
|
3454
|
+
const code = payload.charCodeAt(i);
|
|
3455
|
+
if (code < 256) {
|
|
3456
|
+
result += ENCODE_LOOKUP[code];
|
|
3457
|
+
} else {
|
|
3458
|
+
let temp = "";
|
|
3459
|
+
let c = code;
|
|
3460
|
+
while (c > 0) {
|
|
3461
|
+
temp = DIGITS[c & 3] + temp;
|
|
3462
|
+
c >>= 2;
|
|
3463
|
+
}
|
|
3464
|
+
result += temp;
|
|
3465
|
+
}
|
|
3466
|
+
if (i < payload.length - 1) {
|
|
3467
|
+
result += SEP;
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3470
|
+
return result;
|
|
3471
|
+
}
|
|
3472
|
+
function decodeStealth(stealth) {
|
|
3473
|
+
let result = "";
|
|
3474
|
+
let currentCode = 0;
|
|
3475
|
+
let hasData = false;
|
|
3476
|
+
for (let i = 0;i < stealth.length; i++) {
|
|
3477
|
+
const char = stealth[i];
|
|
3478
|
+
if (char === SEP) {
|
|
3479
|
+
if (hasData) {
|
|
3480
|
+
result += String.fromCharCode(currentCode);
|
|
3481
|
+
currentCode = 0;
|
|
3482
|
+
hasData = false;
|
|
3483
|
+
}
|
|
3484
|
+
continue;
|
|
3485
|
+
}
|
|
3486
|
+
const digit = DECODE_LOOKUP[char];
|
|
3487
|
+
if (digit !== undefined) {
|
|
3488
|
+
currentCode = currentCode << 2 | digit;
|
|
3489
|
+
hasData = true;
|
|
3490
|
+
}
|
|
3491
|
+
}
|
|
3492
|
+
if (hasData) {
|
|
3493
|
+
result += String.fromCharCode(currentCode);
|
|
3494
|
+
}
|
|
3495
|
+
const parts = result.split("|");
|
|
3496
|
+
return parts.length === 3 ? parts[2] : result;
|
|
3497
|
+
}
|
|
3498
|
+
function encryptString(str) {
|
|
3499
|
+
const key = Math.floor(Math.random() * 255);
|
|
3500
|
+
const encrypted = [];
|
|
3501
|
+
for (let i = 0;i < str.length; i++) {
|
|
3502
|
+
encrypted.push(str.charCodeAt(i) ^ key);
|
|
3503
|
+
}
|
|
3504
|
+
const decFuncs = [
|
|
3505
|
+
`(function(a,k){return a.map(function(c){return String.fromCharCode(c^k)}).join('')})`,
|
|
3506
|
+
`(function(x,y){var s='';for(var i=0;i<x.length;i++){s+=String.fromCharCode(x[i]^y)}return s})`
|
|
3507
|
+
];
|
|
3508
|
+
const chosen = decFuncs[Math.floor(Math.random() * decFuncs.length)];
|
|
3509
|
+
return `(${chosen}([${encrypted.join(",")}],${key}))`;
|
|
3510
|
+
}
|
|
3511
|
+
function getOpaquePredicateJS() {
|
|
3512
|
+
const a = Math.floor(Math.random() * 50) + 1;
|
|
3513
|
+
const b = Math.floor(Math.random() * 50) + 1;
|
|
3514
|
+
const variants = [
|
|
3515
|
+
`((Math.pow(${a}, 2) - Math.pow(${b}, 2)) === ((${a} - ${b}) * (${a} + ${b})))`,
|
|
3516
|
+
`(((${a} << 1) ^ (${a} >> 1)) !== ((${b} << 1) ^ (${b} >> 1)) || ${a} === ${a})`,
|
|
3517
|
+
`(function(n){var f=function(x){return x<2?1:f(x-1)+f(x-2)};return f(5) === 8})(${a})`
|
|
3518
|
+
];
|
|
3519
|
+
return variants[Math.floor(Math.random() * variants.length)];
|
|
3520
|
+
}
|
|
3521
|
+
// src/drivers/javascript.ts
|
|
3522
|
+
function injectJS(content, watermark) {
|
|
3523
|
+
const stealthTag = encodeStealth(watermark);
|
|
3524
|
+
const predicate = getOpaquePredicateJS();
|
|
3525
|
+
const guardName = "v" + Math.random().toString(36).slice(2, 7);
|
|
3526
|
+
const guard = `
|
|
3527
|
+
/**
|
|
3528
|
+
* Protected by Abelion (Public)
|
|
3529
|
+
* Identity: ${watermark}
|
|
3530
|
+
*/
|
|
3531
|
+
(function(${guardName}){
|
|
3532
|
+
// Integrity check
|
|
3533
|
+
if(!${predicate}) {
|
|
3534
|
+
console.warn("Abelion: Code integrity check failed.");
|
|
3535
|
+
return;
|
|
3536
|
+
}
|
|
3537
|
+
|
|
3538
|
+
${content}
|
|
3539
|
+
})(function ${guardName}(){/*${stealthTag}*/});`;
|
|
3540
|
+
return guard;
|
|
3541
|
+
}
|
|
3542
|
+
// src/drivers/python.ts
|
|
3543
|
+
function injectPython(content, watermark) {
|
|
3544
|
+
const stealthTag = encodeStealth(watermark);
|
|
3545
|
+
const brand = "A" + "b" + "e" + "l" + "i" + "o" + "n";
|
|
3546
|
+
const guard = `
|
|
3547
|
+
# @license: ${brand} (Public) (c) 2026${stealthTag}
|
|
3548
|
+
# Identity: ${watermark}
|
|
3549
|
+
`;
|
|
3550
|
+
return guard + `
|
|
3551
|
+
` + content;
|
|
3552
|
+
}
|
|
3553
|
+
// src/drivers/html.ts
|
|
3554
|
+
function injectHTML(content, watermark) {
|
|
3555
|
+
const stealthTag = encodeStealth(watermark);
|
|
3556
|
+
const guard = `<!-- Abelion Identity (Public): ${watermark}${stealthTag} -->
|
|
3557
|
+
<meta name="generator" content="Abelion Framework v2.3-${watermark.slice(0, 8)}">`;
|
|
3558
|
+
if (content.includes("<head>")) {
|
|
3559
|
+
return content.replace("<head>", `<head>
|
|
3560
|
+
` + guard);
|
|
3561
|
+
}
|
|
3562
|
+
return guard + `
|
|
3563
|
+
` + content;
|
|
3564
|
+
}
|
|
3565
|
+
// src/drivers/css.ts
|
|
3566
|
+
function injectCSS(content, watermark) {
|
|
3567
|
+
const stealthTag = encodeStealth(watermark);
|
|
3568
|
+
const guard = `/* @license Abelion Integrity Guard v1.2 (c) 2026${stealthTag} */
|
|
3569
|
+
:root { --abelion-integrity: "${watermark.substring(0, 16)}"; }`;
|
|
3570
|
+
return guard + `
|
|
3571
|
+
` + content;
|
|
3572
|
+
}
|
|
3573
|
+
// src/drivers/php.ts
|
|
3574
|
+
function injectPHP(content, watermark) {
|
|
3575
|
+
const stealthTag = encodeStealth(watermark);
|
|
3576
|
+
const guard = `<?php
|
|
3577
|
+
/**
|
|
3578
|
+
* @license Abelion Integrity Guard v1.3 (c) 2026${stealthTag}
|
|
3579
|
+
* Owner: ${watermark}
|
|
3580
|
+
*/
|
|
3581
|
+
`;
|
|
3582
|
+
if (content.trim().startsWith("<?php")) {
|
|
3583
|
+
return content.replace("<?php", guard);
|
|
3584
|
+
}
|
|
3585
|
+
return guard + `
|
|
3586
|
+
` + content;
|
|
3587
|
+
}
|
|
3588
|
+
// src/drivers/cpp.ts
|
|
3589
|
+
function injectCPP(content, watermark) {
|
|
3590
|
+
const stealthTag = encodeStealth(watermark);
|
|
3591
|
+
const guard = `
|
|
3592
|
+
/* @license Abelion Integrity Guard v1.2 (c) 2026${stealthTag} */
|
|
3593
|
+
#ifndef ABELION_GUARD
|
|
3594
|
+
#define ABELION_GUARD "${watermark}"
|
|
3595
|
+
// Note: In C++, stealth is harder, but we embed it in a macro
|
|
3596
|
+
#endif
|
|
3597
|
+
`;
|
|
3598
|
+
return guard + `
|
|
3599
|
+
` + content;
|
|
3600
|
+
}
|
|
3601
|
+
// ../../node_modules/commander/esm.mjs
|
|
3602
|
+
var import__ = __toESM(require_commander(), 1);
|
|
3603
|
+
var {
|
|
3604
|
+
program,
|
|
3605
|
+
createCommand,
|
|
3606
|
+
createArgument,
|
|
3607
|
+
createOption,
|
|
3608
|
+
CommanderError,
|
|
3609
|
+
InvalidArgumentError,
|
|
3610
|
+
InvalidOptionArgumentError,
|
|
3611
|
+
Command,
|
|
3612
|
+
Argument,
|
|
3613
|
+
Option,
|
|
3614
|
+
Help
|
|
3615
|
+
} = import__.default;
|
|
3616
|
+
|
|
3617
|
+
// src/commands/tag.ts
|
|
3618
|
+
var import_chalk = __toESM(require_source(), 1);
|
|
3619
|
+
import * as fs2 from "fs";
|
|
3620
|
+
import * as path2 from "path";
|
|
3621
|
+
|
|
3622
|
+
// src/utils.ts
|
|
3623
|
+
import * as fs from "fs";
|
|
3624
|
+
import * as path from "path";
|
|
3625
|
+
var SUPPORTED_EXTENSIONS = new Set([
|
|
3626
|
+
".js",
|
|
3627
|
+
".ts",
|
|
3628
|
+
".jsx",
|
|
3629
|
+
".tsx",
|
|
3630
|
+
".py",
|
|
3631
|
+
".php",
|
|
3632
|
+
".cpp",
|
|
3633
|
+
".hpp",
|
|
3634
|
+
".c",
|
|
3635
|
+
".h",
|
|
3636
|
+
".html",
|
|
3637
|
+
".htm",
|
|
3638
|
+
".css"
|
|
3639
|
+
]);
|
|
3640
|
+
var EXCLUDED_PATTERNS = [".pem", ".log", ".json", ".md", ".yml", ".yaml", "node_modules", ".git"];
|
|
3641
|
+
function isValidWatermarkMessage(message) {
|
|
3642
|
+
if (!message || message.length > 128) {
|
|
3643
|
+
return false;
|
|
3644
|
+
}
|
|
3645
|
+
return !/[\x00-\x1F\x7F]/.test(message);
|
|
3646
|
+
}
|
|
3647
|
+
function getAllFiles(dir, fileList = []) {
|
|
3648
|
+
const files = fs.readdirSync(dir);
|
|
3649
|
+
files.forEach((file) => {
|
|
3650
|
+
if (EXCLUDED_PATTERNS.some((p) => file.includes(p)))
|
|
3651
|
+
return;
|
|
3652
|
+
const name = path.join(dir, file);
|
|
3653
|
+
if (fs.statSync(name).isDirectory()) {
|
|
3654
|
+
if (!file.startsWith(".")) {
|
|
3655
|
+
getAllFiles(name, fileList);
|
|
3656
|
+
}
|
|
3657
|
+
} else {
|
|
3658
|
+
if (SUPPORTED_EXTENSIONS.has(path.extname(name).toLowerCase())) {
|
|
3659
|
+
fileList.push(name);
|
|
3660
|
+
}
|
|
3661
|
+
}
|
|
3662
|
+
});
|
|
3663
|
+
return fileList;
|
|
3664
|
+
}
|
|
3665
|
+
|
|
3666
|
+
// src/commands/tag.ts
|
|
3667
|
+
async function tagAction(targetPath, options) {
|
|
3668
|
+
if (!fs2.existsSync(targetPath)) {
|
|
3669
|
+
console.error(import_chalk.default.red("Error: Path does not exist"));
|
|
3670
|
+
process.exitCode = 1;
|
|
3671
|
+
return;
|
|
3672
|
+
}
|
|
3673
|
+
if (!isValidWatermarkMessage(options.message)) {
|
|
3674
|
+
console.error(import_chalk.default.red("Error: Invalid ownership message. Use 1-128 printable chars without control characters."));
|
|
3675
|
+
process.exitCode = 1;
|
|
3676
|
+
return;
|
|
3677
|
+
}
|
|
3678
|
+
const watermark = options.message;
|
|
3679
|
+
const stats = fs2.statSync(targetPath);
|
|
3680
|
+
let filesToTag = [];
|
|
3681
|
+
if (stats.isFile()) {
|
|
3682
|
+
if (!SUPPORTED_EXTENSIONS.has(path2.extname(targetPath).toLowerCase())) {
|
|
3683
|
+
console.log(import_chalk.default.yellow("⚠ File extension is not supported for tagging."));
|
|
3684
|
+
return;
|
|
3685
|
+
}
|
|
3686
|
+
filesToTag = [targetPath];
|
|
3687
|
+
} else {
|
|
3688
|
+
filesToTag = getAllFiles(targetPath);
|
|
3689
|
+
}
|
|
3690
|
+
if (filesToTag.length === 0) {
|
|
3691
|
+
console.log(import_chalk.default.yellow("⚠ No supported files found to tag."));
|
|
3692
|
+
return;
|
|
3693
|
+
}
|
|
3694
|
+
if (options.dryRun) {
|
|
3695
|
+
console.log(import_chalk.default.yellow("--- DRY RUN MODE ---"));
|
|
3696
|
+
filesToTag.forEach((f) => console.log(import_chalk.default.yellow(`[DRY-RUN] Would tag: ${f}`)));
|
|
3697
|
+
console.log(import_chalk.default.yellow(`Total files: ${filesToTag.length}`));
|
|
3698
|
+
return;
|
|
3699
|
+
}
|
|
3700
|
+
console.log(import_chalk.default.blue(`\uD83C\uDFF7️ Tagging project: ${path2.resolve(targetPath)}`));
|
|
3701
|
+
console.log(import_chalk.default.gray(`Processing ${filesToTag.length} files...`));
|
|
3702
|
+
const startTime = performance.now();
|
|
3703
|
+
let successCount = 0;
|
|
3704
|
+
filesToTag.forEach((f, index) => {
|
|
3705
|
+
try {
|
|
3706
|
+
const ext = path2.extname(f).toLowerCase();
|
|
3707
|
+
let content = fs2.readFileSync(f, "utf8");
|
|
3708
|
+
process.stdout.write(import_chalk.default.gray(` [${index + 1}/${filesToTag.length}] Tagging ${path2.basename(f)}...\r`));
|
|
3709
|
+
if ([".js", ".ts", ".jsx", ".tsx"].includes(ext)) {
|
|
3710
|
+
content = injectJS(content, watermark);
|
|
3711
|
+
} else if (ext === ".py") {
|
|
3712
|
+
content = injectPython(content, watermark);
|
|
3713
|
+
} else if (ext === ".php") {
|
|
3714
|
+
content = injectPHP(content, watermark);
|
|
3715
|
+
} else if ([".cpp", ".hpp", ".c", ".h"].includes(ext)) {
|
|
3716
|
+
content = injectCPP(content, watermark);
|
|
3717
|
+
} else if ([".html", ".htm"].includes(ext)) {
|
|
3718
|
+
content = injectHTML(content, watermark);
|
|
3719
|
+
} else if (ext === ".css") {
|
|
3720
|
+
content = injectCSS(content, watermark);
|
|
3721
|
+
}
|
|
3722
|
+
fs2.writeFileSync(f, content);
|
|
3723
|
+
successCount += 1;
|
|
3724
|
+
} catch (error) {
|
|
3725
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3726
|
+
console.error(`
|
|
3727
|
+
` + import_chalk.default.red(`❌ Failed to tag ${f}: ${message}`));
|
|
3728
|
+
}
|
|
3729
|
+
});
|
|
3730
|
+
const duration = ((performance.now() - startTime) / 1000).toFixed(2);
|
|
3731
|
+
console.log(`
|
|
3732
|
+
` + import_chalk.default.green(`✔ Tagging complete in ${duration}s. ${successCount}/${filesToTag.length} files watermarked.`));
|
|
3733
|
+
}
|
|
3734
|
+
|
|
3735
|
+
// src/commands/verify.ts
|
|
3736
|
+
var import_chalk2 = __toESM(require_source(), 1);
|
|
3737
|
+
import * as fs3 from "fs";
|
|
3738
|
+
function verifyAction(file) {
|
|
3739
|
+
if (!fs3.existsSync(file)) {
|
|
3740
|
+
console.error(import_chalk2.default.red("Error: File does not exist"));
|
|
3741
|
+
process.exitCode = 1;
|
|
3742
|
+
return;
|
|
3743
|
+
}
|
|
3744
|
+
const startTime = performance.now();
|
|
3745
|
+
try {
|
|
3746
|
+
const content = fs3.readFileSync(file, "utf8");
|
|
3747
|
+
const stealthMatch = content.match(/[\u200B-\u200D\uFEFF\u200E]{10,}/);
|
|
3748
|
+
if (!stealthMatch) {
|
|
3749
|
+
console.log(import_chalk2.default.yellow('⚠ No watermark found. Hint: run `abelion-tagger tag <path> -m "owner"` first.'));
|
|
3750
|
+
return;
|
|
3751
|
+
}
|
|
3752
|
+
const watermark = decodeStealth(stealthMatch[0]);
|
|
3753
|
+
const duration = ((performance.now() - startTime) / 1000).toFixed(2);
|
|
3754
|
+
console.log(import_chalk2.default.cyan(`✔ Ownership verified in ${duration}s: ${watermark}`));
|
|
3755
|
+
} catch (error) {
|
|
3756
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3757
|
+
console.error(import_chalk2.default.red(`Error: Failed to verify file: ${message}`));
|
|
3758
|
+
process.exitCode = 1;
|
|
3759
|
+
}
|
|
3760
|
+
}
|
|
3761
|
+
|
|
3762
|
+
// src/commands/keygen.ts
|
|
3763
|
+
var import_chalk3 = __toESM(require_source(), 1);
|
|
3764
|
+
import * as fs4 from "fs";
|
|
3765
|
+
function keygenAction() {
|
|
3766
|
+
const { publicKey, privateKey } = generateKeyPair();
|
|
3767
|
+
fs4.writeFileSync("abelion_public.pem", publicKey);
|
|
3768
|
+
fs4.writeFileSync("abelion_private.pem", privateKey, { mode: 384 });
|
|
3769
|
+
console.log(import_chalk3.default.green("✔ Keys generated: abelion_public.pem, abelion_private.pem"));
|
|
3770
|
+
}
|
|
3771
|
+
|
|
3772
|
+
// src/cli.ts
|
|
3773
|
+
var program2 = new Command;
|
|
3774
|
+
program2.name("abelion-tagger-public").description("CLI for public code watermarking and ownership verification").version("1.1.0");
|
|
3775
|
+
program2.command("keygen").description("Generate RSA key pair for signing/verification").action(keygenAction);
|
|
3776
|
+
program2.command("tag").description("Tag a directory or file with ownership watermark").argument("<path>", "Target path").option("-m, --message <string>", "Ownership message", "abelion_owner").option("--dry-run", "Preview files that will be tagged without modifying them").action(tagAction);
|
|
3777
|
+
program2.command("verify").description("Verify ownership of a file").argument("<file>", "File path").action(verifyAction);
|
|
3778
|
+
program2.parse();
|