ops-toolkit 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.commitlintrc.js +25 -0
- package/.env.example +25 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/.opencode/README.md +320 -0
- package/.opencode/command/add-cmd.md +38 -0
- package/.opencode/command/add-pkg.md +28 -0
- package/.opencode/command/build.md +27 -0
- package/.opencode/command/debug.md +36 -0
- package/.opencode/command/fix.md +23 -0
- package/.opencode/command/release.md +28 -0
- package/.opencode/command/review.md +36 -0
- package/.opencode/command/test.md +25 -0
- package/.prettierrc +16 -0
- package/.release-it.json +29 -0
- package/.versionrc.js +18 -0
- package/.vscode/extensions.json +14 -0
- package/.vscode/launch.json +33 -0
- package/.vscode/typescript.code-snippets +61 -0
- package/AGENTS.md +277 -0
- package/CHANGELOG.md +24 -0
- package/QUICKSTART.md +136 -0
- package/README.md +143 -0
- package/bin/ops-toolkit.ts +92 -0
- package/bun.lock +1921 -0
- package/dist/index.js +3726 -0
- package/docs/DEBUGGING.md +255 -0
- package/docs/DEVELOPMENT_GUIDE.md +538 -0
- package/eslint.config.js +64 -0
- package/package.json +90 -0
- package/src/commands/deploy/index.ts +97 -0
- package/src/commands/monitor/index.ts +60 -0
- package/src/commands/system/index.ts +120 -0
- package/src/index.ts +82 -0
- package/src/types/commands.ts +41 -0
- package/src/types/index.ts +3 -0
- package/src/types/system.ts +65 -0
- package/src/types/ui.ts +61 -0
- package/src/utils/config.ts +146 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/logger.ts +62 -0
- package/src/utils/system.ts +183 -0
- package/tsconfig.json +48 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3726 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
10
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
11
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
12
|
+
for (let key of __getOwnPropNames(mod))
|
|
13
|
+
if (!__hasOwnProp.call(to, key))
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: () => mod[key],
|
|
16
|
+
enumerable: true
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
21
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
22
|
+
|
|
23
|
+
// node_modules/commander/lib/error.js
|
|
24
|
+
var require_error = __commonJS((exports) => {
|
|
25
|
+
class CommanderError extends Error {
|
|
26
|
+
constructor(exitCode, code, message) {
|
|
27
|
+
super(message);
|
|
28
|
+
Error.captureStackTrace(this, this.constructor);
|
|
29
|
+
this.name = this.constructor.name;
|
|
30
|
+
this.code = code;
|
|
31
|
+
this.exitCode = exitCode;
|
|
32
|
+
this.nestedError = undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
class InvalidArgumentError extends CommanderError {
|
|
37
|
+
constructor(message) {
|
|
38
|
+
super(1, "commander.invalidArgument", message);
|
|
39
|
+
Error.captureStackTrace(this, this.constructor);
|
|
40
|
+
this.name = this.constructor.name;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.CommanderError = CommanderError;
|
|
44
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// node_modules/commander/lib/argument.js
|
|
48
|
+
var require_argument = __commonJS((exports) => {
|
|
49
|
+
var { InvalidArgumentError } = require_error();
|
|
50
|
+
|
|
51
|
+
class Argument {
|
|
52
|
+
constructor(name, description) {
|
|
53
|
+
this.description = description || "";
|
|
54
|
+
this.variadic = false;
|
|
55
|
+
this.parseArg = undefined;
|
|
56
|
+
this.defaultValue = undefined;
|
|
57
|
+
this.defaultValueDescription = undefined;
|
|
58
|
+
this.argChoices = undefined;
|
|
59
|
+
switch (name[0]) {
|
|
60
|
+
case "<":
|
|
61
|
+
this.required = true;
|
|
62
|
+
this._name = name.slice(1, -1);
|
|
63
|
+
break;
|
|
64
|
+
case "[":
|
|
65
|
+
this.required = false;
|
|
66
|
+
this._name = name.slice(1, -1);
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
this.required = true;
|
|
70
|
+
this._name = name;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
if (this._name.length > 3 && this._name.slice(-3) === "...") {
|
|
74
|
+
this.variadic = true;
|
|
75
|
+
this._name = this._name.slice(0, -3);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
name() {
|
|
79
|
+
return this._name;
|
|
80
|
+
}
|
|
81
|
+
_concatValue(value, previous) {
|
|
82
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
83
|
+
return [value];
|
|
84
|
+
}
|
|
85
|
+
return previous.concat(value);
|
|
86
|
+
}
|
|
87
|
+
default(value, description) {
|
|
88
|
+
this.defaultValue = value;
|
|
89
|
+
this.defaultValueDescription = description;
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
argParser(fn) {
|
|
93
|
+
this.parseArg = fn;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
choices(values) {
|
|
97
|
+
this.argChoices = values.slice();
|
|
98
|
+
this.parseArg = (arg, previous) => {
|
|
99
|
+
if (!this.argChoices.includes(arg)) {
|
|
100
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
101
|
+
}
|
|
102
|
+
if (this.variadic) {
|
|
103
|
+
return this._concatValue(arg, previous);
|
|
104
|
+
}
|
|
105
|
+
return arg;
|
|
106
|
+
};
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
argRequired() {
|
|
110
|
+
this.required = true;
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
argOptional() {
|
|
114
|
+
this.required = false;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function humanReadableArgName(arg) {
|
|
119
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
120
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
121
|
+
}
|
|
122
|
+
exports.Argument = Argument;
|
|
123
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// node_modules/commander/lib/help.js
|
|
127
|
+
var require_help = __commonJS((exports) => {
|
|
128
|
+
var { humanReadableArgName } = require_argument();
|
|
129
|
+
|
|
130
|
+
class Help {
|
|
131
|
+
constructor() {
|
|
132
|
+
this.helpWidth = undefined;
|
|
133
|
+
this.sortSubcommands = false;
|
|
134
|
+
this.sortOptions = false;
|
|
135
|
+
this.showGlobalOptions = false;
|
|
136
|
+
}
|
|
137
|
+
visibleCommands(cmd) {
|
|
138
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
139
|
+
if (cmd._hasImplicitHelpCommand()) {
|
|
140
|
+
const [, helpName, helpArgs] = cmd._helpCommandnameAndArgs.match(/([^ ]+) *(.*)/);
|
|
141
|
+
const helpCommand = cmd.createCommand(helpName).helpOption(false);
|
|
142
|
+
helpCommand.description(cmd._helpCommandDescription);
|
|
143
|
+
if (helpArgs)
|
|
144
|
+
helpCommand.arguments(helpArgs);
|
|
145
|
+
visibleCommands.push(helpCommand);
|
|
146
|
+
}
|
|
147
|
+
if (this.sortSubcommands) {
|
|
148
|
+
visibleCommands.sort((a, b) => {
|
|
149
|
+
return a.name().localeCompare(b.name());
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return visibleCommands;
|
|
153
|
+
}
|
|
154
|
+
compareOptions(a, b) {
|
|
155
|
+
const getSortKey = (option) => {
|
|
156
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
157
|
+
};
|
|
158
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
159
|
+
}
|
|
160
|
+
visibleOptions(cmd) {
|
|
161
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
162
|
+
const showShortHelpFlag = cmd._hasHelpOption && cmd._helpShortFlag && !cmd._findOption(cmd._helpShortFlag);
|
|
163
|
+
const showLongHelpFlag = cmd._hasHelpOption && !cmd._findOption(cmd._helpLongFlag);
|
|
164
|
+
if (showShortHelpFlag || showLongHelpFlag) {
|
|
165
|
+
let helpOption;
|
|
166
|
+
if (!showShortHelpFlag) {
|
|
167
|
+
helpOption = cmd.createOption(cmd._helpLongFlag, cmd._helpDescription);
|
|
168
|
+
} else if (!showLongHelpFlag) {
|
|
169
|
+
helpOption = cmd.createOption(cmd._helpShortFlag, cmd._helpDescription);
|
|
170
|
+
} else {
|
|
171
|
+
helpOption = cmd.createOption(cmd._helpFlags, cmd._helpDescription);
|
|
172
|
+
}
|
|
173
|
+
visibleOptions.push(helpOption);
|
|
174
|
+
}
|
|
175
|
+
if (this.sortOptions) {
|
|
176
|
+
visibleOptions.sort(this.compareOptions);
|
|
177
|
+
}
|
|
178
|
+
return visibleOptions;
|
|
179
|
+
}
|
|
180
|
+
visibleGlobalOptions(cmd) {
|
|
181
|
+
if (!this.showGlobalOptions)
|
|
182
|
+
return [];
|
|
183
|
+
const globalOptions = [];
|
|
184
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
185
|
+
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
|
|
186
|
+
globalOptions.push(...visibleOptions);
|
|
187
|
+
}
|
|
188
|
+
if (this.sortOptions) {
|
|
189
|
+
globalOptions.sort(this.compareOptions);
|
|
190
|
+
}
|
|
191
|
+
return globalOptions;
|
|
192
|
+
}
|
|
193
|
+
visibleArguments(cmd) {
|
|
194
|
+
if (cmd._argsDescription) {
|
|
195
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
196
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
200
|
+
return cmd.registeredArguments;
|
|
201
|
+
}
|
|
202
|
+
return [];
|
|
203
|
+
}
|
|
204
|
+
subcommandTerm(cmd) {
|
|
205
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
206
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
207
|
+
}
|
|
208
|
+
optionTerm(option) {
|
|
209
|
+
return option.flags;
|
|
210
|
+
}
|
|
211
|
+
argumentTerm(argument) {
|
|
212
|
+
return argument.name();
|
|
213
|
+
}
|
|
214
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
215
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
216
|
+
return Math.max(max, helper.subcommandTerm(command).length);
|
|
217
|
+
}, 0);
|
|
218
|
+
}
|
|
219
|
+
longestOptionTermLength(cmd, helper) {
|
|
220
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
221
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
222
|
+
}, 0);
|
|
223
|
+
}
|
|
224
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
225
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
226
|
+
return Math.max(max, helper.optionTerm(option).length);
|
|
227
|
+
}, 0);
|
|
228
|
+
}
|
|
229
|
+
longestArgumentTermLength(cmd, helper) {
|
|
230
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
231
|
+
return Math.max(max, helper.argumentTerm(argument).length);
|
|
232
|
+
}, 0);
|
|
233
|
+
}
|
|
234
|
+
commandUsage(cmd) {
|
|
235
|
+
let cmdName = cmd._name;
|
|
236
|
+
if (cmd._aliases[0]) {
|
|
237
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
238
|
+
}
|
|
239
|
+
let ancestorCmdNames = "";
|
|
240
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
241
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
242
|
+
}
|
|
243
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
244
|
+
}
|
|
245
|
+
commandDescription(cmd) {
|
|
246
|
+
return cmd.description();
|
|
247
|
+
}
|
|
248
|
+
subcommandDescription(cmd) {
|
|
249
|
+
return cmd.summary() || cmd.description();
|
|
250
|
+
}
|
|
251
|
+
optionDescription(option) {
|
|
252
|
+
const extraInfo = [];
|
|
253
|
+
if (option.argChoices) {
|
|
254
|
+
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
255
|
+
}
|
|
256
|
+
if (option.defaultValue !== undefined) {
|
|
257
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
258
|
+
if (showDefault) {
|
|
259
|
+
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (option.presetArg !== undefined && option.optional) {
|
|
263
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
264
|
+
}
|
|
265
|
+
if (option.envVar !== undefined) {
|
|
266
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
267
|
+
}
|
|
268
|
+
if (extraInfo.length > 0) {
|
|
269
|
+
return `${option.description} (${extraInfo.join(", ")})`;
|
|
270
|
+
}
|
|
271
|
+
return option.description;
|
|
272
|
+
}
|
|
273
|
+
argumentDescription(argument) {
|
|
274
|
+
const extraInfo = [];
|
|
275
|
+
if (argument.argChoices) {
|
|
276
|
+
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
277
|
+
}
|
|
278
|
+
if (argument.defaultValue !== undefined) {
|
|
279
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
280
|
+
}
|
|
281
|
+
if (extraInfo.length > 0) {
|
|
282
|
+
const extraDescripton = `(${extraInfo.join(", ")})`;
|
|
283
|
+
if (argument.description) {
|
|
284
|
+
return `${argument.description} ${extraDescripton}`;
|
|
285
|
+
}
|
|
286
|
+
return extraDescripton;
|
|
287
|
+
}
|
|
288
|
+
return argument.description;
|
|
289
|
+
}
|
|
290
|
+
formatHelp(cmd, helper) {
|
|
291
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
292
|
+
const helpWidth = helper.helpWidth || 80;
|
|
293
|
+
const itemIndentWidth = 2;
|
|
294
|
+
const itemSeparatorWidth = 2;
|
|
295
|
+
function formatItem(term, description) {
|
|
296
|
+
if (description) {
|
|
297
|
+
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
298
|
+
return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
|
|
299
|
+
}
|
|
300
|
+
return term;
|
|
301
|
+
}
|
|
302
|
+
function formatList(textArray) {
|
|
303
|
+
return textArray.join(`
|
|
304
|
+
`).replace(/^/gm, " ".repeat(itemIndentWidth));
|
|
305
|
+
}
|
|
306
|
+
let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
|
|
307
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
308
|
+
if (commandDescription.length > 0) {
|
|
309
|
+
output = output.concat([helper.wrap(commandDescription, helpWidth, 0), ""]);
|
|
310
|
+
}
|
|
311
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
312
|
+
return formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument));
|
|
313
|
+
});
|
|
314
|
+
if (argumentList.length > 0) {
|
|
315
|
+
output = output.concat(["Arguments:", formatList(argumentList), ""]);
|
|
316
|
+
}
|
|
317
|
+
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
318
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
319
|
+
});
|
|
320
|
+
if (optionList.length > 0) {
|
|
321
|
+
output = output.concat(["Options:", formatList(optionList), ""]);
|
|
322
|
+
}
|
|
323
|
+
if (this.showGlobalOptions) {
|
|
324
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
325
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
326
|
+
});
|
|
327
|
+
if (globalOptionList.length > 0) {
|
|
328
|
+
output = output.concat(["Global Options:", formatList(globalOptionList), ""]);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
332
|
+
return formatItem(helper.subcommandTerm(cmd2), helper.subcommandDescription(cmd2));
|
|
333
|
+
});
|
|
334
|
+
if (commandList.length > 0) {
|
|
335
|
+
output = output.concat(["Commands:", formatList(commandList), ""]);
|
|
336
|
+
}
|
|
337
|
+
return output.join(`
|
|
338
|
+
`);
|
|
339
|
+
}
|
|
340
|
+
padWidth(cmd, helper) {
|
|
341
|
+
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
342
|
+
}
|
|
343
|
+
wrap(str, width, indent, minColumnWidth = 40) {
|
|
344
|
+
const indents = " \\f\\t\\v - \uFEFF";
|
|
345
|
+
const manualIndent = new RegExp(`[\\n][${indents}]+`);
|
|
346
|
+
if (str.match(manualIndent))
|
|
347
|
+
return str;
|
|
348
|
+
const columnWidth = width - indent;
|
|
349
|
+
if (columnWidth < minColumnWidth)
|
|
350
|
+
return str;
|
|
351
|
+
const leadingStr = str.slice(0, indent);
|
|
352
|
+
const columnText = str.slice(indent).replace(`\r
|
|
353
|
+
`, `
|
|
354
|
+
`);
|
|
355
|
+
const indentString = " ".repeat(indent);
|
|
356
|
+
const zeroWidthSpace = "";
|
|
357
|
+
const breaks = `\\s${zeroWidthSpace}`;
|
|
358
|
+
const regex = new RegExp(`
|
|
359
|
+
|.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`, "g");
|
|
360
|
+
const lines = columnText.match(regex) || [];
|
|
361
|
+
return leadingStr + lines.map((line, i) => {
|
|
362
|
+
if (line === `
|
|
363
|
+
`)
|
|
364
|
+
return "";
|
|
365
|
+
return (i > 0 ? indentString : "") + line.trimEnd();
|
|
366
|
+
}).join(`
|
|
367
|
+
`);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
exports.Help = Help;
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
// node_modules/commander/lib/option.js
|
|
374
|
+
var require_option = __commonJS((exports) => {
|
|
375
|
+
var { InvalidArgumentError } = require_error();
|
|
376
|
+
|
|
377
|
+
class Option {
|
|
378
|
+
constructor(flags, description) {
|
|
379
|
+
this.flags = flags;
|
|
380
|
+
this.description = description || "";
|
|
381
|
+
this.required = flags.includes("<");
|
|
382
|
+
this.optional = flags.includes("[");
|
|
383
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
384
|
+
this.mandatory = false;
|
|
385
|
+
const optionFlags = splitOptionFlags(flags);
|
|
386
|
+
this.short = optionFlags.shortFlag;
|
|
387
|
+
this.long = optionFlags.longFlag;
|
|
388
|
+
this.negate = false;
|
|
389
|
+
if (this.long) {
|
|
390
|
+
this.negate = this.long.startsWith("--no-");
|
|
391
|
+
}
|
|
392
|
+
this.defaultValue = undefined;
|
|
393
|
+
this.defaultValueDescription = undefined;
|
|
394
|
+
this.presetArg = undefined;
|
|
395
|
+
this.envVar = undefined;
|
|
396
|
+
this.parseArg = undefined;
|
|
397
|
+
this.hidden = false;
|
|
398
|
+
this.argChoices = undefined;
|
|
399
|
+
this.conflictsWith = [];
|
|
400
|
+
this.implied = undefined;
|
|
401
|
+
}
|
|
402
|
+
default(value, description) {
|
|
403
|
+
this.defaultValue = value;
|
|
404
|
+
this.defaultValueDescription = description;
|
|
405
|
+
return this;
|
|
406
|
+
}
|
|
407
|
+
preset(arg) {
|
|
408
|
+
this.presetArg = arg;
|
|
409
|
+
return this;
|
|
410
|
+
}
|
|
411
|
+
conflicts(names) {
|
|
412
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
413
|
+
return this;
|
|
414
|
+
}
|
|
415
|
+
implies(impliedOptionValues) {
|
|
416
|
+
let newImplied = impliedOptionValues;
|
|
417
|
+
if (typeof impliedOptionValues === "string") {
|
|
418
|
+
newImplied = { [impliedOptionValues]: true };
|
|
419
|
+
}
|
|
420
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
421
|
+
return this;
|
|
422
|
+
}
|
|
423
|
+
env(name) {
|
|
424
|
+
this.envVar = name;
|
|
425
|
+
return this;
|
|
426
|
+
}
|
|
427
|
+
argParser(fn) {
|
|
428
|
+
this.parseArg = fn;
|
|
429
|
+
return this;
|
|
430
|
+
}
|
|
431
|
+
makeOptionMandatory(mandatory = true) {
|
|
432
|
+
this.mandatory = !!mandatory;
|
|
433
|
+
return this;
|
|
434
|
+
}
|
|
435
|
+
hideHelp(hide = true) {
|
|
436
|
+
this.hidden = !!hide;
|
|
437
|
+
return this;
|
|
438
|
+
}
|
|
439
|
+
_concatValue(value, previous) {
|
|
440
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
441
|
+
return [value];
|
|
442
|
+
}
|
|
443
|
+
return previous.concat(value);
|
|
444
|
+
}
|
|
445
|
+
choices(values) {
|
|
446
|
+
this.argChoices = values.slice();
|
|
447
|
+
this.parseArg = (arg, previous) => {
|
|
448
|
+
if (!this.argChoices.includes(arg)) {
|
|
449
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
450
|
+
}
|
|
451
|
+
if (this.variadic) {
|
|
452
|
+
return this._concatValue(arg, previous);
|
|
453
|
+
}
|
|
454
|
+
return arg;
|
|
455
|
+
};
|
|
456
|
+
return this;
|
|
457
|
+
}
|
|
458
|
+
name() {
|
|
459
|
+
if (this.long) {
|
|
460
|
+
return this.long.replace(/^--/, "");
|
|
461
|
+
}
|
|
462
|
+
return this.short.replace(/^-/, "");
|
|
463
|
+
}
|
|
464
|
+
attributeName() {
|
|
465
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
466
|
+
}
|
|
467
|
+
is(arg) {
|
|
468
|
+
return this.short === arg || this.long === arg;
|
|
469
|
+
}
|
|
470
|
+
isBoolean() {
|
|
471
|
+
return !this.required && !this.optional && !this.negate;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
class DualOptions {
|
|
476
|
+
constructor(options) {
|
|
477
|
+
this.positiveOptions = new Map;
|
|
478
|
+
this.negativeOptions = new Map;
|
|
479
|
+
this.dualOptions = new Set;
|
|
480
|
+
options.forEach((option) => {
|
|
481
|
+
if (option.negate) {
|
|
482
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
483
|
+
} else {
|
|
484
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
this.negativeOptions.forEach((value, key) => {
|
|
488
|
+
if (this.positiveOptions.has(key)) {
|
|
489
|
+
this.dualOptions.add(key);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
valueFromOption(value, option) {
|
|
494
|
+
const optionKey = option.attributeName();
|
|
495
|
+
if (!this.dualOptions.has(optionKey))
|
|
496
|
+
return true;
|
|
497
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
498
|
+
const negativeValue = preset !== undefined ? preset : false;
|
|
499
|
+
return option.negate === (negativeValue === value);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
function camelcase(str) {
|
|
503
|
+
return str.split("-").reduce((str2, word) => {
|
|
504
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
function splitOptionFlags(flags) {
|
|
508
|
+
let shortFlag;
|
|
509
|
+
let longFlag;
|
|
510
|
+
const flagParts = flags.split(/[ |,]+/);
|
|
511
|
+
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
512
|
+
shortFlag = flagParts.shift();
|
|
513
|
+
longFlag = flagParts.shift();
|
|
514
|
+
if (!shortFlag && /^-[^-]$/.test(longFlag)) {
|
|
515
|
+
shortFlag = longFlag;
|
|
516
|
+
longFlag = undefined;
|
|
517
|
+
}
|
|
518
|
+
return { shortFlag, longFlag };
|
|
519
|
+
}
|
|
520
|
+
exports.Option = Option;
|
|
521
|
+
exports.splitOptionFlags = splitOptionFlags;
|
|
522
|
+
exports.DualOptions = DualOptions;
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
// node_modules/commander/lib/suggestSimilar.js
|
|
526
|
+
var require_suggestSimilar = __commonJS((exports) => {
|
|
527
|
+
var maxDistance = 3;
|
|
528
|
+
function editDistance(a, b) {
|
|
529
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
530
|
+
return Math.max(a.length, b.length);
|
|
531
|
+
const d = [];
|
|
532
|
+
for (let i = 0;i <= a.length; i++) {
|
|
533
|
+
d[i] = [i];
|
|
534
|
+
}
|
|
535
|
+
for (let j = 0;j <= b.length; j++) {
|
|
536
|
+
d[0][j] = j;
|
|
537
|
+
}
|
|
538
|
+
for (let j = 1;j <= b.length; j++) {
|
|
539
|
+
for (let i = 1;i <= a.length; i++) {
|
|
540
|
+
let cost = 1;
|
|
541
|
+
if (a[i - 1] === b[j - 1]) {
|
|
542
|
+
cost = 0;
|
|
543
|
+
} else {
|
|
544
|
+
cost = 1;
|
|
545
|
+
}
|
|
546
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
547
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
548
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return d[a.length][b.length];
|
|
553
|
+
}
|
|
554
|
+
function suggestSimilar(word, candidates) {
|
|
555
|
+
if (!candidates || candidates.length === 0)
|
|
556
|
+
return "";
|
|
557
|
+
candidates = Array.from(new Set(candidates));
|
|
558
|
+
const searchingOptions = word.startsWith("--");
|
|
559
|
+
if (searchingOptions) {
|
|
560
|
+
word = word.slice(2);
|
|
561
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
562
|
+
}
|
|
563
|
+
let similar = [];
|
|
564
|
+
let bestDistance = maxDistance;
|
|
565
|
+
const minSimilarity = 0.4;
|
|
566
|
+
candidates.forEach((candidate) => {
|
|
567
|
+
if (candidate.length <= 1)
|
|
568
|
+
return;
|
|
569
|
+
const distance = editDistance(word, candidate);
|
|
570
|
+
const length = Math.max(word.length, candidate.length);
|
|
571
|
+
const similarity = (length - distance) / length;
|
|
572
|
+
if (similarity > minSimilarity) {
|
|
573
|
+
if (distance < bestDistance) {
|
|
574
|
+
bestDistance = distance;
|
|
575
|
+
similar = [candidate];
|
|
576
|
+
} else if (distance === bestDistance) {
|
|
577
|
+
similar.push(candidate);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
582
|
+
if (searchingOptions) {
|
|
583
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
584
|
+
}
|
|
585
|
+
if (similar.length > 1) {
|
|
586
|
+
return `
|
|
587
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
588
|
+
}
|
|
589
|
+
if (similar.length === 1) {
|
|
590
|
+
return `
|
|
591
|
+
(Did you mean ${similar[0]}?)`;
|
|
592
|
+
}
|
|
593
|
+
return "";
|
|
594
|
+
}
|
|
595
|
+
exports.suggestSimilar = suggestSimilar;
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
// node_modules/commander/lib/command.js
|
|
599
|
+
var require_command = __commonJS((exports) => {
|
|
600
|
+
var EventEmitter = __require("events").EventEmitter;
|
|
601
|
+
var childProcess = __require("child_process");
|
|
602
|
+
var path = __require("path");
|
|
603
|
+
var fs = __require("fs");
|
|
604
|
+
var process2 = __require("process");
|
|
605
|
+
var { Argument, humanReadableArgName } = require_argument();
|
|
606
|
+
var { CommanderError } = require_error();
|
|
607
|
+
var { Help } = require_help();
|
|
608
|
+
var { Option, splitOptionFlags, DualOptions } = require_option();
|
|
609
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
610
|
+
|
|
611
|
+
class Command extends EventEmitter {
|
|
612
|
+
constructor(name) {
|
|
613
|
+
super();
|
|
614
|
+
this.commands = [];
|
|
615
|
+
this.options = [];
|
|
616
|
+
this.parent = null;
|
|
617
|
+
this._allowUnknownOption = false;
|
|
618
|
+
this._allowExcessArguments = true;
|
|
619
|
+
this.registeredArguments = [];
|
|
620
|
+
this._args = this.registeredArguments;
|
|
621
|
+
this.args = [];
|
|
622
|
+
this.rawArgs = [];
|
|
623
|
+
this.processedArgs = [];
|
|
624
|
+
this._scriptPath = null;
|
|
625
|
+
this._name = name || "";
|
|
626
|
+
this._optionValues = {};
|
|
627
|
+
this._optionValueSources = {};
|
|
628
|
+
this._storeOptionsAsProperties = false;
|
|
629
|
+
this._actionHandler = null;
|
|
630
|
+
this._executableHandler = false;
|
|
631
|
+
this._executableFile = null;
|
|
632
|
+
this._executableDir = null;
|
|
633
|
+
this._defaultCommandName = null;
|
|
634
|
+
this._exitCallback = null;
|
|
635
|
+
this._aliases = [];
|
|
636
|
+
this._combineFlagAndOptionalValue = true;
|
|
637
|
+
this._description = "";
|
|
638
|
+
this._summary = "";
|
|
639
|
+
this._argsDescription = undefined;
|
|
640
|
+
this._enablePositionalOptions = false;
|
|
641
|
+
this._passThroughOptions = false;
|
|
642
|
+
this._lifeCycleHooks = {};
|
|
643
|
+
this._showHelpAfterError = false;
|
|
644
|
+
this._showSuggestionAfterError = true;
|
|
645
|
+
this._outputConfiguration = {
|
|
646
|
+
writeOut: (str) => process2.stdout.write(str),
|
|
647
|
+
writeErr: (str) => process2.stderr.write(str),
|
|
648
|
+
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
|
|
649
|
+
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
|
|
650
|
+
outputError: (str, write) => write(str)
|
|
651
|
+
};
|
|
652
|
+
this._hidden = false;
|
|
653
|
+
this._hasHelpOption = true;
|
|
654
|
+
this._helpFlags = "-h, --help";
|
|
655
|
+
this._helpDescription = "display help for command";
|
|
656
|
+
this._helpShortFlag = "-h";
|
|
657
|
+
this._helpLongFlag = "--help";
|
|
658
|
+
this._addImplicitHelpCommand = undefined;
|
|
659
|
+
this._helpCommandName = "help";
|
|
660
|
+
this._helpCommandnameAndArgs = "help [command]";
|
|
661
|
+
this._helpCommandDescription = "display help for command";
|
|
662
|
+
this._helpConfiguration = {};
|
|
663
|
+
}
|
|
664
|
+
copyInheritedSettings(sourceCommand) {
|
|
665
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
666
|
+
this._hasHelpOption = sourceCommand._hasHelpOption;
|
|
667
|
+
this._helpFlags = sourceCommand._helpFlags;
|
|
668
|
+
this._helpDescription = sourceCommand._helpDescription;
|
|
669
|
+
this._helpShortFlag = sourceCommand._helpShortFlag;
|
|
670
|
+
this._helpLongFlag = sourceCommand._helpLongFlag;
|
|
671
|
+
this._helpCommandName = sourceCommand._helpCommandName;
|
|
672
|
+
this._helpCommandnameAndArgs = sourceCommand._helpCommandnameAndArgs;
|
|
673
|
+
this._helpCommandDescription = sourceCommand._helpCommandDescription;
|
|
674
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
675
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
676
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
677
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
678
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
679
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
680
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
681
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
682
|
+
return this;
|
|
683
|
+
}
|
|
684
|
+
_getCommandAndAncestors() {
|
|
685
|
+
const result = [];
|
|
686
|
+
for (let command = this;command; command = command.parent) {
|
|
687
|
+
result.push(command);
|
|
688
|
+
}
|
|
689
|
+
return result;
|
|
690
|
+
}
|
|
691
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
692
|
+
let desc = actionOptsOrExecDesc;
|
|
693
|
+
let opts = execOpts;
|
|
694
|
+
if (typeof desc === "object" && desc !== null) {
|
|
695
|
+
opts = desc;
|
|
696
|
+
desc = null;
|
|
697
|
+
}
|
|
698
|
+
opts = opts || {};
|
|
699
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
700
|
+
const cmd = this.createCommand(name);
|
|
701
|
+
if (desc) {
|
|
702
|
+
cmd.description(desc);
|
|
703
|
+
cmd._executableHandler = true;
|
|
704
|
+
}
|
|
705
|
+
if (opts.isDefault)
|
|
706
|
+
this._defaultCommandName = cmd._name;
|
|
707
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
708
|
+
cmd._executableFile = opts.executableFile || null;
|
|
709
|
+
if (args)
|
|
710
|
+
cmd.arguments(args);
|
|
711
|
+
this.commands.push(cmd);
|
|
712
|
+
cmd.parent = this;
|
|
713
|
+
cmd.copyInheritedSettings(this);
|
|
714
|
+
if (desc)
|
|
715
|
+
return this;
|
|
716
|
+
return cmd;
|
|
717
|
+
}
|
|
718
|
+
createCommand(name) {
|
|
719
|
+
return new Command(name);
|
|
720
|
+
}
|
|
721
|
+
createHelp() {
|
|
722
|
+
return Object.assign(new Help, this.configureHelp());
|
|
723
|
+
}
|
|
724
|
+
configureHelp(configuration) {
|
|
725
|
+
if (configuration === undefined)
|
|
726
|
+
return this._helpConfiguration;
|
|
727
|
+
this._helpConfiguration = configuration;
|
|
728
|
+
return this;
|
|
729
|
+
}
|
|
730
|
+
configureOutput(configuration) {
|
|
731
|
+
if (configuration === undefined)
|
|
732
|
+
return this._outputConfiguration;
|
|
733
|
+
Object.assign(this._outputConfiguration, configuration);
|
|
734
|
+
return this;
|
|
735
|
+
}
|
|
736
|
+
showHelpAfterError(displayHelp = true) {
|
|
737
|
+
if (typeof displayHelp !== "string")
|
|
738
|
+
displayHelp = !!displayHelp;
|
|
739
|
+
this._showHelpAfterError = displayHelp;
|
|
740
|
+
return this;
|
|
741
|
+
}
|
|
742
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
743
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
744
|
+
return this;
|
|
745
|
+
}
|
|
746
|
+
addCommand(cmd, opts) {
|
|
747
|
+
if (!cmd._name) {
|
|
748
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
749
|
+
- specify the name in Command constructor or using .name()`);
|
|
750
|
+
}
|
|
751
|
+
opts = opts || {};
|
|
752
|
+
if (opts.isDefault)
|
|
753
|
+
this._defaultCommandName = cmd._name;
|
|
754
|
+
if (opts.noHelp || opts.hidden)
|
|
755
|
+
cmd._hidden = true;
|
|
756
|
+
this.commands.push(cmd);
|
|
757
|
+
cmd.parent = this;
|
|
758
|
+
return this;
|
|
759
|
+
}
|
|
760
|
+
createArgument(name, description) {
|
|
761
|
+
return new Argument(name, description);
|
|
762
|
+
}
|
|
763
|
+
argument(name, description, fn, defaultValue) {
|
|
764
|
+
const argument = this.createArgument(name, description);
|
|
765
|
+
if (typeof fn === "function") {
|
|
766
|
+
argument.default(defaultValue).argParser(fn);
|
|
767
|
+
} else {
|
|
768
|
+
argument.default(fn);
|
|
769
|
+
}
|
|
770
|
+
this.addArgument(argument);
|
|
771
|
+
return this;
|
|
772
|
+
}
|
|
773
|
+
arguments(names) {
|
|
774
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
775
|
+
this.argument(detail);
|
|
776
|
+
});
|
|
777
|
+
return this;
|
|
778
|
+
}
|
|
779
|
+
addArgument(argument) {
|
|
780
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
781
|
+
if (previousArgument && previousArgument.variadic) {
|
|
782
|
+
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
783
|
+
}
|
|
784
|
+
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
785
|
+
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
786
|
+
}
|
|
787
|
+
this.registeredArguments.push(argument);
|
|
788
|
+
return this;
|
|
789
|
+
}
|
|
790
|
+
addHelpCommand(enableOrNameAndArgs, description) {
|
|
791
|
+
if (enableOrNameAndArgs === false) {
|
|
792
|
+
this._addImplicitHelpCommand = false;
|
|
793
|
+
} else {
|
|
794
|
+
this._addImplicitHelpCommand = true;
|
|
795
|
+
if (typeof enableOrNameAndArgs === "string") {
|
|
796
|
+
this._helpCommandName = enableOrNameAndArgs.split(" ")[0];
|
|
797
|
+
this._helpCommandnameAndArgs = enableOrNameAndArgs;
|
|
798
|
+
}
|
|
799
|
+
this._helpCommandDescription = description || this._helpCommandDescription;
|
|
800
|
+
}
|
|
801
|
+
return this;
|
|
802
|
+
}
|
|
803
|
+
_hasImplicitHelpCommand() {
|
|
804
|
+
if (this._addImplicitHelpCommand === undefined) {
|
|
805
|
+
return this.commands.length && !this._actionHandler && !this._findCommand("help");
|
|
806
|
+
}
|
|
807
|
+
return this._addImplicitHelpCommand;
|
|
808
|
+
}
|
|
809
|
+
hook(event, listener) {
|
|
810
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
811
|
+
if (!allowedValues.includes(event)) {
|
|
812
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
813
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
814
|
+
}
|
|
815
|
+
if (this._lifeCycleHooks[event]) {
|
|
816
|
+
this._lifeCycleHooks[event].push(listener);
|
|
817
|
+
} else {
|
|
818
|
+
this._lifeCycleHooks[event] = [listener];
|
|
819
|
+
}
|
|
820
|
+
return this;
|
|
821
|
+
}
|
|
822
|
+
exitOverride(fn) {
|
|
823
|
+
if (fn) {
|
|
824
|
+
this._exitCallback = fn;
|
|
825
|
+
} else {
|
|
826
|
+
this._exitCallback = (err) => {
|
|
827
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
828
|
+
throw err;
|
|
829
|
+
} else {}
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
return this;
|
|
833
|
+
}
|
|
834
|
+
_exit(exitCode, code, message) {
|
|
835
|
+
if (this._exitCallback) {
|
|
836
|
+
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
837
|
+
}
|
|
838
|
+
process2.exit(exitCode);
|
|
839
|
+
}
|
|
840
|
+
action(fn) {
|
|
841
|
+
const listener = (args) => {
|
|
842
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
843
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
844
|
+
if (this._storeOptionsAsProperties) {
|
|
845
|
+
actionArgs[expectedArgsCount] = this;
|
|
846
|
+
} else {
|
|
847
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
848
|
+
}
|
|
849
|
+
actionArgs.push(this);
|
|
850
|
+
return fn.apply(this, actionArgs);
|
|
851
|
+
};
|
|
852
|
+
this._actionHandler = listener;
|
|
853
|
+
return this;
|
|
854
|
+
}
|
|
855
|
+
createOption(flags, description) {
|
|
856
|
+
return new Option(flags, description);
|
|
857
|
+
}
|
|
858
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
859
|
+
try {
|
|
860
|
+
return target.parseArg(value, previous);
|
|
861
|
+
} catch (err) {
|
|
862
|
+
if (err.code === "commander.invalidArgument") {
|
|
863
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
864
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
865
|
+
}
|
|
866
|
+
throw err;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
addOption(option) {
|
|
870
|
+
const oname = option.name();
|
|
871
|
+
const name = option.attributeName();
|
|
872
|
+
if (option.negate) {
|
|
873
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
874
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
875
|
+
this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
|
|
876
|
+
}
|
|
877
|
+
} else if (option.defaultValue !== undefined) {
|
|
878
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
879
|
+
}
|
|
880
|
+
this.options.push(option);
|
|
881
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
882
|
+
if (val == null && option.presetArg !== undefined) {
|
|
883
|
+
val = option.presetArg;
|
|
884
|
+
}
|
|
885
|
+
const oldValue = this.getOptionValue(name);
|
|
886
|
+
if (val !== null && option.parseArg) {
|
|
887
|
+
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
888
|
+
} else if (val !== null && option.variadic) {
|
|
889
|
+
val = option._concatValue(val, oldValue);
|
|
890
|
+
}
|
|
891
|
+
if (val == null) {
|
|
892
|
+
if (option.negate) {
|
|
893
|
+
val = false;
|
|
894
|
+
} else if (option.isBoolean() || option.optional) {
|
|
895
|
+
val = true;
|
|
896
|
+
} else {
|
|
897
|
+
val = "";
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
901
|
+
};
|
|
902
|
+
this.on("option:" + oname, (val) => {
|
|
903
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
904
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
905
|
+
});
|
|
906
|
+
if (option.envVar) {
|
|
907
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
908
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
909
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
return this;
|
|
913
|
+
}
|
|
914
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
915
|
+
if (typeof flags === "object" && flags instanceof Option) {
|
|
916
|
+
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
917
|
+
}
|
|
918
|
+
const option = this.createOption(flags, description);
|
|
919
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
920
|
+
if (typeof fn === "function") {
|
|
921
|
+
option.default(defaultValue).argParser(fn);
|
|
922
|
+
} else if (fn instanceof RegExp) {
|
|
923
|
+
const regex = fn;
|
|
924
|
+
fn = (val, def) => {
|
|
925
|
+
const m = regex.exec(val);
|
|
926
|
+
return m ? m[0] : def;
|
|
927
|
+
};
|
|
928
|
+
option.default(defaultValue).argParser(fn);
|
|
929
|
+
} else {
|
|
930
|
+
option.default(fn);
|
|
931
|
+
}
|
|
932
|
+
return this.addOption(option);
|
|
933
|
+
}
|
|
934
|
+
option(flags, description, parseArg, defaultValue) {
|
|
935
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
936
|
+
}
|
|
937
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
938
|
+
return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
|
|
939
|
+
}
|
|
940
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
941
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
942
|
+
return this;
|
|
943
|
+
}
|
|
944
|
+
allowUnknownOption(allowUnknown = true) {
|
|
945
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
946
|
+
return this;
|
|
947
|
+
}
|
|
948
|
+
allowExcessArguments(allowExcess = true) {
|
|
949
|
+
this._allowExcessArguments = !!allowExcess;
|
|
950
|
+
return this;
|
|
951
|
+
}
|
|
952
|
+
enablePositionalOptions(positional = true) {
|
|
953
|
+
this._enablePositionalOptions = !!positional;
|
|
954
|
+
return this;
|
|
955
|
+
}
|
|
956
|
+
passThroughOptions(passThrough = true) {
|
|
957
|
+
this._passThroughOptions = !!passThrough;
|
|
958
|
+
if (!!this.parent && passThrough && !this.parent._enablePositionalOptions) {
|
|
959
|
+
throw new Error("passThroughOptions can not be used without turning on enablePositionalOptions for parent command(s)");
|
|
960
|
+
}
|
|
961
|
+
return this;
|
|
962
|
+
}
|
|
963
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
964
|
+
if (this.options.length) {
|
|
965
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
966
|
+
}
|
|
967
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
968
|
+
return this;
|
|
969
|
+
}
|
|
970
|
+
getOptionValue(key) {
|
|
971
|
+
if (this._storeOptionsAsProperties) {
|
|
972
|
+
return this[key];
|
|
973
|
+
}
|
|
974
|
+
return this._optionValues[key];
|
|
975
|
+
}
|
|
976
|
+
setOptionValue(key, value) {
|
|
977
|
+
return this.setOptionValueWithSource(key, value, undefined);
|
|
978
|
+
}
|
|
979
|
+
setOptionValueWithSource(key, value, source) {
|
|
980
|
+
if (this._storeOptionsAsProperties) {
|
|
981
|
+
this[key] = value;
|
|
982
|
+
} else {
|
|
983
|
+
this._optionValues[key] = value;
|
|
984
|
+
}
|
|
985
|
+
this._optionValueSources[key] = source;
|
|
986
|
+
return this;
|
|
987
|
+
}
|
|
988
|
+
getOptionValueSource(key) {
|
|
989
|
+
return this._optionValueSources[key];
|
|
990
|
+
}
|
|
991
|
+
getOptionValueSourceWithGlobals(key) {
|
|
992
|
+
let source;
|
|
993
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
994
|
+
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
995
|
+
source = cmd.getOptionValueSource(key);
|
|
996
|
+
}
|
|
997
|
+
});
|
|
998
|
+
return source;
|
|
999
|
+
}
|
|
1000
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
1001
|
+
if (argv !== undefined && !Array.isArray(argv)) {
|
|
1002
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
1003
|
+
}
|
|
1004
|
+
parseOptions = parseOptions || {};
|
|
1005
|
+
if (argv === undefined) {
|
|
1006
|
+
argv = process2.argv;
|
|
1007
|
+
if (process2.versions && process2.versions.electron) {
|
|
1008
|
+
parseOptions.from = "electron";
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
this.rawArgs = argv.slice();
|
|
1012
|
+
let userArgs;
|
|
1013
|
+
switch (parseOptions.from) {
|
|
1014
|
+
case undefined:
|
|
1015
|
+
case "node":
|
|
1016
|
+
this._scriptPath = argv[1];
|
|
1017
|
+
userArgs = argv.slice(2);
|
|
1018
|
+
break;
|
|
1019
|
+
case "electron":
|
|
1020
|
+
if (process2.defaultApp) {
|
|
1021
|
+
this._scriptPath = argv[1];
|
|
1022
|
+
userArgs = argv.slice(2);
|
|
1023
|
+
} else {
|
|
1024
|
+
userArgs = argv.slice(1);
|
|
1025
|
+
}
|
|
1026
|
+
break;
|
|
1027
|
+
case "user":
|
|
1028
|
+
userArgs = argv.slice(0);
|
|
1029
|
+
break;
|
|
1030
|
+
default:
|
|
1031
|
+
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
1032
|
+
}
|
|
1033
|
+
if (!this._name && this._scriptPath)
|
|
1034
|
+
this.nameFromFilename(this._scriptPath);
|
|
1035
|
+
this._name = this._name || "program";
|
|
1036
|
+
return userArgs;
|
|
1037
|
+
}
|
|
1038
|
+
parse(argv, parseOptions) {
|
|
1039
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1040
|
+
this._parseCommand([], userArgs);
|
|
1041
|
+
return this;
|
|
1042
|
+
}
|
|
1043
|
+
async parseAsync(argv, parseOptions) {
|
|
1044
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1045
|
+
await this._parseCommand([], userArgs);
|
|
1046
|
+
return this;
|
|
1047
|
+
}
|
|
1048
|
+
_executeSubCommand(subcommand, args) {
|
|
1049
|
+
args = args.slice();
|
|
1050
|
+
let launchWithNode = false;
|
|
1051
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1052
|
+
function findFile(baseDir, baseName) {
|
|
1053
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
1054
|
+
if (fs.existsSync(localBin))
|
|
1055
|
+
return localBin;
|
|
1056
|
+
if (sourceExt.includes(path.extname(baseName)))
|
|
1057
|
+
return;
|
|
1058
|
+
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
1059
|
+
if (foundExt)
|
|
1060
|
+
return `${localBin}${foundExt}`;
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
this._checkForMissingMandatoryOptions();
|
|
1064
|
+
this._checkForConflictingOptions();
|
|
1065
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
1066
|
+
let executableDir = this._executableDir || "";
|
|
1067
|
+
if (this._scriptPath) {
|
|
1068
|
+
let resolvedScriptPath;
|
|
1069
|
+
try {
|
|
1070
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1071
|
+
} catch (err) {
|
|
1072
|
+
resolvedScriptPath = this._scriptPath;
|
|
1073
|
+
}
|
|
1074
|
+
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
1075
|
+
}
|
|
1076
|
+
if (executableDir) {
|
|
1077
|
+
let localFile = findFile(executableDir, executableFile);
|
|
1078
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1079
|
+
const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
1080
|
+
if (legacyName !== this._name) {
|
|
1081
|
+
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
executableFile = localFile || executableFile;
|
|
1085
|
+
}
|
|
1086
|
+
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
1087
|
+
let proc;
|
|
1088
|
+
if (process2.platform !== "win32") {
|
|
1089
|
+
if (launchWithNode) {
|
|
1090
|
+
args.unshift(executableFile);
|
|
1091
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1092
|
+
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
1093
|
+
} else {
|
|
1094
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1095
|
+
}
|
|
1096
|
+
} else {
|
|
1097
|
+
args.unshift(executableFile);
|
|
1098
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1099
|
+
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
1100
|
+
}
|
|
1101
|
+
if (!proc.killed) {
|
|
1102
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
1103
|
+
signals.forEach((signal) => {
|
|
1104
|
+
process2.on(signal, () => {
|
|
1105
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
1106
|
+
proc.kill(signal);
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
const exitCallback = this._exitCallback;
|
|
1112
|
+
if (!exitCallback) {
|
|
1113
|
+
proc.on("close", process2.exit.bind(process2));
|
|
1114
|
+
} else {
|
|
1115
|
+
proc.on("close", () => {
|
|
1116
|
+
exitCallback(new CommanderError(process2.exitCode || 0, "commander.executeSubCommandAsync", "(close)"));
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
proc.on("error", (err) => {
|
|
1120
|
+
if (err.code === "ENOENT") {
|
|
1121
|
+
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";
|
|
1122
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
1123
|
+
- if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1124
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1125
|
+
- ${executableDirMessage}`;
|
|
1126
|
+
throw new Error(executableMissing);
|
|
1127
|
+
} else if (err.code === "EACCES") {
|
|
1128
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
1129
|
+
}
|
|
1130
|
+
if (!exitCallback) {
|
|
1131
|
+
process2.exit(1);
|
|
1132
|
+
} else {
|
|
1133
|
+
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
1134
|
+
wrappedError.nestedError = err;
|
|
1135
|
+
exitCallback(wrappedError);
|
|
1136
|
+
}
|
|
1137
|
+
});
|
|
1138
|
+
this.runningCommand = proc;
|
|
1139
|
+
}
|
|
1140
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
1141
|
+
const subCommand = this._findCommand(commandName);
|
|
1142
|
+
if (!subCommand)
|
|
1143
|
+
this.help({ error: true });
|
|
1144
|
+
let promiseChain;
|
|
1145
|
+
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
|
|
1146
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1147
|
+
if (subCommand._executableHandler) {
|
|
1148
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
1149
|
+
} else {
|
|
1150
|
+
return subCommand._parseCommand(operands, unknown);
|
|
1151
|
+
}
|
|
1152
|
+
});
|
|
1153
|
+
return promiseChain;
|
|
1154
|
+
}
|
|
1155
|
+
_dispatchHelpCommand(subcommandName) {
|
|
1156
|
+
if (!subcommandName) {
|
|
1157
|
+
this.help();
|
|
1158
|
+
}
|
|
1159
|
+
const subCommand = this._findCommand(subcommandName);
|
|
1160
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
1161
|
+
subCommand.help();
|
|
1162
|
+
}
|
|
1163
|
+
return this._dispatchSubcommand(subcommandName, [], [
|
|
1164
|
+
this._helpLongFlag || this._helpShortFlag
|
|
1165
|
+
]);
|
|
1166
|
+
}
|
|
1167
|
+
_checkNumberOfArguments() {
|
|
1168
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
1169
|
+
if (arg.required && this.args[i] == null) {
|
|
1170
|
+
this.missingArgument(arg.name());
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1173
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
1177
|
+
this._excessArguments(this.args);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
_processArguments() {
|
|
1181
|
+
const myParseArg = (argument, value, previous) => {
|
|
1182
|
+
let parsedValue = value;
|
|
1183
|
+
if (value !== null && argument.parseArg) {
|
|
1184
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
1185
|
+
parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
|
|
1186
|
+
}
|
|
1187
|
+
return parsedValue;
|
|
1188
|
+
};
|
|
1189
|
+
this._checkNumberOfArguments();
|
|
1190
|
+
const processedArgs = [];
|
|
1191
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
1192
|
+
let value = declaredArg.defaultValue;
|
|
1193
|
+
if (declaredArg.variadic) {
|
|
1194
|
+
if (index < this.args.length) {
|
|
1195
|
+
value = this.args.slice(index);
|
|
1196
|
+
if (declaredArg.parseArg) {
|
|
1197
|
+
value = value.reduce((processed, v) => {
|
|
1198
|
+
return myParseArg(declaredArg, v, processed);
|
|
1199
|
+
}, declaredArg.defaultValue);
|
|
1200
|
+
}
|
|
1201
|
+
} else if (value === undefined) {
|
|
1202
|
+
value = [];
|
|
1203
|
+
}
|
|
1204
|
+
} else if (index < this.args.length) {
|
|
1205
|
+
value = this.args[index];
|
|
1206
|
+
if (declaredArg.parseArg) {
|
|
1207
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
processedArgs[index] = value;
|
|
1211
|
+
});
|
|
1212
|
+
this.processedArgs = processedArgs;
|
|
1213
|
+
}
|
|
1214
|
+
_chainOrCall(promise, fn) {
|
|
1215
|
+
if (promise && promise.then && typeof promise.then === "function") {
|
|
1216
|
+
return promise.then(() => fn());
|
|
1217
|
+
}
|
|
1218
|
+
return fn();
|
|
1219
|
+
}
|
|
1220
|
+
_chainOrCallHooks(promise, event) {
|
|
1221
|
+
let result = promise;
|
|
1222
|
+
const hooks = [];
|
|
1223
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
|
|
1224
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
1225
|
+
hooks.push({ hookedCommand, callback });
|
|
1226
|
+
});
|
|
1227
|
+
});
|
|
1228
|
+
if (event === "postAction") {
|
|
1229
|
+
hooks.reverse();
|
|
1230
|
+
}
|
|
1231
|
+
hooks.forEach((hookDetail) => {
|
|
1232
|
+
result = this._chainOrCall(result, () => {
|
|
1233
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
1234
|
+
});
|
|
1235
|
+
});
|
|
1236
|
+
return result;
|
|
1237
|
+
}
|
|
1238
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
1239
|
+
let result = promise;
|
|
1240
|
+
if (this._lifeCycleHooks[event] !== undefined) {
|
|
1241
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
1242
|
+
result = this._chainOrCall(result, () => {
|
|
1243
|
+
return hook(this, subCommand);
|
|
1244
|
+
});
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1247
|
+
return result;
|
|
1248
|
+
}
|
|
1249
|
+
_parseCommand(operands, unknown) {
|
|
1250
|
+
const parsed = this.parseOptions(unknown);
|
|
1251
|
+
this._parseOptionsEnv();
|
|
1252
|
+
this._parseOptionsImplied();
|
|
1253
|
+
operands = operands.concat(parsed.operands);
|
|
1254
|
+
unknown = parsed.unknown;
|
|
1255
|
+
this.args = operands.concat(unknown);
|
|
1256
|
+
if (operands && this._findCommand(operands[0])) {
|
|
1257
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
1258
|
+
}
|
|
1259
|
+
if (this._hasImplicitHelpCommand() && operands[0] === this._helpCommandName) {
|
|
1260
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
1261
|
+
}
|
|
1262
|
+
if (this._defaultCommandName) {
|
|
1263
|
+
outputHelpIfRequested(this, unknown);
|
|
1264
|
+
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
1265
|
+
}
|
|
1266
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
1267
|
+
this.help({ error: true });
|
|
1268
|
+
}
|
|
1269
|
+
outputHelpIfRequested(this, parsed.unknown);
|
|
1270
|
+
this._checkForMissingMandatoryOptions();
|
|
1271
|
+
this._checkForConflictingOptions();
|
|
1272
|
+
const checkForUnknownOptions = () => {
|
|
1273
|
+
if (parsed.unknown.length > 0) {
|
|
1274
|
+
this.unknownOption(parsed.unknown[0]);
|
|
1275
|
+
}
|
|
1276
|
+
};
|
|
1277
|
+
const commandEvent = `command:${this.name()}`;
|
|
1278
|
+
if (this._actionHandler) {
|
|
1279
|
+
checkForUnknownOptions();
|
|
1280
|
+
this._processArguments();
|
|
1281
|
+
let promiseChain;
|
|
1282
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
1283
|
+
promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
|
|
1284
|
+
if (this.parent) {
|
|
1285
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1286
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
1290
|
+
return promiseChain;
|
|
1291
|
+
}
|
|
1292
|
+
if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
1293
|
+
checkForUnknownOptions();
|
|
1294
|
+
this._processArguments();
|
|
1295
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1296
|
+
} else if (operands.length) {
|
|
1297
|
+
if (this._findCommand("*")) {
|
|
1298
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
1299
|
+
}
|
|
1300
|
+
if (this.listenerCount("command:*")) {
|
|
1301
|
+
this.emit("command:*", operands, unknown);
|
|
1302
|
+
} else if (this.commands.length) {
|
|
1303
|
+
this.unknownCommand();
|
|
1304
|
+
} else {
|
|
1305
|
+
checkForUnknownOptions();
|
|
1306
|
+
this._processArguments();
|
|
1307
|
+
}
|
|
1308
|
+
} else if (this.commands.length) {
|
|
1309
|
+
checkForUnknownOptions();
|
|
1310
|
+
this.help({ error: true });
|
|
1311
|
+
} else {
|
|
1312
|
+
checkForUnknownOptions();
|
|
1313
|
+
this._processArguments();
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
_findCommand(name) {
|
|
1317
|
+
if (!name)
|
|
1318
|
+
return;
|
|
1319
|
+
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
1320
|
+
}
|
|
1321
|
+
_findOption(arg) {
|
|
1322
|
+
return this.options.find((option) => option.is(arg));
|
|
1323
|
+
}
|
|
1324
|
+
_checkForMissingMandatoryOptions() {
|
|
1325
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1326
|
+
cmd.options.forEach((anOption) => {
|
|
1327
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
|
|
1328
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
1329
|
+
}
|
|
1330
|
+
});
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
_checkForConflictingLocalOptions() {
|
|
1334
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
1335
|
+
const optionKey = option.attributeName();
|
|
1336
|
+
if (this.getOptionValue(optionKey) === undefined) {
|
|
1337
|
+
return false;
|
|
1338
|
+
}
|
|
1339
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
1340
|
+
});
|
|
1341
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
1342
|
+
optionsWithConflicting.forEach((option) => {
|
|
1343
|
+
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
1344
|
+
if (conflictingAndDefined) {
|
|
1345
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
_checkForConflictingOptions() {
|
|
1350
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1351
|
+
cmd._checkForConflictingLocalOptions();
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
parseOptions(argv) {
|
|
1355
|
+
const operands = [];
|
|
1356
|
+
const unknown = [];
|
|
1357
|
+
let dest = operands;
|
|
1358
|
+
const args = argv.slice();
|
|
1359
|
+
function maybeOption(arg) {
|
|
1360
|
+
return arg.length > 1 && arg[0] === "-";
|
|
1361
|
+
}
|
|
1362
|
+
let activeVariadicOption = null;
|
|
1363
|
+
while (args.length) {
|
|
1364
|
+
const arg = args.shift();
|
|
1365
|
+
if (arg === "--") {
|
|
1366
|
+
if (dest === unknown)
|
|
1367
|
+
dest.push(arg);
|
|
1368
|
+
dest.push(...args);
|
|
1369
|
+
break;
|
|
1370
|
+
}
|
|
1371
|
+
if (activeVariadicOption && !maybeOption(arg)) {
|
|
1372
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1375
|
+
activeVariadicOption = null;
|
|
1376
|
+
if (maybeOption(arg)) {
|
|
1377
|
+
const option = this._findOption(arg);
|
|
1378
|
+
if (option) {
|
|
1379
|
+
if (option.required) {
|
|
1380
|
+
const value = args.shift();
|
|
1381
|
+
if (value === undefined)
|
|
1382
|
+
this.optionMissingArgument(option);
|
|
1383
|
+
this.emit(`option:${option.name()}`, value);
|
|
1384
|
+
} else if (option.optional) {
|
|
1385
|
+
let value = null;
|
|
1386
|
+
if (args.length > 0 && !maybeOption(args[0])) {
|
|
1387
|
+
value = args.shift();
|
|
1388
|
+
}
|
|
1389
|
+
this.emit(`option:${option.name()}`, value);
|
|
1390
|
+
} else {
|
|
1391
|
+
this.emit(`option:${option.name()}`);
|
|
1392
|
+
}
|
|
1393
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
1394
|
+
continue;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1398
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
1399
|
+
if (option) {
|
|
1400
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
1401
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1402
|
+
} else {
|
|
1403
|
+
this.emit(`option:${option.name()}`);
|
|
1404
|
+
args.unshift(`-${arg.slice(2)}`);
|
|
1405
|
+
}
|
|
1406
|
+
continue;
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
1410
|
+
const index = arg.indexOf("=");
|
|
1411
|
+
const option = this._findOption(arg.slice(0, index));
|
|
1412
|
+
if (option && (option.required || option.optional)) {
|
|
1413
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1414
|
+
continue;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
if (maybeOption(arg)) {
|
|
1418
|
+
dest = unknown;
|
|
1419
|
+
}
|
|
1420
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1421
|
+
if (this._findCommand(arg)) {
|
|
1422
|
+
operands.push(arg);
|
|
1423
|
+
if (args.length > 0)
|
|
1424
|
+
unknown.push(...args);
|
|
1425
|
+
break;
|
|
1426
|
+
} else if (arg === this._helpCommandName && this._hasImplicitHelpCommand()) {
|
|
1427
|
+
operands.push(arg);
|
|
1428
|
+
if (args.length > 0)
|
|
1429
|
+
operands.push(...args);
|
|
1430
|
+
break;
|
|
1431
|
+
} else if (this._defaultCommandName) {
|
|
1432
|
+
unknown.push(arg);
|
|
1433
|
+
if (args.length > 0)
|
|
1434
|
+
unknown.push(...args);
|
|
1435
|
+
break;
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
if (this._passThroughOptions) {
|
|
1439
|
+
dest.push(arg);
|
|
1440
|
+
if (args.length > 0)
|
|
1441
|
+
dest.push(...args);
|
|
1442
|
+
break;
|
|
1443
|
+
}
|
|
1444
|
+
dest.push(arg);
|
|
1445
|
+
}
|
|
1446
|
+
return { operands, unknown };
|
|
1447
|
+
}
|
|
1448
|
+
opts() {
|
|
1449
|
+
if (this._storeOptionsAsProperties) {
|
|
1450
|
+
const result = {};
|
|
1451
|
+
const len = this.options.length;
|
|
1452
|
+
for (let i = 0;i < len; i++) {
|
|
1453
|
+
const key = this.options[i].attributeName();
|
|
1454
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
1455
|
+
}
|
|
1456
|
+
return result;
|
|
1457
|
+
}
|
|
1458
|
+
return this._optionValues;
|
|
1459
|
+
}
|
|
1460
|
+
optsWithGlobals() {
|
|
1461
|
+
return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
1462
|
+
}
|
|
1463
|
+
error(message, errorOptions) {
|
|
1464
|
+
this._outputConfiguration.outputError(`${message}
|
|
1465
|
+
`, this._outputConfiguration.writeErr);
|
|
1466
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
1467
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
1468
|
+
`);
|
|
1469
|
+
} else if (this._showHelpAfterError) {
|
|
1470
|
+
this._outputConfiguration.writeErr(`
|
|
1471
|
+
`);
|
|
1472
|
+
this.outputHelp({ error: true });
|
|
1473
|
+
}
|
|
1474
|
+
const config = errorOptions || {};
|
|
1475
|
+
const exitCode = config.exitCode || 1;
|
|
1476
|
+
const code = config.code || "commander.error";
|
|
1477
|
+
this._exit(exitCode, code, message);
|
|
1478
|
+
}
|
|
1479
|
+
_parseOptionsEnv() {
|
|
1480
|
+
this.options.forEach((option) => {
|
|
1481
|
+
if (option.envVar && option.envVar in process2.env) {
|
|
1482
|
+
const optionKey = option.attributeName();
|
|
1483
|
+
if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
1484
|
+
if (option.required || option.optional) {
|
|
1485
|
+
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
1486
|
+
} else {
|
|
1487
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
_parseOptionsImplied() {
|
|
1494
|
+
const dualHelper = new DualOptions(this.options);
|
|
1495
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
1496
|
+
return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
1497
|
+
};
|
|
1498
|
+
this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
1499
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
1500
|
+
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
1501
|
+
});
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
missingArgument(name) {
|
|
1505
|
+
const message = `error: missing required argument '${name}'`;
|
|
1506
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
1507
|
+
}
|
|
1508
|
+
optionMissingArgument(option) {
|
|
1509
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
1510
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
1511
|
+
}
|
|
1512
|
+
missingMandatoryOptionValue(option) {
|
|
1513
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
1514
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
1515
|
+
}
|
|
1516
|
+
_conflictingOption(option, conflictingOption) {
|
|
1517
|
+
const findBestOptionFromValue = (option2) => {
|
|
1518
|
+
const optionKey = option2.attributeName();
|
|
1519
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
1520
|
+
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
1521
|
+
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
1522
|
+
if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
|
|
1523
|
+
return negativeOption;
|
|
1524
|
+
}
|
|
1525
|
+
return positiveOption || option2;
|
|
1526
|
+
};
|
|
1527
|
+
const getErrorMessage = (option2) => {
|
|
1528
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
1529
|
+
const optionKey = bestOption.attributeName();
|
|
1530
|
+
const source = this.getOptionValueSource(optionKey);
|
|
1531
|
+
if (source === "env") {
|
|
1532
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
1533
|
+
}
|
|
1534
|
+
return `option '${bestOption.flags}'`;
|
|
1535
|
+
};
|
|
1536
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
1537
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
1538
|
+
}
|
|
1539
|
+
unknownOption(flag) {
|
|
1540
|
+
if (this._allowUnknownOption)
|
|
1541
|
+
return;
|
|
1542
|
+
let suggestion = "";
|
|
1543
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
1544
|
+
let candidateFlags = [];
|
|
1545
|
+
let command = this;
|
|
1546
|
+
do {
|
|
1547
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
1548
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
1549
|
+
command = command.parent;
|
|
1550
|
+
} while (command && !command._enablePositionalOptions);
|
|
1551
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
1552
|
+
}
|
|
1553
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
1554
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
1555
|
+
}
|
|
1556
|
+
_excessArguments(receivedArgs) {
|
|
1557
|
+
if (this._allowExcessArguments)
|
|
1558
|
+
return;
|
|
1559
|
+
const expected = this.registeredArguments.length;
|
|
1560
|
+
const s = expected === 1 ? "" : "s";
|
|
1561
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
1562
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
1563
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
1564
|
+
}
|
|
1565
|
+
unknownCommand() {
|
|
1566
|
+
const unknownName = this.args[0];
|
|
1567
|
+
let suggestion = "";
|
|
1568
|
+
if (this._showSuggestionAfterError) {
|
|
1569
|
+
const candidateNames = [];
|
|
1570
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
1571
|
+
candidateNames.push(command.name());
|
|
1572
|
+
if (command.alias())
|
|
1573
|
+
candidateNames.push(command.alias());
|
|
1574
|
+
});
|
|
1575
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
1576
|
+
}
|
|
1577
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
1578
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
1579
|
+
}
|
|
1580
|
+
version(str, flags, description) {
|
|
1581
|
+
if (str === undefined)
|
|
1582
|
+
return this._version;
|
|
1583
|
+
this._version = str;
|
|
1584
|
+
flags = flags || "-V, --version";
|
|
1585
|
+
description = description || "output the version number";
|
|
1586
|
+
const versionOption = this.createOption(flags, description);
|
|
1587
|
+
this._versionOptionName = versionOption.attributeName();
|
|
1588
|
+
this.options.push(versionOption);
|
|
1589
|
+
this.on("option:" + versionOption.name(), () => {
|
|
1590
|
+
this._outputConfiguration.writeOut(`${str}
|
|
1591
|
+
`);
|
|
1592
|
+
this._exit(0, "commander.version", str);
|
|
1593
|
+
});
|
|
1594
|
+
return this;
|
|
1595
|
+
}
|
|
1596
|
+
description(str, argsDescription) {
|
|
1597
|
+
if (str === undefined && argsDescription === undefined)
|
|
1598
|
+
return this._description;
|
|
1599
|
+
this._description = str;
|
|
1600
|
+
if (argsDescription) {
|
|
1601
|
+
this._argsDescription = argsDescription;
|
|
1602
|
+
}
|
|
1603
|
+
return this;
|
|
1604
|
+
}
|
|
1605
|
+
summary(str) {
|
|
1606
|
+
if (str === undefined)
|
|
1607
|
+
return this._summary;
|
|
1608
|
+
this._summary = str;
|
|
1609
|
+
return this;
|
|
1610
|
+
}
|
|
1611
|
+
alias(alias) {
|
|
1612
|
+
if (alias === undefined)
|
|
1613
|
+
return this._aliases[0];
|
|
1614
|
+
let command = this;
|
|
1615
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
1616
|
+
command = this.commands[this.commands.length - 1];
|
|
1617
|
+
}
|
|
1618
|
+
if (alias === command._name)
|
|
1619
|
+
throw new Error("Command alias can't be the same as its name");
|
|
1620
|
+
command._aliases.push(alias);
|
|
1621
|
+
return this;
|
|
1622
|
+
}
|
|
1623
|
+
aliases(aliases) {
|
|
1624
|
+
if (aliases === undefined)
|
|
1625
|
+
return this._aliases;
|
|
1626
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
1627
|
+
return this;
|
|
1628
|
+
}
|
|
1629
|
+
usage(str) {
|
|
1630
|
+
if (str === undefined) {
|
|
1631
|
+
if (this._usage)
|
|
1632
|
+
return this._usage;
|
|
1633
|
+
const args = this.registeredArguments.map((arg) => {
|
|
1634
|
+
return humanReadableArgName(arg);
|
|
1635
|
+
});
|
|
1636
|
+
return [].concat(this.options.length || this._hasHelpOption ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
|
|
1637
|
+
}
|
|
1638
|
+
this._usage = str;
|
|
1639
|
+
return this;
|
|
1640
|
+
}
|
|
1641
|
+
name(str) {
|
|
1642
|
+
if (str === undefined)
|
|
1643
|
+
return this._name;
|
|
1644
|
+
this._name = str;
|
|
1645
|
+
return this;
|
|
1646
|
+
}
|
|
1647
|
+
nameFromFilename(filename) {
|
|
1648
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
1649
|
+
return this;
|
|
1650
|
+
}
|
|
1651
|
+
executableDir(path2) {
|
|
1652
|
+
if (path2 === undefined)
|
|
1653
|
+
return this._executableDir;
|
|
1654
|
+
this._executableDir = path2;
|
|
1655
|
+
return this;
|
|
1656
|
+
}
|
|
1657
|
+
helpInformation(contextOptions) {
|
|
1658
|
+
const helper = this.createHelp();
|
|
1659
|
+
if (helper.helpWidth === undefined) {
|
|
1660
|
+
helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
|
|
1661
|
+
}
|
|
1662
|
+
return helper.formatHelp(this, helper);
|
|
1663
|
+
}
|
|
1664
|
+
_getHelpContext(contextOptions) {
|
|
1665
|
+
contextOptions = contextOptions || {};
|
|
1666
|
+
const context = { error: !!contextOptions.error };
|
|
1667
|
+
let write;
|
|
1668
|
+
if (context.error) {
|
|
1669
|
+
write = (arg) => this._outputConfiguration.writeErr(arg);
|
|
1670
|
+
} else {
|
|
1671
|
+
write = (arg) => this._outputConfiguration.writeOut(arg);
|
|
1672
|
+
}
|
|
1673
|
+
context.write = contextOptions.write || write;
|
|
1674
|
+
context.command = this;
|
|
1675
|
+
return context;
|
|
1676
|
+
}
|
|
1677
|
+
outputHelp(contextOptions) {
|
|
1678
|
+
let deprecatedCallback;
|
|
1679
|
+
if (typeof contextOptions === "function") {
|
|
1680
|
+
deprecatedCallback = contextOptions;
|
|
1681
|
+
contextOptions = undefined;
|
|
1682
|
+
}
|
|
1683
|
+
const context = this._getHelpContext(contextOptions);
|
|
1684
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", context));
|
|
1685
|
+
this.emit("beforeHelp", context);
|
|
1686
|
+
let helpInformation = this.helpInformation(context);
|
|
1687
|
+
if (deprecatedCallback) {
|
|
1688
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
1689
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
1690
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
context.write(helpInformation);
|
|
1694
|
+
if (this._helpLongFlag) {
|
|
1695
|
+
this.emit(this._helpLongFlag);
|
|
1696
|
+
}
|
|
1697
|
+
this.emit("afterHelp", context);
|
|
1698
|
+
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", context));
|
|
1699
|
+
}
|
|
1700
|
+
helpOption(flags, description) {
|
|
1701
|
+
if (typeof flags === "boolean") {
|
|
1702
|
+
this._hasHelpOption = flags;
|
|
1703
|
+
return this;
|
|
1704
|
+
}
|
|
1705
|
+
this._helpFlags = flags || this._helpFlags;
|
|
1706
|
+
this._helpDescription = description || this._helpDescription;
|
|
1707
|
+
const helpFlags = splitOptionFlags(this._helpFlags);
|
|
1708
|
+
this._helpShortFlag = helpFlags.shortFlag;
|
|
1709
|
+
this._helpLongFlag = helpFlags.longFlag;
|
|
1710
|
+
return this;
|
|
1711
|
+
}
|
|
1712
|
+
help(contextOptions) {
|
|
1713
|
+
this.outputHelp(contextOptions);
|
|
1714
|
+
let exitCode = process2.exitCode || 0;
|
|
1715
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
1716
|
+
exitCode = 1;
|
|
1717
|
+
}
|
|
1718
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
1719
|
+
}
|
|
1720
|
+
addHelpText(position, text) {
|
|
1721
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
1722
|
+
if (!allowedValues.includes(position)) {
|
|
1723
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
1724
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1725
|
+
}
|
|
1726
|
+
const helpEvent = `${position}Help`;
|
|
1727
|
+
this.on(helpEvent, (context) => {
|
|
1728
|
+
let helpStr;
|
|
1729
|
+
if (typeof text === "function") {
|
|
1730
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
1731
|
+
} else {
|
|
1732
|
+
helpStr = text;
|
|
1733
|
+
}
|
|
1734
|
+
if (helpStr) {
|
|
1735
|
+
context.write(`${helpStr}
|
|
1736
|
+
`);
|
|
1737
|
+
}
|
|
1738
|
+
});
|
|
1739
|
+
return this;
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
function outputHelpIfRequested(cmd, args) {
|
|
1743
|
+
const helpOption = cmd._hasHelpOption && args.find((arg) => arg === cmd._helpLongFlag || arg === cmd._helpShortFlag);
|
|
1744
|
+
if (helpOption) {
|
|
1745
|
+
cmd.outputHelp();
|
|
1746
|
+
cmd._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
function incrementNodeInspectorPort(args) {
|
|
1750
|
+
return args.map((arg) => {
|
|
1751
|
+
if (!arg.startsWith("--inspect")) {
|
|
1752
|
+
return arg;
|
|
1753
|
+
}
|
|
1754
|
+
let debugOption;
|
|
1755
|
+
let debugHost = "127.0.0.1";
|
|
1756
|
+
let debugPort = "9229";
|
|
1757
|
+
let match;
|
|
1758
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
1759
|
+
debugOption = match[1];
|
|
1760
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
1761
|
+
debugOption = match[1];
|
|
1762
|
+
if (/^\d+$/.test(match[3])) {
|
|
1763
|
+
debugPort = match[3];
|
|
1764
|
+
} else {
|
|
1765
|
+
debugHost = match[3];
|
|
1766
|
+
}
|
|
1767
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
1768
|
+
debugOption = match[1];
|
|
1769
|
+
debugHost = match[3];
|
|
1770
|
+
debugPort = match[4];
|
|
1771
|
+
}
|
|
1772
|
+
if (debugOption && debugPort !== "0") {
|
|
1773
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
1774
|
+
}
|
|
1775
|
+
return arg;
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
exports.Command = Command;
|
|
1779
|
+
});
|
|
1780
|
+
|
|
1781
|
+
// node_modules/commander/index.js
|
|
1782
|
+
var require_commander = __commonJS((exports, module) => {
|
|
1783
|
+
var { Argument } = require_argument();
|
|
1784
|
+
var { Command } = require_command();
|
|
1785
|
+
var { CommanderError, InvalidArgumentError } = require_error();
|
|
1786
|
+
var { Help } = require_help();
|
|
1787
|
+
var { Option } = require_option();
|
|
1788
|
+
exports = module.exports = new Command;
|
|
1789
|
+
exports.program = exports;
|
|
1790
|
+
exports.Command = Command;
|
|
1791
|
+
exports.Option = Option;
|
|
1792
|
+
exports.Argument = Argument;
|
|
1793
|
+
exports.Help = Help;
|
|
1794
|
+
exports.CommanderError = CommanderError;
|
|
1795
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
1796
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
1797
|
+
});
|
|
1798
|
+
|
|
1799
|
+
// node_modules/commander/esm.mjs
|
|
1800
|
+
var import__ = __toESM(require_commander(), 1);
|
|
1801
|
+
var {
|
|
1802
|
+
program,
|
|
1803
|
+
createCommand,
|
|
1804
|
+
createArgument,
|
|
1805
|
+
createOption,
|
|
1806
|
+
CommanderError,
|
|
1807
|
+
InvalidArgumentError,
|
|
1808
|
+
InvalidOptionArgumentError,
|
|
1809
|
+
Command,
|
|
1810
|
+
Argument,
|
|
1811
|
+
Option,
|
|
1812
|
+
Help
|
|
1813
|
+
} = import__.default;
|
|
1814
|
+
|
|
1815
|
+
// node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
1816
|
+
var ANSI_BACKGROUND_OFFSET = 10;
|
|
1817
|
+
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
1818
|
+
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
1819
|
+
var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
|
|
1820
|
+
var styles = {
|
|
1821
|
+
modifier: {
|
|
1822
|
+
reset: [0, 0],
|
|
1823
|
+
bold: [1, 22],
|
|
1824
|
+
dim: [2, 22],
|
|
1825
|
+
italic: [3, 23],
|
|
1826
|
+
underline: [4, 24],
|
|
1827
|
+
overline: [53, 55],
|
|
1828
|
+
inverse: [7, 27],
|
|
1829
|
+
hidden: [8, 28],
|
|
1830
|
+
strikethrough: [9, 29]
|
|
1831
|
+
},
|
|
1832
|
+
color: {
|
|
1833
|
+
black: [30, 39],
|
|
1834
|
+
red: [31, 39],
|
|
1835
|
+
green: [32, 39],
|
|
1836
|
+
yellow: [33, 39],
|
|
1837
|
+
blue: [34, 39],
|
|
1838
|
+
magenta: [35, 39],
|
|
1839
|
+
cyan: [36, 39],
|
|
1840
|
+
white: [37, 39],
|
|
1841
|
+
blackBright: [90, 39],
|
|
1842
|
+
gray: [90, 39],
|
|
1843
|
+
grey: [90, 39],
|
|
1844
|
+
redBright: [91, 39],
|
|
1845
|
+
greenBright: [92, 39],
|
|
1846
|
+
yellowBright: [93, 39],
|
|
1847
|
+
blueBright: [94, 39],
|
|
1848
|
+
magentaBright: [95, 39],
|
|
1849
|
+
cyanBright: [96, 39],
|
|
1850
|
+
whiteBright: [97, 39]
|
|
1851
|
+
},
|
|
1852
|
+
bgColor: {
|
|
1853
|
+
bgBlack: [40, 49],
|
|
1854
|
+
bgRed: [41, 49],
|
|
1855
|
+
bgGreen: [42, 49],
|
|
1856
|
+
bgYellow: [43, 49],
|
|
1857
|
+
bgBlue: [44, 49],
|
|
1858
|
+
bgMagenta: [45, 49],
|
|
1859
|
+
bgCyan: [46, 49],
|
|
1860
|
+
bgWhite: [47, 49],
|
|
1861
|
+
bgBlackBright: [100, 49],
|
|
1862
|
+
bgGray: [100, 49],
|
|
1863
|
+
bgGrey: [100, 49],
|
|
1864
|
+
bgRedBright: [101, 49],
|
|
1865
|
+
bgGreenBright: [102, 49],
|
|
1866
|
+
bgYellowBright: [103, 49],
|
|
1867
|
+
bgBlueBright: [104, 49],
|
|
1868
|
+
bgMagentaBright: [105, 49],
|
|
1869
|
+
bgCyanBright: [106, 49],
|
|
1870
|
+
bgWhiteBright: [107, 49]
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
var modifierNames = Object.keys(styles.modifier);
|
|
1874
|
+
var foregroundColorNames = Object.keys(styles.color);
|
|
1875
|
+
var backgroundColorNames = Object.keys(styles.bgColor);
|
|
1876
|
+
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
1877
|
+
function assembleStyles() {
|
|
1878
|
+
const codes = new Map;
|
|
1879
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
1880
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
1881
|
+
styles[styleName] = {
|
|
1882
|
+
open: `\x1B[${style[0]}m`,
|
|
1883
|
+
close: `\x1B[${style[1]}m`
|
|
1884
|
+
};
|
|
1885
|
+
group[styleName] = styles[styleName];
|
|
1886
|
+
codes.set(style[0], style[1]);
|
|
1887
|
+
}
|
|
1888
|
+
Object.defineProperty(styles, groupName, {
|
|
1889
|
+
value: group,
|
|
1890
|
+
enumerable: false
|
|
1891
|
+
});
|
|
1892
|
+
}
|
|
1893
|
+
Object.defineProperty(styles, "codes", {
|
|
1894
|
+
value: codes,
|
|
1895
|
+
enumerable: false
|
|
1896
|
+
});
|
|
1897
|
+
styles.color.close = "\x1B[39m";
|
|
1898
|
+
styles.bgColor.close = "\x1B[49m";
|
|
1899
|
+
styles.color.ansi = wrapAnsi16();
|
|
1900
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
1901
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
1902
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
1903
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
1904
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
1905
|
+
Object.defineProperties(styles, {
|
|
1906
|
+
rgbToAnsi256: {
|
|
1907
|
+
value(red, green, blue) {
|
|
1908
|
+
if (red === green && green === blue) {
|
|
1909
|
+
if (red < 8) {
|
|
1910
|
+
return 16;
|
|
1911
|
+
}
|
|
1912
|
+
if (red > 248) {
|
|
1913
|
+
return 231;
|
|
1914
|
+
}
|
|
1915
|
+
return Math.round((red - 8) / 247 * 24) + 232;
|
|
1916
|
+
}
|
|
1917
|
+
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
1918
|
+
},
|
|
1919
|
+
enumerable: false
|
|
1920
|
+
},
|
|
1921
|
+
hexToRgb: {
|
|
1922
|
+
value(hex) {
|
|
1923
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
1924
|
+
if (!matches) {
|
|
1925
|
+
return [0, 0, 0];
|
|
1926
|
+
}
|
|
1927
|
+
let [colorString] = matches;
|
|
1928
|
+
if (colorString.length === 3) {
|
|
1929
|
+
colorString = [...colorString].map((character) => character + character).join("");
|
|
1930
|
+
}
|
|
1931
|
+
const integer = Number.parseInt(colorString, 16);
|
|
1932
|
+
return [
|
|
1933
|
+
integer >> 16 & 255,
|
|
1934
|
+
integer >> 8 & 255,
|
|
1935
|
+
integer & 255
|
|
1936
|
+
];
|
|
1937
|
+
},
|
|
1938
|
+
enumerable: false
|
|
1939
|
+
},
|
|
1940
|
+
hexToAnsi256: {
|
|
1941
|
+
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
1942
|
+
enumerable: false
|
|
1943
|
+
},
|
|
1944
|
+
ansi256ToAnsi: {
|
|
1945
|
+
value(code) {
|
|
1946
|
+
if (code < 8) {
|
|
1947
|
+
return 30 + code;
|
|
1948
|
+
}
|
|
1949
|
+
if (code < 16) {
|
|
1950
|
+
return 90 + (code - 8);
|
|
1951
|
+
}
|
|
1952
|
+
let red;
|
|
1953
|
+
let green;
|
|
1954
|
+
let blue;
|
|
1955
|
+
if (code >= 232) {
|
|
1956
|
+
red = ((code - 232) * 10 + 8) / 255;
|
|
1957
|
+
green = red;
|
|
1958
|
+
blue = red;
|
|
1959
|
+
} else {
|
|
1960
|
+
code -= 16;
|
|
1961
|
+
const remainder = code % 36;
|
|
1962
|
+
red = Math.floor(code / 36) / 5;
|
|
1963
|
+
green = Math.floor(remainder / 6) / 5;
|
|
1964
|
+
blue = remainder % 6 / 5;
|
|
1965
|
+
}
|
|
1966
|
+
const value = Math.max(red, green, blue) * 2;
|
|
1967
|
+
if (value === 0) {
|
|
1968
|
+
return 30;
|
|
1969
|
+
}
|
|
1970
|
+
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
1971
|
+
if (value === 2) {
|
|
1972
|
+
result += 60;
|
|
1973
|
+
}
|
|
1974
|
+
return result;
|
|
1975
|
+
},
|
|
1976
|
+
enumerable: false
|
|
1977
|
+
},
|
|
1978
|
+
rgbToAnsi: {
|
|
1979
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
1980
|
+
enumerable: false
|
|
1981
|
+
},
|
|
1982
|
+
hexToAnsi: {
|
|
1983
|
+
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
1984
|
+
enumerable: false
|
|
1985
|
+
}
|
|
1986
|
+
});
|
|
1987
|
+
return styles;
|
|
1988
|
+
}
|
|
1989
|
+
var ansiStyles = assembleStyles();
|
|
1990
|
+
var ansi_styles_default = ansiStyles;
|
|
1991
|
+
|
|
1992
|
+
// node_modules/chalk/source/vendor/supports-color/index.js
|
|
1993
|
+
import process2 from "node:process";
|
|
1994
|
+
import os from "node:os";
|
|
1995
|
+
import tty from "node:tty";
|
|
1996
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2.argv) {
|
|
1997
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
1998
|
+
const position = argv.indexOf(prefix + flag);
|
|
1999
|
+
const terminatorPosition = argv.indexOf("--");
|
|
2000
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
2001
|
+
}
|
|
2002
|
+
var { env } = process2;
|
|
2003
|
+
var flagForceColor;
|
|
2004
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
2005
|
+
flagForceColor = 0;
|
|
2006
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
2007
|
+
flagForceColor = 1;
|
|
2008
|
+
}
|
|
2009
|
+
function envForceColor() {
|
|
2010
|
+
if ("FORCE_COLOR" in env) {
|
|
2011
|
+
if (env.FORCE_COLOR === "true") {
|
|
2012
|
+
return 1;
|
|
2013
|
+
}
|
|
2014
|
+
if (env.FORCE_COLOR === "false") {
|
|
2015
|
+
return 0;
|
|
2016
|
+
}
|
|
2017
|
+
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
function translateLevel(level) {
|
|
2021
|
+
if (level === 0) {
|
|
2022
|
+
return false;
|
|
2023
|
+
}
|
|
2024
|
+
return {
|
|
2025
|
+
level,
|
|
2026
|
+
hasBasic: true,
|
|
2027
|
+
has256: level >= 2,
|
|
2028
|
+
has16m: level >= 3
|
|
2029
|
+
};
|
|
2030
|
+
}
|
|
2031
|
+
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
2032
|
+
const noFlagForceColor = envForceColor();
|
|
2033
|
+
if (noFlagForceColor !== undefined) {
|
|
2034
|
+
flagForceColor = noFlagForceColor;
|
|
2035
|
+
}
|
|
2036
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
2037
|
+
if (forceColor === 0) {
|
|
2038
|
+
return 0;
|
|
2039
|
+
}
|
|
2040
|
+
if (sniffFlags) {
|
|
2041
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
2042
|
+
return 3;
|
|
2043
|
+
}
|
|
2044
|
+
if (hasFlag("color=256")) {
|
|
2045
|
+
return 2;
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
2049
|
+
return 1;
|
|
2050
|
+
}
|
|
2051
|
+
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
2052
|
+
return 0;
|
|
2053
|
+
}
|
|
2054
|
+
const min = forceColor || 0;
|
|
2055
|
+
if (env.TERM === "dumb") {
|
|
2056
|
+
return min;
|
|
2057
|
+
}
|
|
2058
|
+
if (process2.platform === "win32") {
|
|
2059
|
+
const osRelease = os.release().split(".");
|
|
2060
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
2061
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
2062
|
+
}
|
|
2063
|
+
return 1;
|
|
2064
|
+
}
|
|
2065
|
+
if ("CI" in env) {
|
|
2066
|
+
if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => (key in env))) {
|
|
2067
|
+
return 3;
|
|
2068
|
+
}
|
|
2069
|
+
if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => (sign in env)) || env.CI_NAME === "codeship") {
|
|
2070
|
+
return 1;
|
|
2071
|
+
}
|
|
2072
|
+
return min;
|
|
2073
|
+
}
|
|
2074
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
2075
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
2076
|
+
}
|
|
2077
|
+
if (env.COLORTERM === "truecolor") {
|
|
2078
|
+
return 3;
|
|
2079
|
+
}
|
|
2080
|
+
if (env.TERM === "xterm-kitty") {
|
|
2081
|
+
return 3;
|
|
2082
|
+
}
|
|
2083
|
+
if (env.TERM === "xterm-ghostty") {
|
|
2084
|
+
return 3;
|
|
2085
|
+
}
|
|
2086
|
+
if (env.TERM === "wezterm") {
|
|
2087
|
+
return 3;
|
|
2088
|
+
}
|
|
2089
|
+
if ("TERM_PROGRAM" in env) {
|
|
2090
|
+
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
2091
|
+
switch (env.TERM_PROGRAM) {
|
|
2092
|
+
case "iTerm.app": {
|
|
2093
|
+
return version >= 3 ? 3 : 2;
|
|
2094
|
+
}
|
|
2095
|
+
case "Apple_Terminal": {
|
|
2096
|
+
return 2;
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
2101
|
+
return 2;
|
|
2102
|
+
}
|
|
2103
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
2104
|
+
return 1;
|
|
2105
|
+
}
|
|
2106
|
+
if ("COLORTERM" in env) {
|
|
2107
|
+
return 1;
|
|
2108
|
+
}
|
|
2109
|
+
return min;
|
|
2110
|
+
}
|
|
2111
|
+
function createSupportsColor(stream, options = {}) {
|
|
2112
|
+
const level = _supportsColor(stream, {
|
|
2113
|
+
streamIsTTY: stream && stream.isTTY,
|
|
2114
|
+
...options
|
|
2115
|
+
});
|
|
2116
|
+
return translateLevel(level);
|
|
2117
|
+
}
|
|
2118
|
+
var supportsColor = {
|
|
2119
|
+
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
|
2120
|
+
stderr: createSupportsColor({ isTTY: tty.isatty(2) })
|
|
2121
|
+
};
|
|
2122
|
+
var supports_color_default = supportsColor;
|
|
2123
|
+
|
|
2124
|
+
// node_modules/chalk/source/utilities.js
|
|
2125
|
+
function stringReplaceAll(string, substring, replacer) {
|
|
2126
|
+
let index = string.indexOf(substring);
|
|
2127
|
+
if (index === -1) {
|
|
2128
|
+
return string;
|
|
2129
|
+
}
|
|
2130
|
+
const substringLength = substring.length;
|
|
2131
|
+
let endIndex = 0;
|
|
2132
|
+
let returnValue = "";
|
|
2133
|
+
do {
|
|
2134
|
+
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
2135
|
+
endIndex = index + substringLength;
|
|
2136
|
+
index = string.indexOf(substring, endIndex);
|
|
2137
|
+
} while (index !== -1);
|
|
2138
|
+
returnValue += string.slice(endIndex);
|
|
2139
|
+
return returnValue;
|
|
2140
|
+
}
|
|
2141
|
+
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
2142
|
+
let endIndex = 0;
|
|
2143
|
+
let returnValue = "";
|
|
2144
|
+
do {
|
|
2145
|
+
const gotCR = string[index - 1] === "\r";
|
|
2146
|
+
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? `\r
|
|
2147
|
+
` : `
|
|
2148
|
+
`) + postfix;
|
|
2149
|
+
endIndex = index + 1;
|
|
2150
|
+
index = string.indexOf(`
|
|
2151
|
+
`, endIndex);
|
|
2152
|
+
} while (index !== -1);
|
|
2153
|
+
returnValue += string.slice(endIndex);
|
|
2154
|
+
return returnValue;
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
// node_modules/chalk/source/index.js
|
|
2158
|
+
var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
|
|
2159
|
+
var GENERATOR = Symbol("GENERATOR");
|
|
2160
|
+
var STYLER = Symbol("STYLER");
|
|
2161
|
+
var IS_EMPTY = Symbol("IS_EMPTY");
|
|
2162
|
+
var levelMapping = [
|
|
2163
|
+
"ansi",
|
|
2164
|
+
"ansi",
|
|
2165
|
+
"ansi256",
|
|
2166
|
+
"ansi16m"
|
|
2167
|
+
];
|
|
2168
|
+
var styles2 = Object.create(null);
|
|
2169
|
+
var applyOptions = (object, options = {}) => {
|
|
2170
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
2171
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
2172
|
+
}
|
|
2173
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
2174
|
+
object.level = options.level === undefined ? colorLevel : options.level;
|
|
2175
|
+
};
|
|
2176
|
+
var chalkFactory = (options) => {
|
|
2177
|
+
const chalk = (...strings) => strings.join(" ");
|
|
2178
|
+
applyOptions(chalk, options);
|
|
2179
|
+
Object.setPrototypeOf(chalk, createChalk.prototype);
|
|
2180
|
+
return chalk;
|
|
2181
|
+
};
|
|
2182
|
+
function createChalk(options) {
|
|
2183
|
+
return chalkFactory(options);
|
|
2184
|
+
}
|
|
2185
|
+
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
2186
|
+
for (const [styleName, style] of Object.entries(ansi_styles_default)) {
|
|
2187
|
+
styles2[styleName] = {
|
|
2188
|
+
get() {
|
|
2189
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
2190
|
+
Object.defineProperty(this, styleName, { value: builder });
|
|
2191
|
+
return builder;
|
|
2192
|
+
}
|
|
2193
|
+
};
|
|
2194
|
+
}
|
|
2195
|
+
styles2.visible = {
|
|
2196
|
+
get() {
|
|
2197
|
+
const builder = createBuilder(this, this[STYLER], true);
|
|
2198
|
+
Object.defineProperty(this, "visible", { value: builder });
|
|
2199
|
+
return builder;
|
|
2200
|
+
}
|
|
2201
|
+
};
|
|
2202
|
+
var getModelAnsi = (model, level, type, ...arguments_) => {
|
|
2203
|
+
if (model === "rgb") {
|
|
2204
|
+
if (level === "ansi16m") {
|
|
2205
|
+
return ansi_styles_default[type].ansi16m(...arguments_);
|
|
2206
|
+
}
|
|
2207
|
+
if (level === "ansi256") {
|
|
2208
|
+
return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
|
|
2209
|
+
}
|
|
2210
|
+
return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
|
|
2211
|
+
}
|
|
2212
|
+
if (model === "hex") {
|
|
2213
|
+
return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
|
|
2214
|
+
}
|
|
2215
|
+
return ansi_styles_default[type][model](...arguments_);
|
|
2216
|
+
};
|
|
2217
|
+
var usedModels = ["rgb", "hex", "ansi256"];
|
|
2218
|
+
for (const model of usedModels) {
|
|
2219
|
+
styles2[model] = {
|
|
2220
|
+
get() {
|
|
2221
|
+
const { level } = this;
|
|
2222
|
+
return function(...arguments_) {
|
|
2223
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
|
2224
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
2225
|
+
};
|
|
2226
|
+
}
|
|
2227
|
+
};
|
|
2228
|
+
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
2229
|
+
styles2[bgModel] = {
|
|
2230
|
+
get() {
|
|
2231
|
+
const { level } = this;
|
|
2232
|
+
return function(...arguments_) {
|
|
2233
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
|
|
2234
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
2235
|
+
};
|
|
2236
|
+
}
|
|
2237
|
+
};
|
|
2238
|
+
}
|
|
2239
|
+
var proto = Object.defineProperties(() => {}, {
|
|
2240
|
+
...styles2,
|
|
2241
|
+
level: {
|
|
2242
|
+
enumerable: true,
|
|
2243
|
+
get() {
|
|
2244
|
+
return this[GENERATOR].level;
|
|
2245
|
+
},
|
|
2246
|
+
set(level) {
|
|
2247
|
+
this[GENERATOR].level = level;
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
});
|
|
2251
|
+
var createStyler = (open, close, parent) => {
|
|
2252
|
+
let openAll;
|
|
2253
|
+
let closeAll;
|
|
2254
|
+
if (parent === undefined) {
|
|
2255
|
+
openAll = open;
|
|
2256
|
+
closeAll = close;
|
|
2257
|
+
} else {
|
|
2258
|
+
openAll = parent.openAll + open;
|
|
2259
|
+
closeAll = close + parent.closeAll;
|
|
2260
|
+
}
|
|
2261
|
+
return {
|
|
2262
|
+
open,
|
|
2263
|
+
close,
|
|
2264
|
+
openAll,
|
|
2265
|
+
closeAll,
|
|
2266
|
+
parent
|
|
2267
|
+
};
|
|
2268
|
+
};
|
|
2269
|
+
var createBuilder = (self, _styler, _isEmpty) => {
|
|
2270
|
+
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
2271
|
+
Object.setPrototypeOf(builder, proto);
|
|
2272
|
+
builder[GENERATOR] = self;
|
|
2273
|
+
builder[STYLER] = _styler;
|
|
2274
|
+
builder[IS_EMPTY] = _isEmpty;
|
|
2275
|
+
return builder;
|
|
2276
|
+
};
|
|
2277
|
+
var applyStyle = (self, string) => {
|
|
2278
|
+
if (self.level <= 0 || !string) {
|
|
2279
|
+
return self[IS_EMPTY] ? "" : string;
|
|
2280
|
+
}
|
|
2281
|
+
let styler = self[STYLER];
|
|
2282
|
+
if (styler === undefined) {
|
|
2283
|
+
return string;
|
|
2284
|
+
}
|
|
2285
|
+
const { openAll, closeAll } = styler;
|
|
2286
|
+
if (string.includes("\x1B")) {
|
|
2287
|
+
while (styler !== undefined) {
|
|
2288
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
2289
|
+
styler = styler.parent;
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
const lfIndex = string.indexOf(`
|
|
2293
|
+
`);
|
|
2294
|
+
if (lfIndex !== -1) {
|
|
2295
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
2296
|
+
}
|
|
2297
|
+
return openAll + string + closeAll;
|
|
2298
|
+
};
|
|
2299
|
+
Object.defineProperties(createChalk.prototype, styles2);
|
|
2300
|
+
var chalk = createChalk();
|
|
2301
|
+
var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
2302
|
+
var source_default = chalk;
|
|
2303
|
+
|
|
2304
|
+
// node_modules/figlet/dist/node-figlet.mjs
|
|
2305
|
+
import * as fs from "fs";
|
|
2306
|
+
import * as path from "path";
|
|
2307
|
+
|
|
2308
|
+
// node_modules/figlet/dist/figlet.mjs
|
|
2309
|
+
var LAYOUT = {
|
|
2310
|
+
FULL_WIDTH: 0,
|
|
2311
|
+
FITTING: 1,
|
|
2312
|
+
SMUSHING: 2,
|
|
2313
|
+
CONTROLLED_SMUSHING: 3
|
|
2314
|
+
};
|
|
2315
|
+
|
|
2316
|
+
class FigletFont {
|
|
2317
|
+
constructor() {
|
|
2318
|
+
this.comment = "";
|
|
2319
|
+
this.numChars = 0;
|
|
2320
|
+
this.options = {};
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
var fontList = [
|
|
2324
|
+
"1Row",
|
|
2325
|
+
"3-D",
|
|
2326
|
+
"3D Diagonal",
|
|
2327
|
+
"3D-ASCII",
|
|
2328
|
+
"3x5",
|
|
2329
|
+
"4Max",
|
|
2330
|
+
"5 Line Oblique",
|
|
2331
|
+
"AMC 3 Line",
|
|
2332
|
+
"AMC 3 Liv1",
|
|
2333
|
+
"AMC AAA01",
|
|
2334
|
+
"AMC Neko",
|
|
2335
|
+
"AMC Razor",
|
|
2336
|
+
"AMC Razor2",
|
|
2337
|
+
"AMC Slash",
|
|
2338
|
+
"AMC Slider",
|
|
2339
|
+
"AMC Thin",
|
|
2340
|
+
"AMC Tubes",
|
|
2341
|
+
"AMC Untitled",
|
|
2342
|
+
"ANSI Regular",
|
|
2343
|
+
"ANSI Shadow",
|
|
2344
|
+
"ANSI-Compact",
|
|
2345
|
+
"ASCII 12",
|
|
2346
|
+
"ASCII 9",
|
|
2347
|
+
"ASCII New Roman",
|
|
2348
|
+
"Acrobatic",
|
|
2349
|
+
"Alligator",
|
|
2350
|
+
"Alligator2",
|
|
2351
|
+
"Alpha",
|
|
2352
|
+
"Alphabet",
|
|
2353
|
+
"Arrows",
|
|
2354
|
+
"Avatar",
|
|
2355
|
+
"B1FF",
|
|
2356
|
+
"Babyface Lame",
|
|
2357
|
+
"Babyface Leet",
|
|
2358
|
+
"Banner",
|
|
2359
|
+
"Banner3-D",
|
|
2360
|
+
"Banner3",
|
|
2361
|
+
"Banner4",
|
|
2362
|
+
"Barbwire",
|
|
2363
|
+
"Basic",
|
|
2364
|
+
"Bear",
|
|
2365
|
+
"Bell",
|
|
2366
|
+
"Benjamin",
|
|
2367
|
+
"Big ASCII 12",
|
|
2368
|
+
"Big ASCII 9",
|
|
2369
|
+
"Big Chief",
|
|
2370
|
+
"Big Money-ne",
|
|
2371
|
+
"Big Money-nw",
|
|
2372
|
+
"Big Money-se",
|
|
2373
|
+
"Big Money-sw",
|
|
2374
|
+
"Big Mono 12",
|
|
2375
|
+
"Big Mono 9",
|
|
2376
|
+
"Big",
|
|
2377
|
+
"Bigfig",
|
|
2378
|
+
"Binary",
|
|
2379
|
+
"Block",
|
|
2380
|
+
"Blocks",
|
|
2381
|
+
"Bloody",
|
|
2382
|
+
"BlurVision ASCII",
|
|
2383
|
+
"Bolger",
|
|
2384
|
+
"Braced",
|
|
2385
|
+
"Bright",
|
|
2386
|
+
"Broadway KB",
|
|
2387
|
+
"Broadway",
|
|
2388
|
+
"Bubble",
|
|
2389
|
+
"Bulbhead",
|
|
2390
|
+
"Caligraphy",
|
|
2391
|
+
"Caligraphy2",
|
|
2392
|
+
"Calvin S",
|
|
2393
|
+
"Cards",
|
|
2394
|
+
"Catwalk",
|
|
2395
|
+
"Chiseled",
|
|
2396
|
+
"Chunky",
|
|
2397
|
+
"Circle",
|
|
2398
|
+
"Coinstak",
|
|
2399
|
+
"Cola",
|
|
2400
|
+
"Colossal",
|
|
2401
|
+
"Computer",
|
|
2402
|
+
"Contessa",
|
|
2403
|
+
"Contrast",
|
|
2404
|
+
"Cosmike",
|
|
2405
|
+
"Cosmike2",
|
|
2406
|
+
"Crawford",
|
|
2407
|
+
"Crawford2",
|
|
2408
|
+
"Crazy",
|
|
2409
|
+
"Cricket",
|
|
2410
|
+
"Cursive",
|
|
2411
|
+
"Cyberlarge",
|
|
2412
|
+
"Cybermedium",
|
|
2413
|
+
"Cybersmall",
|
|
2414
|
+
"Cygnet",
|
|
2415
|
+
"DANC4",
|
|
2416
|
+
"DOS Rebel",
|
|
2417
|
+
"DWhistled",
|
|
2418
|
+
"Dancing Font",
|
|
2419
|
+
"Decimal",
|
|
2420
|
+
"Def Leppard",
|
|
2421
|
+
"Delta Corps Priest 1",
|
|
2422
|
+
"DiamFont",
|
|
2423
|
+
"Diamond",
|
|
2424
|
+
"Diet Cola",
|
|
2425
|
+
"Digital",
|
|
2426
|
+
"Doh",
|
|
2427
|
+
"Doom",
|
|
2428
|
+
"Dot Matrix",
|
|
2429
|
+
"Double Shorts",
|
|
2430
|
+
"Double",
|
|
2431
|
+
"Dr Pepper",
|
|
2432
|
+
"Efti Chess",
|
|
2433
|
+
"Efti Font",
|
|
2434
|
+
"Efti Italic",
|
|
2435
|
+
"Efti Piti",
|
|
2436
|
+
"Efti Robot",
|
|
2437
|
+
"Efti Wall",
|
|
2438
|
+
"Efti Water",
|
|
2439
|
+
"Electronic",
|
|
2440
|
+
"Elite",
|
|
2441
|
+
"Emboss 2",
|
|
2442
|
+
"Emboss",
|
|
2443
|
+
"Epic",
|
|
2444
|
+
"Fender",
|
|
2445
|
+
"Filter",
|
|
2446
|
+
"Fire Font-k",
|
|
2447
|
+
"Fire Font-s",
|
|
2448
|
+
"Flipped",
|
|
2449
|
+
"Flower Power",
|
|
2450
|
+
"Four Tops",
|
|
2451
|
+
"Fraktur",
|
|
2452
|
+
"Fun Face",
|
|
2453
|
+
"Fun Faces",
|
|
2454
|
+
"Future",
|
|
2455
|
+
"Fuzzy",
|
|
2456
|
+
"Georgi16",
|
|
2457
|
+
"Georgia11",
|
|
2458
|
+
"Ghost",
|
|
2459
|
+
"Ghoulish",
|
|
2460
|
+
"Glenyn",
|
|
2461
|
+
"Goofy",
|
|
2462
|
+
"Gothic",
|
|
2463
|
+
"Graceful",
|
|
2464
|
+
"Gradient",
|
|
2465
|
+
"Graffiti",
|
|
2466
|
+
"Greek",
|
|
2467
|
+
"Heart Left",
|
|
2468
|
+
"Heart Right",
|
|
2469
|
+
"Henry 3D",
|
|
2470
|
+
"Hex",
|
|
2471
|
+
"Hieroglyphs",
|
|
2472
|
+
"Hollywood",
|
|
2473
|
+
"Horizontal Left",
|
|
2474
|
+
"Horizontal Right",
|
|
2475
|
+
"ICL-1900",
|
|
2476
|
+
"Impossible",
|
|
2477
|
+
"Invita",
|
|
2478
|
+
"Isometric1",
|
|
2479
|
+
"Isometric2",
|
|
2480
|
+
"Isometric3",
|
|
2481
|
+
"Isometric4",
|
|
2482
|
+
"Italic",
|
|
2483
|
+
"Ivrit",
|
|
2484
|
+
"JS Block Letters",
|
|
2485
|
+
"JS Bracket Letters",
|
|
2486
|
+
"JS Capital Curves",
|
|
2487
|
+
"JS Cursive",
|
|
2488
|
+
"JS Stick Letters",
|
|
2489
|
+
"Jacky",
|
|
2490
|
+
"Jazmine",
|
|
2491
|
+
"Jerusalem",
|
|
2492
|
+
"Katakana",
|
|
2493
|
+
"Kban",
|
|
2494
|
+
"Keyboard",
|
|
2495
|
+
"Knob",
|
|
2496
|
+
"Konto Slant",
|
|
2497
|
+
"Konto",
|
|
2498
|
+
"LCD",
|
|
2499
|
+
"Larry 3D 2",
|
|
2500
|
+
"Larry 3D",
|
|
2501
|
+
"Lean",
|
|
2502
|
+
"Letter",
|
|
2503
|
+
"Letters",
|
|
2504
|
+
"Lil Devil",
|
|
2505
|
+
"Line Blocks",
|
|
2506
|
+
"Linux",
|
|
2507
|
+
"Lockergnome",
|
|
2508
|
+
"Madrid",
|
|
2509
|
+
"Marquee",
|
|
2510
|
+
"Maxfour",
|
|
2511
|
+
"Merlin1",
|
|
2512
|
+
"Merlin2",
|
|
2513
|
+
"Mike",
|
|
2514
|
+
"Mini",
|
|
2515
|
+
"Mirror",
|
|
2516
|
+
"Mnemonic",
|
|
2517
|
+
"Modular",
|
|
2518
|
+
"Mono 12",
|
|
2519
|
+
"Mono 9",
|
|
2520
|
+
"Morse",
|
|
2521
|
+
"Morse2",
|
|
2522
|
+
"Moscow",
|
|
2523
|
+
"Mshebrew210",
|
|
2524
|
+
"Muzzle",
|
|
2525
|
+
"NScript",
|
|
2526
|
+
"NT Greek",
|
|
2527
|
+
"NV Script",
|
|
2528
|
+
"Nancyj-Fancy",
|
|
2529
|
+
"Nancyj-Improved",
|
|
2530
|
+
"Nancyj-Underlined",
|
|
2531
|
+
"Nancyj",
|
|
2532
|
+
"Nipples",
|
|
2533
|
+
"O8",
|
|
2534
|
+
"OS2",
|
|
2535
|
+
"Octal",
|
|
2536
|
+
"Ogre",
|
|
2537
|
+
"Old Banner",
|
|
2538
|
+
"Pagga",
|
|
2539
|
+
"Patorjk's Cheese",
|
|
2540
|
+
"Patorjk-HeX",
|
|
2541
|
+
"Pawp",
|
|
2542
|
+
"Peaks Slant",
|
|
2543
|
+
"Peaks",
|
|
2544
|
+
"Pebbles",
|
|
2545
|
+
"Pepper",
|
|
2546
|
+
"Poison",
|
|
2547
|
+
"Puffy",
|
|
2548
|
+
"Puzzle",
|
|
2549
|
+
"Pyramid",
|
|
2550
|
+
"Rammstein",
|
|
2551
|
+
"Rebel",
|
|
2552
|
+
"Rectangles",
|
|
2553
|
+
"Red Phoenix",
|
|
2554
|
+
"Relief",
|
|
2555
|
+
"Relief2",
|
|
2556
|
+
"Reverse",
|
|
2557
|
+
"Roman",
|
|
2558
|
+
"Rot13",
|
|
2559
|
+
"Rotated",
|
|
2560
|
+
"Rounded",
|
|
2561
|
+
"Rowan Cap",
|
|
2562
|
+
"Rozzo",
|
|
2563
|
+
"RubiFont",
|
|
2564
|
+
"Runic",
|
|
2565
|
+
"Runyc",
|
|
2566
|
+
"S Blood",
|
|
2567
|
+
"SL Script",
|
|
2568
|
+
"Santa Clara",
|
|
2569
|
+
"Script",
|
|
2570
|
+
"Serifcap",
|
|
2571
|
+
"Shaded Blocky",
|
|
2572
|
+
"Shadow",
|
|
2573
|
+
"Shimrod",
|
|
2574
|
+
"Short",
|
|
2575
|
+
"Slant Relief",
|
|
2576
|
+
"Slant",
|
|
2577
|
+
"Slide",
|
|
2578
|
+
"Small ASCII 12",
|
|
2579
|
+
"Small ASCII 9",
|
|
2580
|
+
"Small Block",
|
|
2581
|
+
"Small Braille",
|
|
2582
|
+
"Small Caps",
|
|
2583
|
+
"Small Isometric1",
|
|
2584
|
+
"Small Keyboard",
|
|
2585
|
+
"Small Mono 12",
|
|
2586
|
+
"Small Mono 9",
|
|
2587
|
+
"Small Poison",
|
|
2588
|
+
"Small Script",
|
|
2589
|
+
"Small Shadow",
|
|
2590
|
+
"Small Slant",
|
|
2591
|
+
"Small Tengwar",
|
|
2592
|
+
"Small",
|
|
2593
|
+
"Soft",
|
|
2594
|
+
"Speed",
|
|
2595
|
+
"Spliff",
|
|
2596
|
+
"Stacey",
|
|
2597
|
+
"Stampate",
|
|
2598
|
+
"Stampatello",
|
|
2599
|
+
"Standard",
|
|
2600
|
+
"Star Strips",
|
|
2601
|
+
"Star Wars",
|
|
2602
|
+
"Stellar",
|
|
2603
|
+
"Stforek",
|
|
2604
|
+
"Stick Letters",
|
|
2605
|
+
"Stop",
|
|
2606
|
+
"Straight",
|
|
2607
|
+
"Stronger Than All",
|
|
2608
|
+
"Sub-Zero",
|
|
2609
|
+
"Swamp Land",
|
|
2610
|
+
"Swan",
|
|
2611
|
+
"Sweet",
|
|
2612
|
+
"THIS",
|
|
2613
|
+
"Tanja",
|
|
2614
|
+
"Tengwar",
|
|
2615
|
+
"Term",
|
|
2616
|
+
"Terrace",
|
|
2617
|
+
"Test1",
|
|
2618
|
+
"The Edge",
|
|
2619
|
+
"Thick",
|
|
2620
|
+
"Thin",
|
|
2621
|
+
"Thorned",
|
|
2622
|
+
"Three Point",
|
|
2623
|
+
"Ticks Slant",
|
|
2624
|
+
"Ticks",
|
|
2625
|
+
"Tiles",
|
|
2626
|
+
"Tinker-Toy",
|
|
2627
|
+
"Tmplr",
|
|
2628
|
+
"Tombstone",
|
|
2629
|
+
"Train",
|
|
2630
|
+
"Trek",
|
|
2631
|
+
"Tsalagi",
|
|
2632
|
+
"Tubular",
|
|
2633
|
+
"Twisted",
|
|
2634
|
+
"Two Point",
|
|
2635
|
+
"USA Flag",
|
|
2636
|
+
"Univers",
|
|
2637
|
+
"Upside Down Text",
|
|
2638
|
+
"Varsity",
|
|
2639
|
+
"Wavescape",
|
|
2640
|
+
"Wavy",
|
|
2641
|
+
"Weird",
|
|
2642
|
+
"Wet Letter",
|
|
2643
|
+
"Whimsy",
|
|
2644
|
+
"WideTerm",
|
|
2645
|
+
"Wow",
|
|
2646
|
+
"miniwi"
|
|
2647
|
+
];
|
|
2648
|
+
function escapeRegExpChar(char) {
|
|
2649
|
+
const specialChars = /[.*+?^${}()|[\]\\]/;
|
|
2650
|
+
return specialChars.test(char) ? "\\" + char : char;
|
|
2651
|
+
}
|
|
2652
|
+
var figlet = (() => {
|
|
2653
|
+
const { FULL_WIDTH = 0, FITTING, SMUSHING, CONTROLLED_SMUSHING } = LAYOUT;
|
|
2654
|
+
const figFonts = {};
|
|
2655
|
+
const figDefaults = {
|
|
2656
|
+
font: "Standard",
|
|
2657
|
+
fontPath: "./fonts",
|
|
2658
|
+
fetchFontIfMissing: true
|
|
2659
|
+
};
|
|
2660
|
+
function removeEndChar(line, lineNum, fontHeight) {
|
|
2661
|
+
const endChar = escapeRegExpChar(line.trim().slice(-1)) || "@";
|
|
2662
|
+
const endCharRegEx = lineNum === fontHeight - 1 ? new RegExp(endChar + endChar + "?\\s*$") : new RegExp(endChar + "\\s*$");
|
|
2663
|
+
return line.replace(endCharRegEx, "");
|
|
2664
|
+
}
|
|
2665
|
+
function getSmushingRules(oldLayout = -1, newLayout = null) {
|
|
2666
|
+
let rules = {};
|
|
2667
|
+
let val;
|
|
2668
|
+
let codes = [
|
|
2669
|
+
[16384, "vLayout", SMUSHING],
|
|
2670
|
+
[8192, "vLayout", FITTING],
|
|
2671
|
+
[4096, "vRule5", true],
|
|
2672
|
+
[2048, "vRule4", true],
|
|
2673
|
+
[1024, "vRule3", true],
|
|
2674
|
+
[512, "vRule2", true],
|
|
2675
|
+
[256, "vRule1", true],
|
|
2676
|
+
[128, "hLayout", SMUSHING],
|
|
2677
|
+
[64, "hLayout", FITTING],
|
|
2678
|
+
[32, "hRule6", true],
|
|
2679
|
+
[16, "hRule5", true],
|
|
2680
|
+
[8, "hRule4", true],
|
|
2681
|
+
[4, "hRule3", true],
|
|
2682
|
+
[2, "hRule2", true],
|
|
2683
|
+
[1, "hRule1", true]
|
|
2684
|
+
];
|
|
2685
|
+
val = newLayout !== null ? newLayout : oldLayout;
|
|
2686
|
+
for (const [code, rule, value] of codes) {
|
|
2687
|
+
if (val >= code) {
|
|
2688
|
+
val -= code;
|
|
2689
|
+
if (rules[rule] === undefined) {
|
|
2690
|
+
rules[rule] = value;
|
|
2691
|
+
}
|
|
2692
|
+
} else if (rule !== "vLayout" && rule !== "hLayout") {
|
|
2693
|
+
rules[rule] = false;
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
if (typeof rules["hLayout"] === "undefined") {
|
|
2697
|
+
if (oldLayout === 0) {
|
|
2698
|
+
rules["hLayout"] = FITTING;
|
|
2699
|
+
} else if (oldLayout === -1) {
|
|
2700
|
+
rules["hLayout"] = FULL_WIDTH;
|
|
2701
|
+
} else {
|
|
2702
|
+
if (rules["hRule1"] || rules["hRule2"] || rules["hRule3"] || rules["hRule4"] || rules["hRule5"] || rules["hRule6"]) {
|
|
2703
|
+
rules["hLayout"] = CONTROLLED_SMUSHING;
|
|
2704
|
+
} else {
|
|
2705
|
+
rules["hLayout"] = SMUSHING;
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
} else if (rules["hLayout"] === SMUSHING) {
|
|
2709
|
+
if (rules["hRule1"] || rules["hRule2"] || rules["hRule3"] || rules["hRule4"] || rules["hRule5"] || rules["hRule6"]) {
|
|
2710
|
+
rules["hLayout"] = CONTROLLED_SMUSHING;
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
if (typeof rules["vLayout"] === "undefined") {
|
|
2714
|
+
if (rules["vRule1"] || rules["vRule2"] || rules["vRule3"] || rules["vRule4"] || rules["vRule5"]) {
|
|
2715
|
+
rules["vLayout"] = CONTROLLED_SMUSHING;
|
|
2716
|
+
} else {
|
|
2717
|
+
rules["vLayout"] = FULL_WIDTH;
|
|
2718
|
+
}
|
|
2719
|
+
} else if (rules["vLayout"] === SMUSHING) {
|
|
2720
|
+
if (rules["vRule1"] || rules["vRule2"] || rules["vRule3"] || rules["vRule4"] || rules["vRule5"]) {
|
|
2721
|
+
rules["vLayout"] = CONTROLLED_SMUSHING;
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
return rules;
|
|
2725
|
+
}
|
|
2726
|
+
function hRule1_Smush(ch1, ch2, hardBlank = "") {
|
|
2727
|
+
if (ch1 === ch2 && ch1 !== hardBlank) {
|
|
2728
|
+
return ch1;
|
|
2729
|
+
}
|
|
2730
|
+
return false;
|
|
2731
|
+
}
|
|
2732
|
+
function hRule2_Smush(ch1, ch2) {
|
|
2733
|
+
let rule2Str = "|/\\[]{}()<>";
|
|
2734
|
+
if (ch1 === "_") {
|
|
2735
|
+
if (rule2Str.indexOf(ch2) !== -1) {
|
|
2736
|
+
return ch2;
|
|
2737
|
+
}
|
|
2738
|
+
} else if (ch2 === "_") {
|
|
2739
|
+
if (rule2Str.indexOf(ch1) !== -1) {
|
|
2740
|
+
return ch1;
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
return false;
|
|
2744
|
+
}
|
|
2745
|
+
function hRule3_Smush(ch1, ch2) {
|
|
2746
|
+
let rule3Classes = "| /\\ [] {} () <>";
|
|
2747
|
+
let r3_pos1 = rule3Classes.indexOf(ch1);
|
|
2748
|
+
let r3_pos2 = rule3Classes.indexOf(ch2);
|
|
2749
|
+
if (r3_pos1 !== -1 && r3_pos2 !== -1) {
|
|
2750
|
+
if (r3_pos1 !== r3_pos2 && Math.abs(r3_pos1 - r3_pos2) !== 1) {
|
|
2751
|
+
const startPos = Math.max(r3_pos1, r3_pos2);
|
|
2752
|
+
const endPos = startPos + 1;
|
|
2753
|
+
return rule3Classes.substring(startPos, endPos);
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
return false;
|
|
2757
|
+
}
|
|
2758
|
+
function hRule4_Smush(ch1, ch2) {
|
|
2759
|
+
let rule4Str = "[] {} ()";
|
|
2760
|
+
let r4_pos1 = rule4Str.indexOf(ch1);
|
|
2761
|
+
let r4_pos2 = rule4Str.indexOf(ch2);
|
|
2762
|
+
if (r4_pos1 !== -1 && r4_pos2 !== -1) {
|
|
2763
|
+
if (Math.abs(r4_pos1 - r4_pos2) <= 1) {
|
|
2764
|
+
return "|";
|
|
2765
|
+
}
|
|
2766
|
+
}
|
|
2767
|
+
return false;
|
|
2768
|
+
}
|
|
2769
|
+
function hRule5_Smush(ch1, ch2) {
|
|
2770
|
+
const patterns = {
|
|
2771
|
+
"/\\": "|",
|
|
2772
|
+
"\\/": "Y",
|
|
2773
|
+
"><": "X"
|
|
2774
|
+
};
|
|
2775
|
+
return patterns[ch1 + ch2] || false;
|
|
2776
|
+
}
|
|
2777
|
+
function hRule6_Smush(ch1, ch2, hardBlank = "") {
|
|
2778
|
+
if (ch1 === hardBlank && ch2 === hardBlank) {
|
|
2779
|
+
return hardBlank;
|
|
2780
|
+
}
|
|
2781
|
+
return false;
|
|
2782
|
+
}
|
|
2783
|
+
function vRule1_Smush(ch1, ch2) {
|
|
2784
|
+
if (ch1 === ch2) {
|
|
2785
|
+
return ch1;
|
|
2786
|
+
}
|
|
2787
|
+
return false;
|
|
2788
|
+
}
|
|
2789
|
+
function vRule2_Smush(ch1, ch2) {
|
|
2790
|
+
return hRule2_Smush(ch1, ch2);
|
|
2791
|
+
}
|
|
2792
|
+
function vRule3_Smush(ch1, ch2) {
|
|
2793
|
+
return hRule3_Smush(ch1, ch2);
|
|
2794
|
+
}
|
|
2795
|
+
function vRule4_Smush(ch1, ch2) {
|
|
2796
|
+
if (ch1 === "-" && ch2 === "_" || ch1 === "_" && ch2 === "-") {
|
|
2797
|
+
return "=";
|
|
2798
|
+
}
|
|
2799
|
+
return false;
|
|
2800
|
+
}
|
|
2801
|
+
function vRule5_Smush(ch1, ch2) {
|
|
2802
|
+
if (ch1 === "|" && ch2 === "|") {
|
|
2803
|
+
return "|";
|
|
2804
|
+
}
|
|
2805
|
+
return false;
|
|
2806
|
+
}
|
|
2807
|
+
function uni_Smush(ch1, ch2, hardBlank) {
|
|
2808
|
+
if (ch2 === " " || ch2 === "") {
|
|
2809
|
+
return ch1;
|
|
2810
|
+
} else if (ch2 === hardBlank && ch1 !== " ") {
|
|
2811
|
+
return ch1;
|
|
2812
|
+
} else {
|
|
2813
|
+
return ch2;
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
function canVerticalSmush(txt1, txt2, opts) {
|
|
2817
|
+
if (opts.fittingRules && opts.fittingRules.vLayout === FULL_WIDTH) {
|
|
2818
|
+
return "invalid";
|
|
2819
|
+
}
|
|
2820
|
+
let ii, len = Math.min(txt1.length, txt2.length), ch1, ch2, endSmush = false, validSmush;
|
|
2821
|
+
if (len === 0) {
|
|
2822
|
+
return "invalid";
|
|
2823
|
+
}
|
|
2824
|
+
for (ii = 0;ii < len; ii++) {
|
|
2825
|
+
ch1 = txt1.substring(ii, ii + 1);
|
|
2826
|
+
ch2 = txt2.substring(ii, ii + 1);
|
|
2827
|
+
if (ch1 !== " " && ch2 !== " ") {
|
|
2828
|
+
if (opts.fittingRules && opts.fittingRules.vLayout === FITTING) {
|
|
2829
|
+
return "invalid";
|
|
2830
|
+
} else if (opts.fittingRules && opts.fittingRules.vLayout === SMUSHING) {
|
|
2831
|
+
return "end";
|
|
2832
|
+
} else {
|
|
2833
|
+
if (vRule5_Smush(ch1, ch2)) {
|
|
2834
|
+
endSmush = endSmush || false;
|
|
2835
|
+
continue;
|
|
2836
|
+
}
|
|
2837
|
+
validSmush = false;
|
|
2838
|
+
validSmush = opts.fittingRules && opts.fittingRules.vRule1 ? vRule1_Smush(ch1, ch2) : validSmush;
|
|
2839
|
+
validSmush = !validSmush && opts.fittingRules && opts.fittingRules.vRule2 ? vRule2_Smush(ch1, ch2) : validSmush;
|
|
2840
|
+
validSmush = !validSmush && opts.fittingRules && opts.fittingRules.vRule3 ? vRule3_Smush(ch1, ch2) : validSmush;
|
|
2841
|
+
validSmush = !validSmush && opts.fittingRules && opts.fittingRules.vRule4 ? vRule4_Smush(ch1, ch2) : validSmush;
|
|
2842
|
+
endSmush = true;
|
|
2843
|
+
if (!validSmush) {
|
|
2844
|
+
return "invalid";
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
if (endSmush) {
|
|
2850
|
+
return "end";
|
|
2851
|
+
} else {
|
|
2852
|
+
return "valid";
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
function getVerticalSmushDist(lines1, lines2, opts) {
|
|
2856
|
+
let maxDist = lines1.length;
|
|
2857
|
+
let len1 = lines1.length;
|
|
2858
|
+
let subLines1, subLines2, slen;
|
|
2859
|
+
let curDist = 1;
|
|
2860
|
+
let ii, ret, result;
|
|
2861
|
+
while (curDist <= maxDist) {
|
|
2862
|
+
subLines1 = lines1.slice(Math.max(0, len1 - curDist), len1);
|
|
2863
|
+
subLines2 = lines2.slice(0, Math.min(maxDist, curDist));
|
|
2864
|
+
slen = subLines2.length;
|
|
2865
|
+
result = "";
|
|
2866
|
+
for (ii = 0;ii < slen; ii++) {
|
|
2867
|
+
ret = canVerticalSmush(subLines1[ii], subLines2[ii], opts);
|
|
2868
|
+
if (ret === "end") {
|
|
2869
|
+
result = ret;
|
|
2870
|
+
} else if (ret === "invalid") {
|
|
2871
|
+
result = ret;
|
|
2872
|
+
break;
|
|
2873
|
+
} else {
|
|
2874
|
+
if (result === "") {
|
|
2875
|
+
result = "valid";
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
}
|
|
2879
|
+
if (result === "invalid") {
|
|
2880
|
+
curDist--;
|
|
2881
|
+
break;
|
|
2882
|
+
}
|
|
2883
|
+
if (result === "end") {
|
|
2884
|
+
break;
|
|
2885
|
+
}
|
|
2886
|
+
if (result === "valid") {
|
|
2887
|
+
curDist++;
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
return Math.min(maxDist, curDist);
|
|
2891
|
+
}
|
|
2892
|
+
function verticallySmushLines(line1, line2, opts) {
|
|
2893
|
+
let ii, len = Math.min(line1.length, line2.length);
|
|
2894
|
+
let ch1, ch2, result = "", validSmush;
|
|
2895
|
+
const fittingRules = opts.fittingRules || {};
|
|
2896
|
+
for (ii = 0;ii < len; ii++) {
|
|
2897
|
+
ch1 = line1.substring(ii, ii + 1);
|
|
2898
|
+
ch2 = line2.substring(ii, ii + 1);
|
|
2899
|
+
if (ch1 !== " " && ch2 !== " ") {
|
|
2900
|
+
if (fittingRules.vLayout === FITTING) {
|
|
2901
|
+
result += uni_Smush(ch1, ch2);
|
|
2902
|
+
} else if (fittingRules.vLayout === SMUSHING) {
|
|
2903
|
+
result += uni_Smush(ch1, ch2);
|
|
2904
|
+
} else {
|
|
2905
|
+
validSmush = false;
|
|
2906
|
+
validSmush = fittingRules.vRule5 ? vRule5_Smush(ch1, ch2) : validSmush;
|
|
2907
|
+
validSmush = !validSmush && fittingRules.vRule1 ? vRule1_Smush(ch1, ch2) : validSmush;
|
|
2908
|
+
validSmush = !validSmush && fittingRules.vRule2 ? vRule2_Smush(ch1, ch2) : validSmush;
|
|
2909
|
+
validSmush = !validSmush && fittingRules.vRule3 ? vRule3_Smush(ch1, ch2) : validSmush;
|
|
2910
|
+
validSmush = !validSmush && fittingRules.vRule4 ? vRule4_Smush(ch1, ch2) : validSmush;
|
|
2911
|
+
result += validSmush;
|
|
2912
|
+
}
|
|
2913
|
+
} else {
|
|
2914
|
+
result += uni_Smush(ch1, ch2);
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
return result;
|
|
2918
|
+
}
|
|
2919
|
+
function verticalSmush(lines1, lines2, overlap, opts) {
|
|
2920
|
+
let len1 = lines1.length;
|
|
2921
|
+
let len2 = lines2.length;
|
|
2922
|
+
let piece1 = lines1.slice(0, Math.max(0, len1 - overlap));
|
|
2923
|
+
let piece2_1 = lines1.slice(Math.max(0, len1 - overlap), len1);
|
|
2924
|
+
let piece2_2 = lines2.slice(0, Math.min(overlap, len2));
|
|
2925
|
+
let ii, len, line, piece2 = [], piece3;
|
|
2926
|
+
len = piece2_1.length;
|
|
2927
|
+
for (ii = 0;ii < len; ii++) {
|
|
2928
|
+
if (ii >= len2) {
|
|
2929
|
+
line = piece2_1[ii];
|
|
2930
|
+
} else {
|
|
2931
|
+
line = verticallySmushLines(piece2_1[ii], piece2_2[ii], opts);
|
|
2932
|
+
}
|
|
2933
|
+
piece2.push(line);
|
|
2934
|
+
}
|
|
2935
|
+
piece3 = lines2.slice(Math.min(overlap, len2), len2);
|
|
2936
|
+
return [...piece1, ...piece2, ...piece3];
|
|
2937
|
+
}
|
|
2938
|
+
function padLines(lines, numSpaces) {
|
|
2939
|
+
const padding = " ".repeat(numSpaces);
|
|
2940
|
+
return lines.map((line) => line + padding);
|
|
2941
|
+
}
|
|
2942
|
+
function smushVerticalFigLines(output, lines, opts) {
|
|
2943
|
+
let len1 = output[0].length;
|
|
2944
|
+
let len2 = lines[0].length;
|
|
2945
|
+
let overlap;
|
|
2946
|
+
if (len1 > len2) {
|
|
2947
|
+
lines = padLines(lines, len1 - len2);
|
|
2948
|
+
} else if (len2 > len1) {
|
|
2949
|
+
output = padLines(output, len2 - len1);
|
|
2950
|
+
}
|
|
2951
|
+
overlap = getVerticalSmushDist(output, lines, opts);
|
|
2952
|
+
return verticalSmush(output, lines, overlap, opts);
|
|
2953
|
+
}
|
|
2954
|
+
function getHorizontalSmushLength(txt1, txt2, opts) {
|
|
2955
|
+
const fittingRules = opts.fittingRules || {};
|
|
2956
|
+
if (fittingRules.hLayout === FULL_WIDTH) {
|
|
2957
|
+
return 0;
|
|
2958
|
+
}
|
|
2959
|
+
let ii, len1 = txt1.length, len2 = txt2.length;
|
|
2960
|
+
let maxDist = len1;
|
|
2961
|
+
let curDist = 1;
|
|
2962
|
+
let breakAfter = false;
|
|
2963
|
+
let seg1, seg2, ch1, ch2;
|
|
2964
|
+
if (len1 === 0) {
|
|
2965
|
+
return 0;
|
|
2966
|
+
}
|
|
2967
|
+
distCal:
|
|
2968
|
+
while (curDist <= maxDist) {
|
|
2969
|
+
const seg1StartPos = len1 - curDist;
|
|
2970
|
+
seg1 = txt1.substring(seg1StartPos, seg1StartPos + curDist);
|
|
2971
|
+
seg2 = txt2.substring(0, Math.min(curDist, len2));
|
|
2972
|
+
for (ii = 0;ii < Math.min(curDist, len2); ii++) {
|
|
2973
|
+
ch1 = seg1.substring(ii, ii + 1);
|
|
2974
|
+
ch2 = seg2.substring(ii, ii + 1);
|
|
2975
|
+
if (ch1 !== " " && ch2 !== " ") {
|
|
2976
|
+
if (fittingRules.hLayout === FITTING) {
|
|
2977
|
+
curDist = curDist - 1;
|
|
2978
|
+
break distCal;
|
|
2979
|
+
} else if (fittingRules.hLayout === SMUSHING) {
|
|
2980
|
+
if (ch1 === opts.hardBlank || ch2 === opts.hardBlank) {
|
|
2981
|
+
curDist = curDist - 1;
|
|
2982
|
+
}
|
|
2983
|
+
break distCal;
|
|
2984
|
+
} else {
|
|
2985
|
+
breakAfter = true;
|
|
2986
|
+
const validSmush = fittingRules.hRule1 && hRule1_Smush(ch1, ch2, opts.hardBlank) || fittingRules.hRule2 && hRule2_Smush(ch1, ch2) || fittingRules.hRule3 && hRule3_Smush(ch1, ch2) || fittingRules.hRule4 && hRule4_Smush(ch1, ch2) || fittingRules.hRule5 && hRule5_Smush(ch1, ch2) || fittingRules.hRule6 && hRule6_Smush(ch1, ch2, opts.hardBlank);
|
|
2987
|
+
if (!validSmush) {
|
|
2988
|
+
curDist = curDist - 1;
|
|
2989
|
+
break distCal;
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
if (breakAfter) {
|
|
2995
|
+
break;
|
|
2996
|
+
}
|
|
2997
|
+
curDist++;
|
|
2998
|
+
}
|
|
2999
|
+
return Math.min(maxDist, curDist);
|
|
3000
|
+
}
|
|
3001
|
+
function horizontalSmush(textBlock1, textBlock2, overlap, opts) {
|
|
3002
|
+
let ii, jj, outputFig = [], overlapStart, piece1, piece2, piece3, len1, len2, txt1, txt2;
|
|
3003
|
+
const fittingRules = opts.fittingRules || {};
|
|
3004
|
+
if (typeof opts.height !== "number") {
|
|
3005
|
+
throw new Error("height is not defined.");
|
|
3006
|
+
}
|
|
3007
|
+
for (ii = 0;ii < opts.height; ii++) {
|
|
3008
|
+
txt1 = textBlock1[ii];
|
|
3009
|
+
txt2 = textBlock2[ii];
|
|
3010
|
+
len1 = txt1.length;
|
|
3011
|
+
len2 = txt2.length;
|
|
3012
|
+
overlapStart = len1 - overlap;
|
|
3013
|
+
piece1 = txt1.slice(0, Math.max(0, overlapStart));
|
|
3014
|
+
piece2 = "";
|
|
3015
|
+
const seg1StartPos = Math.max(0, len1 - overlap);
|
|
3016
|
+
let seg1 = txt1.substring(seg1StartPos, seg1StartPos + overlap);
|
|
3017
|
+
let seg2 = txt2.substring(0, Math.min(overlap, len2));
|
|
3018
|
+
for (jj = 0;jj < overlap; jj++) {
|
|
3019
|
+
let ch1 = jj < len1 ? seg1.substring(jj, jj + 1) : " ";
|
|
3020
|
+
let ch2 = jj < len2 ? seg2.substring(jj, jj + 1) : " ";
|
|
3021
|
+
if (ch1 !== " " && ch2 !== " ") {
|
|
3022
|
+
if (fittingRules.hLayout === FITTING || fittingRules.hLayout === SMUSHING) {
|
|
3023
|
+
piece2 += uni_Smush(ch1, ch2, opts.hardBlank);
|
|
3024
|
+
} else {
|
|
3025
|
+
const nextCh = fittingRules.hRule1 && hRule1_Smush(ch1, ch2, opts.hardBlank) || fittingRules.hRule2 && hRule2_Smush(ch1, ch2) || fittingRules.hRule3 && hRule3_Smush(ch1, ch2) || fittingRules.hRule4 && hRule4_Smush(ch1, ch2) || fittingRules.hRule5 && hRule5_Smush(ch1, ch2) || fittingRules.hRule6 && hRule6_Smush(ch1, ch2, opts.hardBlank) || uni_Smush(ch1, ch2, opts.hardBlank);
|
|
3026
|
+
piece2 += nextCh;
|
|
3027
|
+
}
|
|
3028
|
+
} else {
|
|
3029
|
+
piece2 += uni_Smush(ch1, ch2, opts.hardBlank);
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
if (overlap >= len2) {
|
|
3033
|
+
piece3 = "";
|
|
3034
|
+
} else {
|
|
3035
|
+
piece3 = txt2.substring(overlap, overlap + Math.max(0, len2 - overlap));
|
|
3036
|
+
}
|
|
3037
|
+
outputFig[ii] = piece1 + piece2 + piece3;
|
|
3038
|
+
}
|
|
3039
|
+
return outputFig;
|
|
3040
|
+
}
|
|
3041
|
+
function newFigChar(len) {
|
|
3042
|
+
return new Array(len).fill("");
|
|
3043
|
+
}
|
|
3044
|
+
const figLinesWidth = function(textLines) {
|
|
3045
|
+
return Math.max(...textLines.map((line) => line.length));
|
|
3046
|
+
};
|
|
3047
|
+
function joinFigArray(array, len, opts) {
|
|
3048
|
+
return array.reduce(function(acc, data) {
|
|
3049
|
+
return horizontalSmush(acc, data.fig, data.overlap || 0, opts);
|
|
3050
|
+
}, newFigChar(len));
|
|
3051
|
+
}
|
|
3052
|
+
function breakWord(figChars, len, opts) {
|
|
3053
|
+
for (let i = figChars.length - 1;i > 0; i--) {
|
|
3054
|
+
const w = joinFigArray(figChars.slice(0, i), len, opts);
|
|
3055
|
+
if (figLinesWidth(w) <= opts.width) {
|
|
3056
|
+
return {
|
|
3057
|
+
outputFigText: w,
|
|
3058
|
+
chars: figChars.slice(i)
|
|
3059
|
+
};
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
return { outputFigText: newFigChar(len), chars: figChars };
|
|
3063
|
+
}
|
|
3064
|
+
function generateFigTextLines(txt, figChars, opts) {
|
|
3065
|
+
let charIndex, figChar, overlap = 0, row, outputFigText, len, height = opts.height, outputFigLines = [], maxWidth, nextFigChars = {
|
|
3066
|
+
chars: [],
|
|
3067
|
+
overlap
|
|
3068
|
+
}, figWords = [], char, isSpace, textFigWord, textFigLine, tmpBreak;
|
|
3069
|
+
if (typeof height !== "number") {
|
|
3070
|
+
throw new Error("height is not defined.");
|
|
3071
|
+
}
|
|
3072
|
+
outputFigText = newFigChar(height);
|
|
3073
|
+
const fittingRules = opts.fittingRules || {};
|
|
3074
|
+
if (opts.printDirection === 1) {
|
|
3075
|
+
txt = txt.split("").reverse().join("");
|
|
3076
|
+
}
|
|
3077
|
+
len = txt.length;
|
|
3078
|
+
for (charIndex = 0;charIndex < len; charIndex++) {
|
|
3079
|
+
char = txt.substring(charIndex, charIndex + 1);
|
|
3080
|
+
isSpace = char.match(/\s/);
|
|
3081
|
+
figChar = figChars[char.charCodeAt(0)];
|
|
3082
|
+
textFigLine = null;
|
|
3083
|
+
if (figChar) {
|
|
3084
|
+
if (fittingRules.hLayout !== FULL_WIDTH) {
|
|
3085
|
+
overlap = 1e4;
|
|
3086
|
+
for (row = 0;row < height; row++) {
|
|
3087
|
+
overlap = Math.min(overlap, getHorizontalSmushLength(outputFigText[row], figChar[row], opts));
|
|
3088
|
+
}
|
|
3089
|
+
overlap = overlap === 1e4 ? 0 : overlap;
|
|
3090
|
+
}
|
|
3091
|
+
if (opts.width > 0) {
|
|
3092
|
+
if (opts.whitespaceBreak) {
|
|
3093
|
+
textFigWord = joinFigArray(nextFigChars.chars.concat([
|
|
3094
|
+
{
|
|
3095
|
+
fig: figChar,
|
|
3096
|
+
overlap
|
|
3097
|
+
}
|
|
3098
|
+
]), height, opts);
|
|
3099
|
+
textFigLine = joinFigArray(figWords.concat([
|
|
3100
|
+
{
|
|
3101
|
+
fig: textFigWord,
|
|
3102
|
+
overlap: nextFigChars.overlap
|
|
3103
|
+
}
|
|
3104
|
+
]), height, opts);
|
|
3105
|
+
maxWidth = figLinesWidth(textFigLine);
|
|
3106
|
+
} else {
|
|
3107
|
+
textFigLine = horizontalSmush(outputFigText, figChar, overlap, opts);
|
|
3108
|
+
maxWidth = figLinesWidth(textFigLine);
|
|
3109
|
+
}
|
|
3110
|
+
if (maxWidth >= opts.width && charIndex > 0) {
|
|
3111
|
+
if (opts.whitespaceBreak) {
|
|
3112
|
+
outputFigText = joinFigArray(figWords.slice(0, -1), height, opts);
|
|
3113
|
+
if (figWords.length > 1) {
|
|
3114
|
+
outputFigLines.push(outputFigText);
|
|
3115
|
+
outputFigText = newFigChar(height);
|
|
3116
|
+
}
|
|
3117
|
+
figWords = [];
|
|
3118
|
+
} else {
|
|
3119
|
+
outputFigLines.push(outputFigText);
|
|
3120
|
+
outputFigText = newFigChar(height);
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
if (opts.width > 0 && opts.whitespaceBreak) {
|
|
3125
|
+
if (!isSpace || charIndex === len - 1) {
|
|
3126
|
+
nextFigChars.chars.push({ fig: figChar, overlap });
|
|
3127
|
+
}
|
|
3128
|
+
if (isSpace || charIndex === len - 1) {
|
|
3129
|
+
tmpBreak = null;
|
|
3130
|
+
while (true) {
|
|
3131
|
+
textFigLine = joinFigArray(nextFigChars.chars, height, opts);
|
|
3132
|
+
maxWidth = figLinesWidth(textFigLine);
|
|
3133
|
+
if (maxWidth >= opts.width) {
|
|
3134
|
+
tmpBreak = breakWord(nextFigChars.chars, height, opts);
|
|
3135
|
+
nextFigChars = { chars: tmpBreak.chars };
|
|
3136
|
+
outputFigLines.push(tmpBreak.outputFigText);
|
|
3137
|
+
} else {
|
|
3138
|
+
break;
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
3141
|
+
if (maxWidth > 0) {
|
|
3142
|
+
if (tmpBreak) {
|
|
3143
|
+
figWords.push({ fig: textFigLine, overlap: 1 });
|
|
3144
|
+
} else {
|
|
3145
|
+
figWords.push({
|
|
3146
|
+
fig: textFigLine,
|
|
3147
|
+
overlap: nextFigChars.overlap
|
|
3148
|
+
});
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
if (isSpace) {
|
|
3152
|
+
figWords.push({ fig: figChar, overlap });
|
|
3153
|
+
outputFigText = newFigChar(height);
|
|
3154
|
+
}
|
|
3155
|
+
if (charIndex === len - 1) {
|
|
3156
|
+
outputFigText = joinFigArray(figWords, height, opts);
|
|
3157
|
+
}
|
|
3158
|
+
nextFigChars = {
|
|
3159
|
+
chars: [],
|
|
3160
|
+
overlap
|
|
3161
|
+
};
|
|
3162
|
+
continue;
|
|
3163
|
+
}
|
|
3164
|
+
}
|
|
3165
|
+
outputFigText = horizontalSmush(outputFigText, figChar, overlap, opts);
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
if (figLinesWidth(outputFigText) > 0) {
|
|
3169
|
+
outputFigLines.push(outputFigText);
|
|
3170
|
+
}
|
|
3171
|
+
if (!opts.showHardBlanks) {
|
|
3172
|
+
outputFigLines.forEach(function(outputFigText2) {
|
|
3173
|
+
len = outputFigText2.length;
|
|
3174
|
+
for (row = 0;row < len; row++) {
|
|
3175
|
+
outputFigText2[row] = outputFigText2[row].replace(new RegExp("\\" + opts.hardBlank, "g"), " ");
|
|
3176
|
+
}
|
|
3177
|
+
});
|
|
3178
|
+
}
|
|
3179
|
+
if (txt === "" && outputFigLines.length === 0) {
|
|
3180
|
+
outputFigLines.push(new Array(height).fill(""));
|
|
3181
|
+
}
|
|
3182
|
+
return outputFigLines;
|
|
3183
|
+
}
|
|
3184
|
+
const getHorizontalFittingRules = function(layout, options) {
|
|
3185
|
+
let params;
|
|
3186
|
+
const fittingRules = options.fittingRules || {};
|
|
3187
|
+
if (layout === "default") {
|
|
3188
|
+
params = {
|
|
3189
|
+
hLayout: fittingRules.hLayout,
|
|
3190
|
+
hRule1: fittingRules.hRule1,
|
|
3191
|
+
hRule2: fittingRules.hRule2,
|
|
3192
|
+
hRule3: fittingRules.hRule3,
|
|
3193
|
+
hRule4: fittingRules.hRule4,
|
|
3194
|
+
hRule5: fittingRules.hRule5,
|
|
3195
|
+
hRule6: fittingRules.hRule6
|
|
3196
|
+
};
|
|
3197
|
+
} else if (layout === "full") {
|
|
3198
|
+
params = {
|
|
3199
|
+
hLayout: FULL_WIDTH,
|
|
3200
|
+
hRule1: false,
|
|
3201
|
+
hRule2: false,
|
|
3202
|
+
hRule3: false,
|
|
3203
|
+
hRule4: false,
|
|
3204
|
+
hRule5: false,
|
|
3205
|
+
hRule6: false
|
|
3206
|
+
};
|
|
3207
|
+
} else if (layout === "fitted") {
|
|
3208
|
+
params = {
|
|
3209
|
+
hLayout: FITTING,
|
|
3210
|
+
hRule1: false,
|
|
3211
|
+
hRule2: false,
|
|
3212
|
+
hRule3: false,
|
|
3213
|
+
hRule4: false,
|
|
3214
|
+
hRule5: false,
|
|
3215
|
+
hRule6: false
|
|
3216
|
+
};
|
|
3217
|
+
} else if (layout === "controlled smushing") {
|
|
3218
|
+
params = {
|
|
3219
|
+
hLayout: CONTROLLED_SMUSHING,
|
|
3220
|
+
hRule1: true,
|
|
3221
|
+
hRule2: true,
|
|
3222
|
+
hRule3: true,
|
|
3223
|
+
hRule4: true,
|
|
3224
|
+
hRule5: true,
|
|
3225
|
+
hRule6: true
|
|
3226
|
+
};
|
|
3227
|
+
} else if (layout === "universal smushing") {
|
|
3228
|
+
params = {
|
|
3229
|
+
hLayout: SMUSHING,
|
|
3230
|
+
hRule1: false,
|
|
3231
|
+
hRule2: false,
|
|
3232
|
+
hRule3: false,
|
|
3233
|
+
hRule4: false,
|
|
3234
|
+
hRule5: false,
|
|
3235
|
+
hRule6: false
|
|
3236
|
+
};
|
|
3237
|
+
} else {
|
|
3238
|
+
return;
|
|
3239
|
+
}
|
|
3240
|
+
return params;
|
|
3241
|
+
};
|
|
3242
|
+
const getVerticalFittingRules = function(layout, options) {
|
|
3243
|
+
let params = {};
|
|
3244
|
+
const fittingRules = options.fittingRules || {};
|
|
3245
|
+
if (layout === "default") {
|
|
3246
|
+
params = {
|
|
3247
|
+
vLayout: fittingRules.vLayout,
|
|
3248
|
+
vRule1: fittingRules.vRule1,
|
|
3249
|
+
vRule2: fittingRules.vRule2,
|
|
3250
|
+
vRule3: fittingRules.vRule3,
|
|
3251
|
+
vRule4: fittingRules.vRule4,
|
|
3252
|
+
vRule5: fittingRules.vRule5
|
|
3253
|
+
};
|
|
3254
|
+
} else if (layout === "full") {
|
|
3255
|
+
params = {
|
|
3256
|
+
vLayout: FULL_WIDTH,
|
|
3257
|
+
vRule1: false,
|
|
3258
|
+
vRule2: false,
|
|
3259
|
+
vRule3: false,
|
|
3260
|
+
vRule4: false,
|
|
3261
|
+
vRule5: false
|
|
3262
|
+
};
|
|
3263
|
+
} else if (layout === "fitted") {
|
|
3264
|
+
params = {
|
|
3265
|
+
vLayout: FITTING,
|
|
3266
|
+
vRule1: false,
|
|
3267
|
+
vRule2: false,
|
|
3268
|
+
vRule3: false,
|
|
3269
|
+
vRule4: false,
|
|
3270
|
+
vRule5: false
|
|
3271
|
+
};
|
|
3272
|
+
} else if (layout === "controlled smushing") {
|
|
3273
|
+
params = {
|
|
3274
|
+
vLayout: CONTROLLED_SMUSHING,
|
|
3275
|
+
vRule1: true,
|
|
3276
|
+
vRule2: true,
|
|
3277
|
+
vRule3: true,
|
|
3278
|
+
vRule4: true,
|
|
3279
|
+
vRule5: true
|
|
3280
|
+
};
|
|
3281
|
+
} else if (layout === "universal smushing") {
|
|
3282
|
+
params = {
|
|
3283
|
+
vLayout: SMUSHING,
|
|
3284
|
+
vRule1: false,
|
|
3285
|
+
vRule2: false,
|
|
3286
|
+
vRule3: false,
|
|
3287
|
+
vRule4: false,
|
|
3288
|
+
vRule5: false
|
|
3289
|
+
};
|
|
3290
|
+
} else {
|
|
3291
|
+
return;
|
|
3292
|
+
}
|
|
3293
|
+
return params;
|
|
3294
|
+
};
|
|
3295
|
+
const generateText = function(fontName, options, txt) {
|
|
3296
|
+
txt = txt.replace(/\r\n/g, `
|
|
3297
|
+
`).replace(/\r/g, `
|
|
3298
|
+
`);
|
|
3299
|
+
let lines = txt.split(`
|
|
3300
|
+
`);
|
|
3301
|
+
let figLines = [];
|
|
3302
|
+
let ii, len, output;
|
|
3303
|
+
len = lines.length;
|
|
3304
|
+
for (ii = 0;ii < len; ii++) {
|
|
3305
|
+
figLines = figLines.concat(generateFigTextLines(lines[ii], figFonts[fontName], options));
|
|
3306
|
+
}
|
|
3307
|
+
len = figLines.length;
|
|
3308
|
+
output = figLines[0];
|
|
3309
|
+
for (ii = 1;ii < len; ii++) {
|
|
3310
|
+
output = smushVerticalFigLines(output, figLines[ii], options);
|
|
3311
|
+
}
|
|
3312
|
+
return output ? output.join(`
|
|
3313
|
+
`) : "";
|
|
3314
|
+
};
|
|
3315
|
+
function _reworkFontOpts(fontMeta, options) {
|
|
3316
|
+
let myOpts;
|
|
3317
|
+
if (typeof structuredClone !== "undefined") {
|
|
3318
|
+
myOpts = structuredClone(fontMeta);
|
|
3319
|
+
} else {
|
|
3320
|
+
myOpts = JSON.parse(JSON.stringify(fontMeta));
|
|
3321
|
+
}
|
|
3322
|
+
myOpts.showHardBlanks = options.showHardBlanks || false;
|
|
3323
|
+
myOpts.width = options.width || -1;
|
|
3324
|
+
myOpts.whitespaceBreak = options.whitespaceBreak || false;
|
|
3325
|
+
if (options.horizontalLayout) {
|
|
3326
|
+
const params = getHorizontalFittingRules(options.horizontalLayout, fontMeta);
|
|
3327
|
+
if (params) {
|
|
3328
|
+
Object.assign(myOpts.fittingRules, params);
|
|
3329
|
+
}
|
|
3330
|
+
}
|
|
3331
|
+
if (options.verticalLayout) {
|
|
3332
|
+
const params = getVerticalFittingRules(options.verticalLayout, fontMeta);
|
|
3333
|
+
if (params) {
|
|
3334
|
+
Object.assign(myOpts.fittingRules, params);
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
myOpts.printDirection = options.printDirection !== null && options.printDirection !== undefined ? options.printDirection : fontMeta.printDirection;
|
|
3338
|
+
return myOpts;
|
|
3339
|
+
}
|
|
3340
|
+
const me = async function(txt, optionsOrFontOrCallback, callback) {
|
|
3341
|
+
return me.text(txt, optionsOrFontOrCallback, callback);
|
|
3342
|
+
};
|
|
3343
|
+
me.text = async function(txt, optionsOrFontOrCallback, callback) {
|
|
3344
|
+
txt = txt + "";
|
|
3345
|
+
let options, next;
|
|
3346
|
+
if (typeof optionsOrFontOrCallback === "function") {
|
|
3347
|
+
next = optionsOrFontOrCallback;
|
|
3348
|
+
options = { font: figDefaults.font };
|
|
3349
|
+
} else if (typeof optionsOrFontOrCallback === "string") {
|
|
3350
|
+
options = { font: optionsOrFontOrCallback };
|
|
3351
|
+
next = callback;
|
|
3352
|
+
} else if (optionsOrFontOrCallback) {
|
|
3353
|
+
options = optionsOrFontOrCallback;
|
|
3354
|
+
next = callback;
|
|
3355
|
+
} else {
|
|
3356
|
+
options = { font: figDefaults.font };
|
|
3357
|
+
next = callback;
|
|
3358
|
+
}
|
|
3359
|
+
const fontName = options.font || figDefaults.font;
|
|
3360
|
+
try {
|
|
3361
|
+
const fontOpts = await me.loadFont(fontName);
|
|
3362
|
+
const generatedTxt = fontOpts ? generateText(fontName, _reworkFontOpts(fontOpts, options), txt) : "";
|
|
3363
|
+
if (next) {
|
|
3364
|
+
next(null, generatedTxt);
|
|
3365
|
+
}
|
|
3366
|
+
return generatedTxt;
|
|
3367
|
+
} catch (err) {
|
|
3368
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
3369
|
+
if (next) {
|
|
3370
|
+
next(error);
|
|
3371
|
+
return "";
|
|
3372
|
+
}
|
|
3373
|
+
throw error;
|
|
3374
|
+
}
|
|
3375
|
+
};
|
|
3376
|
+
me.textSync = function(txt, options) {
|
|
3377
|
+
txt = txt + "";
|
|
3378
|
+
if (typeof options === "string") {
|
|
3379
|
+
options = { font: options };
|
|
3380
|
+
} else {
|
|
3381
|
+
options = options || {};
|
|
3382
|
+
}
|
|
3383
|
+
const fontName = options.font || figDefaults.font;
|
|
3384
|
+
let fontOpts = _reworkFontOpts(me.loadFontSync(fontName), options);
|
|
3385
|
+
return generateText(fontName, fontOpts, txt);
|
|
3386
|
+
};
|
|
3387
|
+
me.metadata = async function(fontName, callback) {
|
|
3388
|
+
fontName = fontName + "";
|
|
3389
|
+
try {
|
|
3390
|
+
const fontOpts = await me.loadFont(fontName);
|
|
3391
|
+
if (!fontOpts) {
|
|
3392
|
+
throw new Error("Error loading font.");
|
|
3393
|
+
}
|
|
3394
|
+
const font = figFonts[fontName] || {};
|
|
3395
|
+
const result = [fontOpts, font.comment || ""];
|
|
3396
|
+
if (callback) {
|
|
3397
|
+
callback(null, fontOpts, font.comment);
|
|
3398
|
+
}
|
|
3399
|
+
return result;
|
|
3400
|
+
} catch (err) {
|
|
3401
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
3402
|
+
if (callback) {
|
|
3403
|
+
callback(error);
|
|
3404
|
+
return null;
|
|
3405
|
+
}
|
|
3406
|
+
throw error;
|
|
3407
|
+
}
|
|
3408
|
+
};
|
|
3409
|
+
me.defaults = function(opts) {
|
|
3410
|
+
if (opts && typeof opts === "object") {
|
|
3411
|
+
Object.assign(figDefaults, opts);
|
|
3412
|
+
}
|
|
3413
|
+
if (typeof structuredClone !== "undefined") {
|
|
3414
|
+
return structuredClone(figDefaults);
|
|
3415
|
+
} else {
|
|
3416
|
+
return JSON.parse(JSON.stringify(figDefaults));
|
|
3417
|
+
}
|
|
3418
|
+
};
|
|
3419
|
+
me.parseFont = function(fontName, data, override = true) {
|
|
3420
|
+
if (figFonts[fontName] && !override) {
|
|
3421
|
+
return figFonts[fontName].options;
|
|
3422
|
+
}
|
|
3423
|
+
data = data.replace(/\r\n/g, `
|
|
3424
|
+
`).replace(/\r/g, `
|
|
3425
|
+
`);
|
|
3426
|
+
const font = new FigletFont;
|
|
3427
|
+
const lines = data.split(`
|
|
3428
|
+
`);
|
|
3429
|
+
const headerLine = lines.shift();
|
|
3430
|
+
if (!headerLine) {
|
|
3431
|
+
throw new Error("Invalid font file: missing header");
|
|
3432
|
+
}
|
|
3433
|
+
const headerData = headerLine.split(" ");
|
|
3434
|
+
const opts = {
|
|
3435
|
+
hardBlank: headerData[0].substring(5, 6),
|
|
3436
|
+
height: parseInt(headerData[1], 10),
|
|
3437
|
+
baseline: parseInt(headerData[2], 10),
|
|
3438
|
+
maxLength: parseInt(headerData[3], 10),
|
|
3439
|
+
oldLayout: parseInt(headerData[4], 10),
|
|
3440
|
+
numCommentLines: parseInt(headerData[5], 10),
|
|
3441
|
+
printDirection: headerData[6] ? parseInt(headerData[6], 10) : 0,
|
|
3442
|
+
fullLayout: headerData[7] ? parseInt(headerData[7], 10) : null,
|
|
3443
|
+
codeTagCount: headerData[8] ? parseInt(headerData[8], 10) : null
|
|
3444
|
+
};
|
|
3445
|
+
const hardBlank = opts.hardBlank || "";
|
|
3446
|
+
if (hardBlank.length !== 1 || [
|
|
3447
|
+
opts.height,
|
|
3448
|
+
opts.baseline,
|
|
3449
|
+
opts.maxLength,
|
|
3450
|
+
opts.oldLayout,
|
|
3451
|
+
opts.numCommentLines
|
|
3452
|
+
].some((val) => val === null || val === undefined || isNaN(val))) {
|
|
3453
|
+
throw new Error("FIGlet header contains invalid values.");
|
|
3454
|
+
}
|
|
3455
|
+
if (opts.height == null || opts.numCommentLines == null) {
|
|
3456
|
+
throw new Error("FIGlet header contains invalid values.");
|
|
3457
|
+
}
|
|
3458
|
+
opts.fittingRules = getSmushingRules(opts.oldLayout, opts.fullLayout);
|
|
3459
|
+
font.options = opts;
|
|
3460
|
+
const charNums = [];
|
|
3461
|
+
for (let i = 32;i <= 126; i++) {
|
|
3462
|
+
charNums.push(i);
|
|
3463
|
+
}
|
|
3464
|
+
charNums.push(196, 214, 220, 228, 246, 252, 223);
|
|
3465
|
+
if (lines.length < opts.numCommentLines + opts.height * charNums.length) {
|
|
3466
|
+
throw new Error(`FIGlet file is missing data. Line length: ${lines.length}. Comment lines: ${opts.numCommentLines}. Height: ${opts.height}. Num chars: ${charNums.length}.`);
|
|
3467
|
+
}
|
|
3468
|
+
font.comment = lines.splice(0, opts.numCommentLines).join(`
|
|
3469
|
+
`);
|
|
3470
|
+
font.numChars = 0;
|
|
3471
|
+
while (lines.length > 0 && font.numChars < charNums.length) {
|
|
3472
|
+
const cNum = charNums[font.numChars];
|
|
3473
|
+
font[cNum] = lines.splice(0, opts.height);
|
|
3474
|
+
for (let i = 0;i < opts.height; i++) {
|
|
3475
|
+
if (typeof font[cNum][i] === "undefined") {
|
|
3476
|
+
font[cNum][i] = "";
|
|
3477
|
+
} else {
|
|
3478
|
+
font[cNum][i] = removeEndChar(font[cNum][i], i, opts.height);
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3481
|
+
font.numChars++;
|
|
3482
|
+
}
|
|
3483
|
+
while (lines.length > 0) {
|
|
3484
|
+
const cNumLine = lines.shift();
|
|
3485
|
+
if (!cNumLine || cNumLine.trim() === "")
|
|
3486
|
+
break;
|
|
3487
|
+
let cNum = cNumLine.split(" ")[0];
|
|
3488
|
+
let parsedNum;
|
|
3489
|
+
if (/^-?0[xX][0-9a-fA-F]+$/.test(cNum)) {
|
|
3490
|
+
parsedNum = parseInt(cNum, 16);
|
|
3491
|
+
} else if (/^-?0[0-7]+$/.test(cNum)) {
|
|
3492
|
+
parsedNum = parseInt(cNum, 8);
|
|
3493
|
+
} else if (/^-?[0-9]+$/.test(cNum)) {
|
|
3494
|
+
parsedNum = parseInt(cNum, 10);
|
|
3495
|
+
} else {
|
|
3496
|
+
throw new Error(`Error parsing data. Invalid data: ${cNum}`);
|
|
3497
|
+
}
|
|
3498
|
+
if (parsedNum === -1 || parsedNum < -2147483648 || parsedNum > 2147483647) {
|
|
3499
|
+
const msg = parsedNum === -1 ? "The char code -1 is not permitted." : `The char code cannot be ${parsedNum < -2147483648 ? "less than -2147483648" : "greater than 2147483647"}.`;
|
|
3500
|
+
throw new Error(`Error parsing data. ${msg}`);
|
|
3501
|
+
}
|
|
3502
|
+
font[parsedNum] = lines.splice(0, opts.height);
|
|
3503
|
+
for (let i = 0;i < opts.height; i++) {
|
|
3504
|
+
if (typeof font[parsedNum][i] === "undefined") {
|
|
3505
|
+
font[parsedNum][i] = "";
|
|
3506
|
+
} else {
|
|
3507
|
+
font[parsedNum][i] = removeEndChar(font[parsedNum][i], i, opts.height);
|
|
3508
|
+
}
|
|
3509
|
+
}
|
|
3510
|
+
font.numChars++;
|
|
3511
|
+
}
|
|
3512
|
+
figFonts[fontName] = font;
|
|
3513
|
+
return opts;
|
|
3514
|
+
};
|
|
3515
|
+
me.loadedFonts = () => {
|
|
3516
|
+
return Object.keys(figFonts);
|
|
3517
|
+
};
|
|
3518
|
+
me.clearLoadedFonts = () => {
|
|
3519
|
+
Object.keys(figFonts).forEach((key) => {
|
|
3520
|
+
delete figFonts[key];
|
|
3521
|
+
});
|
|
3522
|
+
};
|
|
3523
|
+
me.loadFont = async function(fontName, callback) {
|
|
3524
|
+
if (figFonts[fontName]) {
|
|
3525
|
+
const result = figFonts[fontName].options;
|
|
3526
|
+
if (callback) {
|
|
3527
|
+
callback(null, result);
|
|
3528
|
+
}
|
|
3529
|
+
return Promise.resolve(result);
|
|
3530
|
+
}
|
|
3531
|
+
try {
|
|
3532
|
+
if (!figDefaults.fetchFontIfMissing) {
|
|
3533
|
+
throw new Error(`Font is not loaded: ${fontName}`);
|
|
3534
|
+
}
|
|
3535
|
+
const response = await fetch(`${figDefaults.fontPath}/${fontName}.flf`);
|
|
3536
|
+
if (!response.ok) {
|
|
3537
|
+
throw new Error(`Network response was not ok: ${response.status}`);
|
|
3538
|
+
}
|
|
3539
|
+
const text = await response.text();
|
|
3540
|
+
const result = me.parseFont(fontName, text);
|
|
3541
|
+
if (callback) {
|
|
3542
|
+
callback(null, result);
|
|
3543
|
+
}
|
|
3544
|
+
return result;
|
|
3545
|
+
} catch (error) {
|
|
3546
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
3547
|
+
if (callback) {
|
|
3548
|
+
callback(err);
|
|
3549
|
+
return null;
|
|
3550
|
+
}
|
|
3551
|
+
throw err;
|
|
3552
|
+
}
|
|
3553
|
+
};
|
|
3554
|
+
me.loadFontSync = function(name) {
|
|
3555
|
+
if (figFonts[name]) {
|
|
3556
|
+
return figFonts[name].options;
|
|
3557
|
+
}
|
|
3558
|
+
throw new Error("Synchronous font loading is not implemented for the browser, it will only work for fonts already loaded.");
|
|
3559
|
+
};
|
|
3560
|
+
me.preloadFonts = async function(fonts, callback) {
|
|
3561
|
+
try {
|
|
3562
|
+
for (const name of fonts) {
|
|
3563
|
+
const response = await fetch(`${figDefaults.fontPath}/${name}.flf`);
|
|
3564
|
+
if (!response.ok) {
|
|
3565
|
+
throw new Error(`Failed to preload fonts. Error fetching font: ${name}, status code: ${response.statusText}`);
|
|
3566
|
+
}
|
|
3567
|
+
const data = await response.text();
|
|
3568
|
+
me.parseFont(name, data);
|
|
3569
|
+
}
|
|
3570
|
+
if (callback) {
|
|
3571
|
+
callback();
|
|
3572
|
+
}
|
|
3573
|
+
} catch (error) {
|
|
3574
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
3575
|
+
if (callback) {
|
|
3576
|
+
callback(err);
|
|
3577
|
+
return;
|
|
3578
|
+
}
|
|
3579
|
+
throw error;
|
|
3580
|
+
}
|
|
3581
|
+
};
|
|
3582
|
+
me.fonts = function(callback) {
|
|
3583
|
+
return new Promise(function(resolve, reject) {
|
|
3584
|
+
resolve(fontList);
|
|
3585
|
+
if (callback) {
|
|
3586
|
+
callback(null, fontList);
|
|
3587
|
+
}
|
|
3588
|
+
});
|
|
3589
|
+
};
|
|
3590
|
+
me.fontsSync = function() {
|
|
3591
|
+
return fontList;
|
|
3592
|
+
};
|
|
3593
|
+
me.figFonts = figFonts;
|
|
3594
|
+
return me;
|
|
3595
|
+
})();
|
|
3596
|
+
|
|
3597
|
+
// node_modules/figlet/dist/node-figlet.mjs
|
|
3598
|
+
import { fileURLToPath } from "url";
|
|
3599
|
+
var __filename2 = fileURLToPath(import.meta.url);
|
|
3600
|
+
var __dirname2 = path.dirname(__filename2);
|
|
3601
|
+
var fontPath = path.join(__dirname2, "/../fonts/");
|
|
3602
|
+
var nodeFiglet = figlet;
|
|
3603
|
+
nodeFiglet.defaults({ fontPath });
|
|
3604
|
+
nodeFiglet.loadFont = function(name, callback) {
|
|
3605
|
+
return new Promise((resolve, reject) => {
|
|
3606
|
+
if (nodeFiglet.figFonts[name]) {
|
|
3607
|
+
if (callback) {
|
|
3608
|
+
callback(null, nodeFiglet.figFonts[name].options);
|
|
3609
|
+
}
|
|
3610
|
+
resolve(nodeFiglet.figFonts[name].options);
|
|
3611
|
+
return;
|
|
3612
|
+
}
|
|
3613
|
+
fs.readFile(path.join(nodeFiglet.defaults().fontPath, name + ".flf"), { encoding: "utf-8" }, (err, fontData) => {
|
|
3614
|
+
if (err) {
|
|
3615
|
+
if (callback) {
|
|
3616
|
+
callback(err);
|
|
3617
|
+
}
|
|
3618
|
+
reject(err);
|
|
3619
|
+
return;
|
|
3620
|
+
}
|
|
3621
|
+
fontData = fontData + "";
|
|
3622
|
+
try {
|
|
3623
|
+
const font = nodeFiglet.parseFont(name, fontData);
|
|
3624
|
+
if (callback) {
|
|
3625
|
+
callback(null, font);
|
|
3626
|
+
}
|
|
3627
|
+
resolve(font);
|
|
3628
|
+
} catch (error) {
|
|
3629
|
+
const typedError = error instanceof Error ? error : new Error(String(error));
|
|
3630
|
+
if (callback) {
|
|
3631
|
+
callback(typedError);
|
|
3632
|
+
}
|
|
3633
|
+
reject(typedError);
|
|
3634
|
+
}
|
|
3635
|
+
});
|
|
3636
|
+
});
|
|
3637
|
+
};
|
|
3638
|
+
nodeFiglet.loadFontSync = function(font) {
|
|
3639
|
+
if (nodeFiglet.figFonts[font]) {
|
|
3640
|
+
return nodeFiglet.figFonts[font].options;
|
|
3641
|
+
}
|
|
3642
|
+
const fontData = fs.readFileSync(path.join(nodeFiglet.defaults().fontPath, font + ".flf"), {
|
|
3643
|
+
encoding: "utf-8"
|
|
3644
|
+
}) + "";
|
|
3645
|
+
return nodeFiglet.parseFont(font, fontData);
|
|
3646
|
+
};
|
|
3647
|
+
nodeFiglet.fonts = function(next) {
|
|
3648
|
+
return new Promise((resolve, reject) => {
|
|
3649
|
+
const fontList2 = [];
|
|
3650
|
+
fs.readdir(nodeFiglet.defaults().fontPath, (err, files) => {
|
|
3651
|
+
if (err) {
|
|
3652
|
+
next && next(err);
|
|
3653
|
+
reject(err);
|
|
3654
|
+
return;
|
|
3655
|
+
}
|
|
3656
|
+
files.forEach((file) => {
|
|
3657
|
+
if (/\.flf$/.test(file)) {
|
|
3658
|
+
fontList2.push(file.replace(/\.flf$/, ""));
|
|
3659
|
+
}
|
|
3660
|
+
});
|
|
3661
|
+
next && next(null, fontList2);
|
|
3662
|
+
resolve(fontList2);
|
|
3663
|
+
});
|
|
3664
|
+
});
|
|
3665
|
+
};
|
|
3666
|
+
nodeFiglet.fontsSync = function() {
|
|
3667
|
+
const fontList2 = [];
|
|
3668
|
+
fs.readdirSync(nodeFiglet.defaults().fontPath).forEach((file) => {
|
|
3669
|
+
if (/\.flf$/.test(file)) {
|
|
3670
|
+
fontList2.push(file.replace(/\.flf$/, ""));
|
|
3671
|
+
}
|
|
3672
|
+
});
|
|
3673
|
+
return fontList2;
|
|
3674
|
+
};
|
|
3675
|
+
|
|
3676
|
+
// src/index.ts
|
|
3677
|
+
async function main() {
|
|
3678
|
+
const welcomeText = nodeFiglet.textSync("ops-toolkit", {
|
|
3679
|
+
font: "Standard",
|
|
3680
|
+
horizontalLayout: "default",
|
|
3681
|
+
verticalLayout: "default"
|
|
3682
|
+
});
|
|
3683
|
+
console.log(source_default.cyan(welcomeText));
|
|
3684
|
+
program.name("ops").description("\u5168\u9762\u7684DevOps CLI\u5DE5\u5177\u5305").version("1.0.0");
|
|
3685
|
+
program.option("-d, --debug", "\u542F\u7528\u8C03\u8BD5\u6A21\u5F0F", false);
|
|
3686
|
+
program.option("-v, --verbose", "\u542F\u7528\u8BE6\u7EC6\u65E5\u5FD7", false);
|
|
3687
|
+
program.command("ui", { isDefault: true }).description("\u542F\u52A8\u4EA4\u4E92\u5F0F\u7EC8\u7AEF\u754C\u9762").action(async () => {
|
|
3688
|
+
console.log(source_default.green("\uD83D\uDE80 ops-toolkit CLI\u6B63\u5728\u8FD0\u884C!"));
|
|
3689
|
+
console.log(source_default.blue("\uD83D\uDCCB \u53EF\u7528\u547D\u4EE4:"));
|
|
3690
|
+
console.log(source_default.white(" ops monitor - \u7CFB\u7EDF\u76D1\u63A7"));
|
|
3691
|
+
console.log(source_default.white(" ops logs - \u65E5\u5FD7\u7BA1\u7406"));
|
|
3692
|
+
console.log(source_default.white(" ops deploy - \u90E8\u7F72\u5DE5\u5177"));
|
|
3693
|
+
console.log(source_default.white(" ops system - \u7CFB\u7EDF\u7BA1\u7406"));
|
|
3694
|
+
console.log(source_default.gray(`
|
|
3695
|
+
\uD83D\uDD27 UI\u529F\u80FD\u5373\u5C06\u63A8\u51FA...`));
|
|
3696
|
+
});
|
|
3697
|
+
program.command("monitor").description("\u7CFB\u7EDF\u76D1\u63A7").action(async () => {
|
|
3698
|
+
console.log(source_default.blue("\uD83D\uDCCA \u7CFB\u7EDF\u76D1\u63A7"));
|
|
3699
|
+
console.log(source_default.yellow("\u26A0\uFE0F \u76D1\u63A7\u529F\u80FD\u5373\u5C06\u63A8\u51FA..."));
|
|
3700
|
+
});
|
|
3701
|
+
program.command("logs").description("\u65E5\u5FD7\u7BA1\u7406").action(async () => {
|
|
3702
|
+
console.log(source_default.blue("\uD83D\uDCCB \u65E5\u5FD7\u7BA1\u7406"));
|
|
3703
|
+
console.log(source_default.yellow("\u26A0\uFE0F \u65E5\u5FD7\u7BA1\u7406\u529F\u80FD\u5373\u5C06\u63A8\u51FA..."));
|
|
3704
|
+
});
|
|
3705
|
+
program.command("deploy").description("\u90E8\u7F72\u5DE5\u5177").action(async () => {
|
|
3706
|
+
console.log(source_default.blue("\uD83D\uDE80 \u90E8\u7F72\u5DE5\u5177"));
|
|
3707
|
+
console.log(source_default.yellow("\u26A0\uFE0F \u90E8\u7F72\u529F\u80FD\u5373\u5C06\u63A8\u51FA..."));
|
|
3708
|
+
});
|
|
3709
|
+
program.command("system").description("\u7CFB\u7EDF\u7BA1\u7406").action(async () => {
|
|
3710
|
+
console.log(source_default.blue("\u2699\uFE0F \u7CFB\u7EDF\u7BA1\u7406"));
|
|
3711
|
+
console.log(source_default.yellow("\u26A0\uFE0F \u7CFB\u7EDF\u7BA1\u7406\u529F\u80FD\u5373\u5C06\u63A8\u51FA..."));
|
|
3712
|
+
});
|
|
3713
|
+
program.parse();
|
|
3714
|
+
}
|
|
3715
|
+
process.on("uncaughtException", (error) => {
|
|
3716
|
+
console.error(source_default.red("\u274C \u672A\u6355\u83B7\u5F02\u5E38:"), error);
|
|
3717
|
+
process.exit(1);
|
|
3718
|
+
});
|
|
3719
|
+
process.on("unhandledRejection", (reason, promise) => {
|
|
3720
|
+
console.error(source_default.red("\u274C \u672A\u5904\u7406\u7684Promise\u62D2\u7EDD:"), promise, "\u539F\u56E0:", reason);
|
|
3721
|
+
process.exit(1);
|
|
3722
|
+
});
|
|
3723
|
+
main().catch((error) => {
|
|
3724
|
+
console.error(source_default.red("\u274C \u542F\u52A8\u5E94\u7528\u5931\u8D25:"), error);
|
|
3725
|
+
process.exit(1);
|
|
3726
|
+
});
|