diff-mindustry-bundles 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +45 -0
- package/README.template.md +29 -0
- package/build/index.js +3503 -0
- package/package.json +24 -0
package/build/index.js
ADDED
|
@@ -0,0 +1,3503 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
20
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
for (let key of __getOwnPropNames(mod))
|
|
23
|
+
if (!__hasOwnProp.call(to, key))
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
26
|
+
enumerable: true
|
|
27
|
+
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toCommonJS = (from) => {
|
|
33
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
34
|
+
if (entry)
|
|
35
|
+
return entry;
|
|
36
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
37
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
38
|
+
for (var key of __getOwnPropNames(from))
|
|
39
|
+
if (!__hasOwnProp.call(entry, key))
|
|
40
|
+
__defProp(entry, key, {
|
|
41
|
+
get: __accessProp.bind(from, key),
|
|
42
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
__moduleCache.set(from, entry);
|
|
46
|
+
return entry;
|
|
47
|
+
};
|
|
48
|
+
var __moduleCache;
|
|
49
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
50
|
+
var __returnValue = (v) => v;
|
|
51
|
+
function __exportSetter(name, newValue) {
|
|
52
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
53
|
+
}
|
|
54
|
+
var __export = (target, all) => {
|
|
55
|
+
for (var name in all)
|
|
56
|
+
__defProp(target, name, {
|
|
57
|
+
get: all[name],
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true,
|
|
60
|
+
set: __exportSetter.bind(all, name)
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
64
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
65
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
66
|
+
}) : x)(function(x) {
|
|
67
|
+
if (typeof require !== "undefined")
|
|
68
|
+
return require.apply(this, arguments);
|
|
69
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// node_modules/commander/lib/error.js
|
|
73
|
+
var require_error = __commonJS((exports) => {
|
|
74
|
+
class CommanderError extends Error {
|
|
75
|
+
constructor(exitCode, code, message) {
|
|
76
|
+
super(message);
|
|
77
|
+
Error.captureStackTrace(this, this.constructor);
|
|
78
|
+
this.name = this.constructor.name;
|
|
79
|
+
this.code = code;
|
|
80
|
+
this.exitCode = exitCode;
|
|
81
|
+
this.nestedError = undefined;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
class InvalidArgumentError extends CommanderError {
|
|
86
|
+
constructor(message) {
|
|
87
|
+
super(1, "commander.invalidArgument", message);
|
|
88
|
+
Error.captureStackTrace(this, this.constructor);
|
|
89
|
+
this.name = this.constructor.name;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.CommanderError = CommanderError;
|
|
93
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// node_modules/commander/lib/argument.js
|
|
97
|
+
var require_argument = __commonJS((exports) => {
|
|
98
|
+
var { InvalidArgumentError } = require_error();
|
|
99
|
+
|
|
100
|
+
class Argument {
|
|
101
|
+
constructor(name, description) {
|
|
102
|
+
this.description = description || "";
|
|
103
|
+
this.variadic = false;
|
|
104
|
+
this.parseArg = undefined;
|
|
105
|
+
this.defaultValue = undefined;
|
|
106
|
+
this.defaultValueDescription = undefined;
|
|
107
|
+
this.argChoices = undefined;
|
|
108
|
+
switch (name[0]) {
|
|
109
|
+
case "<":
|
|
110
|
+
this.required = true;
|
|
111
|
+
this._name = name.slice(1, -1);
|
|
112
|
+
break;
|
|
113
|
+
case "[":
|
|
114
|
+
this.required = false;
|
|
115
|
+
this._name = name.slice(1, -1);
|
|
116
|
+
break;
|
|
117
|
+
default:
|
|
118
|
+
this.required = true;
|
|
119
|
+
this._name = name;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
if (this._name.endsWith("...")) {
|
|
123
|
+
this.variadic = true;
|
|
124
|
+
this._name = this._name.slice(0, -3);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
name() {
|
|
128
|
+
return this._name;
|
|
129
|
+
}
|
|
130
|
+
_collectValue(value, previous) {
|
|
131
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
132
|
+
return [value];
|
|
133
|
+
}
|
|
134
|
+
previous.push(value);
|
|
135
|
+
return previous;
|
|
136
|
+
}
|
|
137
|
+
default(value, description) {
|
|
138
|
+
this.defaultValue = value;
|
|
139
|
+
this.defaultValueDescription = description;
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
argParser(fn) {
|
|
143
|
+
this.parseArg = fn;
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
choices(values) {
|
|
147
|
+
this.argChoices = values.slice();
|
|
148
|
+
this.parseArg = (arg, previous) => {
|
|
149
|
+
if (!this.argChoices.includes(arg)) {
|
|
150
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
151
|
+
}
|
|
152
|
+
if (this.variadic) {
|
|
153
|
+
return this._collectValue(arg, previous);
|
|
154
|
+
}
|
|
155
|
+
return arg;
|
|
156
|
+
};
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
argRequired() {
|
|
160
|
+
this.required = true;
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
argOptional() {
|
|
164
|
+
this.required = false;
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function humanReadableArgName(arg) {
|
|
169
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
170
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
171
|
+
}
|
|
172
|
+
exports.Argument = Argument;
|
|
173
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// node:events
|
|
177
|
+
var exports_events = {};
|
|
178
|
+
__export(exports_events, {
|
|
179
|
+
setMaxListeners: () => setMaxListeners2,
|
|
180
|
+
once: () => once2,
|
|
181
|
+
listenerCount: () => listenerCount2,
|
|
182
|
+
init: () => EventEmitter,
|
|
183
|
+
getMaxListeners: () => getMaxListeners2,
|
|
184
|
+
getEventListeners: () => getEventListeners,
|
|
185
|
+
default: () => events_default,
|
|
186
|
+
captureRejectionSymbol: () => captureRejectionSymbol,
|
|
187
|
+
addAbortListener: () => addAbortListener,
|
|
188
|
+
EventEmitter: () => EventEmitter
|
|
189
|
+
});
|
|
190
|
+
function emitError(emitter, args) {
|
|
191
|
+
var { _events: events } = emitter;
|
|
192
|
+
if (args[0] ??= Error("Unhandled error."), !events)
|
|
193
|
+
throw args[0];
|
|
194
|
+
var errorMonitor = events[kErrorMonitor];
|
|
195
|
+
if (errorMonitor)
|
|
196
|
+
for (var handler of ArrayPrototypeSlice.call(errorMonitor))
|
|
197
|
+
handler.apply(emitter, args);
|
|
198
|
+
var handlers = events.error;
|
|
199
|
+
if (!handlers)
|
|
200
|
+
throw args[0];
|
|
201
|
+
for (var handler of ArrayPrototypeSlice.call(handlers))
|
|
202
|
+
handler.apply(emitter, args);
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
function addCatch(emitter, promise, type, args) {
|
|
206
|
+
promise.then(undefined, function(err) {
|
|
207
|
+
queueMicrotask(() => emitUnhandledRejectionOrErr(emitter, err, type, args));
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function emitUnhandledRejectionOrErr(emitter, err, type, args) {
|
|
211
|
+
if (typeof emitter[kRejection] === "function")
|
|
212
|
+
emitter[kRejection](err, type, ...args);
|
|
213
|
+
else
|
|
214
|
+
try {
|
|
215
|
+
emitter[kCapture] = false, emitter.emit("error", err);
|
|
216
|
+
} finally {
|
|
217
|
+
emitter[kCapture] = true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function overflowWarning(emitter, type, handlers) {
|
|
221
|
+
handlers.warned = true;
|
|
222
|
+
let warn = Error(`Possible EventEmitter memory leak detected. ${handlers.length} ${String(type)} listeners added to [${emitter.constructor.name}]. Use emitter.setMaxListeners() to increase limit`);
|
|
223
|
+
warn.name = "MaxListenersExceededWarning", warn.emitter = emitter, warn.type = type, warn.count = handlers.length, console.warn(warn);
|
|
224
|
+
}
|
|
225
|
+
function onceWrapper(type, listener, ...args) {
|
|
226
|
+
this.removeListener(type, listener), listener.apply(this, args);
|
|
227
|
+
}
|
|
228
|
+
function once2(emitter, type, options) {
|
|
229
|
+
var signal = options?.signal;
|
|
230
|
+
if (validateAbortSignal(signal, "options.signal"), signal?.aborted)
|
|
231
|
+
throw new AbortError(undefined, { cause: signal?.reason });
|
|
232
|
+
let { resolve, reject, promise } = $newPromiseCapability(Promise), errorListener = (err) => {
|
|
233
|
+
if (emitter.removeListener(type, resolver), signal != null)
|
|
234
|
+
eventTargetAgnosticRemoveListener(signal, "abort", abortListener);
|
|
235
|
+
reject(err);
|
|
236
|
+
}, resolver = (...args) => {
|
|
237
|
+
if (typeof emitter.removeListener === "function")
|
|
238
|
+
emitter.removeListener("error", errorListener);
|
|
239
|
+
if (signal != null)
|
|
240
|
+
eventTargetAgnosticRemoveListener(signal, "abort", abortListener);
|
|
241
|
+
resolve(args);
|
|
242
|
+
};
|
|
243
|
+
if (eventTargetAgnosticAddListener(emitter, type, resolver, { once: true }), type !== "error" && typeof emitter.once === "function")
|
|
244
|
+
emitter.once("error", errorListener);
|
|
245
|
+
function abortListener() {
|
|
246
|
+
eventTargetAgnosticRemoveListener(emitter, type, resolver), eventTargetAgnosticRemoveListener(emitter, "error", errorListener), reject(new AbortError(undefined, { cause: signal?.reason }));
|
|
247
|
+
}
|
|
248
|
+
if (signal != null)
|
|
249
|
+
eventTargetAgnosticAddListener(signal, "abort", abortListener, { once: true });
|
|
250
|
+
return promise;
|
|
251
|
+
}
|
|
252
|
+
function getEventListeners(emitter, type) {
|
|
253
|
+
return emitter.listeners(type);
|
|
254
|
+
}
|
|
255
|
+
function setMaxListeners2(n, ...eventTargets) {
|
|
256
|
+
validateNumber(n, "setMaxListeners", 0);
|
|
257
|
+
var length;
|
|
258
|
+
if (eventTargets && (length = eventTargets.length))
|
|
259
|
+
for (let i = 0;i < length; i++)
|
|
260
|
+
eventTargets[i].setMaxListeners(n);
|
|
261
|
+
else
|
|
262
|
+
defaultMaxListeners = n;
|
|
263
|
+
}
|
|
264
|
+
function listenerCount2(emitter, type) {
|
|
265
|
+
return emitter.listenerCount(type);
|
|
266
|
+
}
|
|
267
|
+
function eventTargetAgnosticRemoveListener(emitter, name, listener, flags) {
|
|
268
|
+
if (typeof emitter.removeListener === "function")
|
|
269
|
+
emitter.removeListener(name, listener);
|
|
270
|
+
else
|
|
271
|
+
emitter.removeEventListener(name, listener, flags);
|
|
272
|
+
}
|
|
273
|
+
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
274
|
+
if (typeof emitter.on === "function")
|
|
275
|
+
if (flags.once)
|
|
276
|
+
emitter.once(name, listener);
|
|
277
|
+
else
|
|
278
|
+
emitter.on(name, listener);
|
|
279
|
+
else
|
|
280
|
+
emitter.addEventListener(name, listener, flags);
|
|
281
|
+
}
|
|
282
|
+
function ERR_INVALID_ARG_TYPE(name, type, value) {
|
|
283
|
+
let err = TypeError(`The "${name}" argument must be of type ${type}. Received ${value}`);
|
|
284
|
+
return err.code = "ERR_INVALID_ARG_TYPE", err;
|
|
285
|
+
}
|
|
286
|
+
function ERR_OUT_OF_RANGE(name, range, value) {
|
|
287
|
+
let err = RangeError(`The "${name}" argument is out of range. It must be ${range}. Received ${value}`);
|
|
288
|
+
return err.code = "ERR_OUT_OF_RANGE", err;
|
|
289
|
+
}
|
|
290
|
+
function validateAbortSignal(signal, name) {
|
|
291
|
+
if (signal !== undefined && (signal === null || typeof signal !== "object" || !("aborted" in signal)))
|
|
292
|
+
throw ERR_INVALID_ARG_TYPE(name, "AbortSignal", signal);
|
|
293
|
+
}
|
|
294
|
+
function validateNumber(value, name, min, max) {
|
|
295
|
+
if (typeof value !== "number")
|
|
296
|
+
throw ERR_INVALID_ARG_TYPE(name, "number", value);
|
|
297
|
+
if (min != null && value < min || max != null && value > max || (min != null || max != null) && Number.isNaN(value))
|
|
298
|
+
throw ERR_OUT_OF_RANGE(name, `${min != null ? `>= ${min}` : ""}${min != null && max != null ? " && " : ""}${max != null ? `<= ${max}` : ""}`, value);
|
|
299
|
+
}
|
|
300
|
+
function checkListener(listener) {
|
|
301
|
+
if (typeof listener !== "function")
|
|
302
|
+
throw TypeError("The listener must be a function");
|
|
303
|
+
}
|
|
304
|
+
function validateBoolean(value, name) {
|
|
305
|
+
if (typeof value !== "boolean")
|
|
306
|
+
throw ERR_INVALID_ARG_TYPE(name, "boolean", value);
|
|
307
|
+
}
|
|
308
|
+
function getMaxListeners2(emitterOrTarget) {
|
|
309
|
+
return emitterOrTarget?._maxListeners ?? defaultMaxListeners;
|
|
310
|
+
}
|
|
311
|
+
function addAbortListener(signal, listener) {
|
|
312
|
+
if (signal === undefined)
|
|
313
|
+
throw ERR_INVALID_ARG_TYPE("signal", "AbortSignal", signal);
|
|
314
|
+
if (validateAbortSignal(signal, "signal"), typeof listener !== "function")
|
|
315
|
+
throw ERR_INVALID_ARG_TYPE("listener", "function", listener);
|
|
316
|
+
let removeEventListener;
|
|
317
|
+
if (signal.aborted)
|
|
318
|
+
queueMicrotask(() => listener());
|
|
319
|
+
else
|
|
320
|
+
signal.addEventListener("abort", listener, { __proto__: null, once: true }), removeEventListener = () => {
|
|
321
|
+
signal.removeEventListener("abort", listener);
|
|
322
|
+
};
|
|
323
|
+
return { __proto__: null, [Symbol.dispose]() {
|
|
324
|
+
removeEventListener?.();
|
|
325
|
+
} };
|
|
326
|
+
}
|
|
327
|
+
var SymbolFor, kCapture, kErrorMonitor, kMaxEventTargetListeners, kMaxEventTargetListenersWarned, kRejection, captureRejectionSymbol, ArrayPrototypeSlice, defaultMaxListeners = 10, EventEmitter = function(opts) {
|
|
328
|
+
if (this._events === undefined || this._events === this.__proto__._events)
|
|
329
|
+
this._events = { __proto__: null }, this._eventsCount = 0;
|
|
330
|
+
if (this._maxListeners ??= undefined, this[kCapture] = opts?.captureRejections ? Boolean(opts?.captureRejections) : EventEmitterPrototype[kCapture])
|
|
331
|
+
this.emit = emitWithRejectionCapture;
|
|
332
|
+
}, EventEmitterPrototype, emitWithoutRejectionCapture = function(type, ...args) {
|
|
333
|
+
if (type === "error")
|
|
334
|
+
return emitError(this, args);
|
|
335
|
+
var { _events: events } = this;
|
|
336
|
+
if (events === undefined)
|
|
337
|
+
return false;
|
|
338
|
+
var handlers = events[type];
|
|
339
|
+
if (handlers === undefined)
|
|
340
|
+
return false;
|
|
341
|
+
let maybeClonedHandlers = handlers.length > 1 ? handlers.slice() : handlers;
|
|
342
|
+
for (let i = 0, { length } = maybeClonedHandlers;i < length; i++) {
|
|
343
|
+
let handler = maybeClonedHandlers[i];
|
|
344
|
+
switch (args.length) {
|
|
345
|
+
case 0:
|
|
346
|
+
handler.call(this);
|
|
347
|
+
break;
|
|
348
|
+
case 1:
|
|
349
|
+
handler.call(this, args[0]);
|
|
350
|
+
break;
|
|
351
|
+
case 2:
|
|
352
|
+
handler.call(this, args[0], args[1]);
|
|
353
|
+
break;
|
|
354
|
+
case 3:
|
|
355
|
+
handler.call(this, args[0], args[1], args[2]);
|
|
356
|
+
break;
|
|
357
|
+
default:
|
|
358
|
+
handler.apply(this, args);
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return true;
|
|
363
|
+
}, emitWithRejectionCapture = function(type, ...args) {
|
|
364
|
+
if (type === "error")
|
|
365
|
+
return emitError(this, args);
|
|
366
|
+
var { _events: events } = this;
|
|
367
|
+
if (events === undefined)
|
|
368
|
+
return false;
|
|
369
|
+
var handlers = events[type];
|
|
370
|
+
if (handlers === undefined)
|
|
371
|
+
return false;
|
|
372
|
+
let maybeClonedHandlers = handlers.length > 1 ? handlers.slice() : handlers;
|
|
373
|
+
for (let i = 0, { length } = maybeClonedHandlers;i < length; i++) {
|
|
374
|
+
let handler = maybeClonedHandlers[i], result;
|
|
375
|
+
switch (args.length) {
|
|
376
|
+
case 0:
|
|
377
|
+
result = handler.call(this);
|
|
378
|
+
break;
|
|
379
|
+
case 1:
|
|
380
|
+
result = handler.call(this, args[0]);
|
|
381
|
+
break;
|
|
382
|
+
case 2:
|
|
383
|
+
result = handler.call(this, args[0], args[1]);
|
|
384
|
+
break;
|
|
385
|
+
case 3:
|
|
386
|
+
result = handler.call(this, args[0], args[1], args[2]);
|
|
387
|
+
break;
|
|
388
|
+
default:
|
|
389
|
+
result = handler.apply(this, args);
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
if (result !== undefined && typeof result?.then === "function" && result.then === Promise.prototype.then)
|
|
393
|
+
addCatch(this, result, type, args);
|
|
394
|
+
}
|
|
395
|
+
return true;
|
|
396
|
+
}, AbortError, events_default;
|
|
397
|
+
var init_events = __esm(() => {
|
|
398
|
+
SymbolFor = Symbol.for;
|
|
399
|
+
kCapture = Symbol("kCapture");
|
|
400
|
+
kErrorMonitor = SymbolFor("events.errorMonitor");
|
|
401
|
+
kMaxEventTargetListeners = Symbol("events.maxEventTargetListeners");
|
|
402
|
+
kMaxEventTargetListenersWarned = Symbol("events.maxEventTargetListenersWarned");
|
|
403
|
+
kRejection = SymbolFor("nodejs.rejection");
|
|
404
|
+
captureRejectionSymbol = SymbolFor("nodejs.rejection");
|
|
405
|
+
ArrayPrototypeSlice = Array.prototype.slice;
|
|
406
|
+
EventEmitterPrototype = EventEmitter.prototype = {};
|
|
407
|
+
EventEmitterPrototype._events = undefined;
|
|
408
|
+
EventEmitterPrototype._eventsCount = 0;
|
|
409
|
+
EventEmitterPrototype._maxListeners = undefined;
|
|
410
|
+
EventEmitterPrototype.setMaxListeners = function(n) {
|
|
411
|
+
return validateNumber(n, "setMaxListeners", 0), this._maxListeners = n, this;
|
|
412
|
+
};
|
|
413
|
+
EventEmitterPrototype.constructor = EventEmitter;
|
|
414
|
+
EventEmitterPrototype.getMaxListeners = function() {
|
|
415
|
+
return this?._maxListeners ?? defaultMaxListeners;
|
|
416
|
+
};
|
|
417
|
+
EventEmitterPrototype.emit = emitWithoutRejectionCapture;
|
|
418
|
+
EventEmitterPrototype.addListener = function(type, fn) {
|
|
419
|
+
checkListener(fn);
|
|
420
|
+
var events = this._events;
|
|
421
|
+
if (!events)
|
|
422
|
+
events = this._events = { __proto__: null }, this._eventsCount = 0;
|
|
423
|
+
else if (events.newListener)
|
|
424
|
+
this.emit("newListener", type, fn.listener ?? fn);
|
|
425
|
+
var handlers = events[type];
|
|
426
|
+
if (!handlers)
|
|
427
|
+
events[type] = [fn], this._eventsCount++;
|
|
428
|
+
else {
|
|
429
|
+
handlers.push(fn);
|
|
430
|
+
var m = this._maxListeners ?? defaultMaxListeners;
|
|
431
|
+
if (m > 0 && handlers.length > m && !handlers.warned)
|
|
432
|
+
overflowWarning(this, type, handlers);
|
|
433
|
+
}
|
|
434
|
+
return this;
|
|
435
|
+
};
|
|
436
|
+
EventEmitterPrototype.on = EventEmitterPrototype.addListener;
|
|
437
|
+
EventEmitterPrototype.prependListener = function(type, fn) {
|
|
438
|
+
checkListener(fn);
|
|
439
|
+
var events = this._events;
|
|
440
|
+
if (!events)
|
|
441
|
+
events = this._events = { __proto__: null }, this._eventsCount = 0;
|
|
442
|
+
else if (events.newListener)
|
|
443
|
+
this.emit("newListener", type, fn.listener ?? fn);
|
|
444
|
+
var handlers = events[type];
|
|
445
|
+
if (!handlers)
|
|
446
|
+
events[type] = [fn], this._eventsCount++;
|
|
447
|
+
else {
|
|
448
|
+
handlers.unshift(fn);
|
|
449
|
+
var m = this._maxListeners ?? defaultMaxListeners;
|
|
450
|
+
if (m > 0 && handlers.length > m && !handlers.warned)
|
|
451
|
+
overflowWarning(this, type, handlers);
|
|
452
|
+
}
|
|
453
|
+
return this;
|
|
454
|
+
};
|
|
455
|
+
EventEmitterPrototype.once = function(type, fn) {
|
|
456
|
+
checkListener(fn);
|
|
457
|
+
let bound = onceWrapper.bind(this, type, fn);
|
|
458
|
+
return bound.listener = fn, this.addListener(type, bound), this;
|
|
459
|
+
};
|
|
460
|
+
EventEmitterPrototype.prependOnceListener = function(type, fn) {
|
|
461
|
+
checkListener(fn);
|
|
462
|
+
let bound = onceWrapper.bind(this, type, fn);
|
|
463
|
+
return bound.listener = fn, this.prependListener(type, bound), this;
|
|
464
|
+
};
|
|
465
|
+
EventEmitterPrototype.removeListener = function(type, fn) {
|
|
466
|
+
checkListener(fn);
|
|
467
|
+
var { _events: events } = this;
|
|
468
|
+
if (!events)
|
|
469
|
+
return this;
|
|
470
|
+
var handlers = events[type];
|
|
471
|
+
if (!handlers)
|
|
472
|
+
return this;
|
|
473
|
+
var length = handlers.length;
|
|
474
|
+
let position = -1;
|
|
475
|
+
for (let i = length - 1;i >= 0; i--)
|
|
476
|
+
if (handlers[i] === fn || handlers[i].listener === fn) {
|
|
477
|
+
position = i;
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
if (position < 0)
|
|
481
|
+
return this;
|
|
482
|
+
if (position === 0)
|
|
483
|
+
handlers.shift();
|
|
484
|
+
else
|
|
485
|
+
handlers.splice(position, 1);
|
|
486
|
+
if (handlers.length === 0)
|
|
487
|
+
delete events[type], this._eventsCount--;
|
|
488
|
+
return this;
|
|
489
|
+
};
|
|
490
|
+
EventEmitterPrototype.off = EventEmitterPrototype.removeListener;
|
|
491
|
+
EventEmitterPrototype.removeAllListeners = function(type) {
|
|
492
|
+
var { _events: events } = this;
|
|
493
|
+
if (type && events) {
|
|
494
|
+
if (events[type])
|
|
495
|
+
delete events[type], this._eventsCount--;
|
|
496
|
+
} else
|
|
497
|
+
this._events = { __proto__: null };
|
|
498
|
+
return this;
|
|
499
|
+
};
|
|
500
|
+
EventEmitterPrototype.listeners = function(type) {
|
|
501
|
+
var { _events: events } = this;
|
|
502
|
+
if (!events)
|
|
503
|
+
return [];
|
|
504
|
+
var handlers = events[type];
|
|
505
|
+
if (!handlers)
|
|
506
|
+
return [];
|
|
507
|
+
return handlers.map((x) => x.listener ?? x);
|
|
508
|
+
};
|
|
509
|
+
EventEmitterPrototype.rawListeners = function(type) {
|
|
510
|
+
var { _events } = this;
|
|
511
|
+
if (!_events)
|
|
512
|
+
return [];
|
|
513
|
+
var handlers = _events[type];
|
|
514
|
+
if (!handlers)
|
|
515
|
+
return [];
|
|
516
|
+
return handlers.slice();
|
|
517
|
+
};
|
|
518
|
+
EventEmitterPrototype.listenerCount = function(type) {
|
|
519
|
+
var { _events: events } = this;
|
|
520
|
+
if (!events)
|
|
521
|
+
return 0;
|
|
522
|
+
return events[type]?.length ?? 0;
|
|
523
|
+
};
|
|
524
|
+
EventEmitterPrototype.eventNames = function() {
|
|
525
|
+
return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
|
|
526
|
+
};
|
|
527
|
+
EventEmitterPrototype[kCapture] = false;
|
|
528
|
+
AbortError = class AbortError extends Error {
|
|
529
|
+
constructor(message = "The operation was aborted", options = undefined) {
|
|
530
|
+
if (options !== undefined && typeof options !== "object")
|
|
531
|
+
throw ERR_INVALID_ARG_TYPE("options", "Object", options);
|
|
532
|
+
super(message, options);
|
|
533
|
+
this.code = "ABORT_ERR", this.name = "AbortError";
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
Object.defineProperties(EventEmitter, { captureRejections: { get() {
|
|
537
|
+
return EventEmitterPrototype[kCapture];
|
|
538
|
+
}, set(value) {
|
|
539
|
+
validateBoolean(value, "EventEmitter.captureRejections"), EventEmitterPrototype[kCapture] = value;
|
|
540
|
+
}, enumerable: true }, defaultMaxListeners: { enumerable: true, get: () => {
|
|
541
|
+
return defaultMaxListeners;
|
|
542
|
+
}, set: (arg) => {
|
|
543
|
+
validateNumber(arg, "defaultMaxListeners", 0), defaultMaxListeners = arg;
|
|
544
|
+
} }, kMaxEventTargetListeners: { value: kMaxEventTargetListeners, enumerable: false, configurable: false, writable: false }, kMaxEventTargetListenersWarned: { value: kMaxEventTargetListenersWarned, enumerable: false, configurable: false, writable: false } });
|
|
545
|
+
Object.assign(EventEmitter, { once: once2, getEventListeners, getMaxListeners: getMaxListeners2, setMaxListeners: setMaxListeners2, EventEmitter, usingDomains: false, captureRejectionSymbol, errorMonitor: kErrorMonitor, addAbortListener, init: EventEmitter, listenerCount: listenerCount2 });
|
|
546
|
+
events_default = EventEmitter;
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
// node:path
|
|
550
|
+
var exports_path = {};
|
|
551
|
+
__export(exports_path, {
|
|
552
|
+
sep: () => sep,
|
|
553
|
+
resolve: () => resolve,
|
|
554
|
+
relative: () => relative,
|
|
555
|
+
posix: () => posix,
|
|
556
|
+
parse: () => parse,
|
|
557
|
+
normalize: () => normalize,
|
|
558
|
+
join: () => join,
|
|
559
|
+
isAbsolute: () => isAbsolute,
|
|
560
|
+
format: () => format,
|
|
561
|
+
extname: () => extname,
|
|
562
|
+
dirname: () => dirname,
|
|
563
|
+
delimiter: () => delimiter,
|
|
564
|
+
default: () => path_default,
|
|
565
|
+
basename: () => basename,
|
|
566
|
+
_makeLong: () => _makeLong
|
|
567
|
+
});
|
|
568
|
+
function assertPath(path) {
|
|
569
|
+
if (typeof path !== "string")
|
|
570
|
+
throw TypeError("Path must be a string. Received " + JSON.stringify(path));
|
|
571
|
+
}
|
|
572
|
+
function normalizeStringPosix(path, allowAboveRoot) {
|
|
573
|
+
var res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, code;
|
|
574
|
+
for (var i = 0;i <= path.length; ++i) {
|
|
575
|
+
if (i < path.length)
|
|
576
|
+
code = path.charCodeAt(i);
|
|
577
|
+
else if (code === 47)
|
|
578
|
+
break;
|
|
579
|
+
else
|
|
580
|
+
code = 47;
|
|
581
|
+
if (code === 47) {
|
|
582
|
+
if (lastSlash === i - 1 || dots === 1)
|
|
583
|
+
;
|
|
584
|
+
else if (lastSlash !== i - 1 && dots === 2) {
|
|
585
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
|
|
586
|
+
if (res.length > 2) {
|
|
587
|
+
var lastSlashIndex = res.lastIndexOf("/");
|
|
588
|
+
if (lastSlashIndex !== res.length - 1) {
|
|
589
|
+
if (lastSlashIndex === -1)
|
|
590
|
+
res = "", lastSegmentLength = 0;
|
|
591
|
+
else
|
|
592
|
+
res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
593
|
+
lastSlash = i, dots = 0;
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
} else if (res.length === 2 || res.length === 1) {
|
|
597
|
+
res = "", lastSegmentLength = 0, lastSlash = i, dots = 0;
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
if (allowAboveRoot) {
|
|
602
|
+
if (res.length > 0)
|
|
603
|
+
res += "/..";
|
|
604
|
+
else
|
|
605
|
+
res = "..";
|
|
606
|
+
lastSegmentLength = 2;
|
|
607
|
+
}
|
|
608
|
+
} else {
|
|
609
|
+
if (res.length > 0)
|
|
610
|
+
res += "/" + path.slice(lastSlash + 1, i);
|
|
611
|
+
else
|
|
612
|
+
res = path.slice(lastSlash + 1, i);
|
|
613
|
+
lastSegmentLength = i - lastSlash - 1;
|
|
614
|
+
}
|
|
615
|
+
lastSlash = i, dots = 0;
|
|
616
|
+
} else if (code === 46 && dots !== -1)
|
|
617
|
+
++dots;
|
|
618
|
+
else
|
|
619
|
+
dots = -1;
|
|
620
|
+
}
|
|
621
|
+
return res;
|
|
622
|
+
}
|
|
623
|
+
function _format(sep, pathObject) {
|
|
624
|
+
var dir = pathObject.dir || pathObject.root, base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
|
|
625
|
+
if (!dir)
|
|
626
|
+
return base;
|
|
627
|
+
if (dir === pathObject.root)
|
|
628
|
+
return dir + base;
|
|
629
|
+
return dir + sep + base;
|
|
630
|
+
}
|
|
631
|
+
function resolve() {
|
|
632
|
+
var resolvedPath = "", resolvedAbsolute = false, cwd;
|
|
633
|
+
for (var i = arguments.length - 1;i >= -1 && !resolvedAbsolute; i--) {
|
|
634
|
+
var path;
|
|
635
|
+
if (i >= 0)
|
|
636
|
+
path = arguments[i];
|
|
637
|
+
else {
|
|
638
|
+
if (cwd === undefined)
|
|
639
|
+
cwd = process.cwd();
|
|
640
|
+
path = cwd;
|
|
641
|
+
}
|
|
642
|
+
if (assertPath(path), path.length === 0)
|
|
643
|
+
continue;
|
|
644
|
+
resolvedPath = path + "/" + resolvedPath, resolvedAbsolute = path.charCodeAt(0) === 47;
|
|
645
|
+
}
|
|
646
|
+
if (resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute), resolvedAbsolute)
|
|
647
|
+
if (resolvedPath.length > 0)
|
|
648
|
+
return "/" + resolvedPath;
|
|
649
|
+
else
|
|
650
|
+
return "/";
|
|
651
|
+
else if (resolvedPath.length > 0)
|
|
652
|
+
return resolvedPath;
|
|
653
|
+
else
|
|
654
|
+
return ".";
|
|
655
|
+
}
|
|
656
|
+
function normalize(path) {
|
|
657
|
+
if (assertPath(path), path.length === 0)
|
|
658
|
+
return ".";
|
|
659
|
+
var isAbsolute = path.charCodeAt(0) === 47, trailingSeparator = path.charCodeAt(path.length - 1) === 47;
|
|
660
|
+
if (path = normalizeStringPosix(path, !isAbsolute), path.length === 0 && !isAbsolute)
|
|
661
|
+
path = ".";
|
|
662
|
+
if (path.length > 0 && trailingSeparator)
|
|
663
|
+
path += "/";
|
|
664
|
+
if (isAbsolute)
|
|
665
|
+
return "/" + path;
|
|
666
|
+
return path;
|
|
667
|
+
}
|
|
668
|
+
function isAbsolute(path) {
|
|
669
|
+
return assertPath(path), path.length > 0 && path.charCodeAt(0) === 47;
|
|
670
|
+
}
|
|
671
|
+
function join() {
|
|
672
|
+
if (arguments.length === 0)
|
|
673
|
+
return ".";
|
|
674
|
+
var joined;
|
|
675
|
+
for (var i = 0;i < arguments.length; ++i) {
|
|
676
|
+
var arg = arguments[i];
|
|
677
|
+
if (assertPath(arg), arg.length > 0)
|
|
678
|
+
if (joined === undefined)
|
|
679
|
+
joined = arg;
|
|
680
|
+
else
|
|
681
|
+
joined += "/" + arg;
|
|
682
|
+
}
|
|
683
|
+
if (joined === undefined)
|
|
684
|
+
return ".";
|
|
685
|
+
return normalize(joined);
|
|
686
|
+
}
|
|
687
|
+
function relative(from, to) {
|
|
688
|
+
if (assertPath(from), assertPath(to), from === to)
|
|
689
|
+
return "";
|
|
690
|
+
if (from = resolve(from), to = resolve(to), from === to)
|
|
691
|
+
return "";
|
|
692
|
+
var fromStart = 1;
|
|
693
|
+
for (;fromStart < from.length; ++fromStart)
|
|
694
|
+
if (from.charCodeAt(fromStart) !== 47)
|
|
695
|
+
break;
|
|
696
|
+
var fromEnd = from.length, fromLen = fromEnd - fromStart, toStart = 1;
|
|
697
|
+
for (;toStart < to.length; ++toStart)
|
|
698
|
+
if (to.charCodeAt(toStart) !== 47)
|
|
699
|
+
break;
|
|
700
|
+
var toEnd = to.length, toLen = toEnd - toStart, length = fromLen < toLen ? fromLen : toLen, lastCommonSep = -1, i = 0;
|
|
701
|
+
for (;i <= length; ++i) {
|
|
702
|
+
if (i === length) {
|
|
703
|
+
if (toLen > length) {
|
|
704
|
+
if (to.charCodeAt(toStart + i) === 47)
|
|
705
|
+
return to.slice(toStart + i + 1);
|
|
706
|
+
else if (i === 0)
|
|
707
|
+
return to.slice(toStart + i);
|
|
708
|
+
} else if (fromLen > length) {
|
|
709
|
+
if (from.charCodeAt(fromStart + i) === 47)
|
|
710
|
+
lastCommonSep = i;
|
|
711
|
+
else if (i === 0)
|
|
712
|
+
lastCommonSep = 0;
|
|
713
|
+
}
|
|
714
|
+
break;
|
|
715
|
+
}
|
|
716
|
+
var fromCode = from.charCodeAt(fromStart + i), toCode = to.charCodeAt(toStart + i);
|
|
717
|
+
if (fromCode !== toCode)
|
|
718
|
+
break;
|
|
719
|
+
else if (fromCode === 47)
|
|
720
|
+
lastCommonSep = i;
|
|
721
|
+
}
|
|
722
|
+
var out = "";
|
|
723
|
+
for (i = fromStart + lastCommonSep + 1;i <= fromEnd; ++i)
|
|
724
|
+
if (i === fromEnd || from.charCodeAt(i) === 47)
|
|
725
|
+
if (out.length === 0)
|
|
726
|
+
out += "..";
|
|
727
|
+
else
|
|
728
|
+
out += "/..";
|
|
729
|
+
if (out.length > 0)
|
|
730
|
+
return out + to.slice(toStart + lastCommonSep);
|
|
731
|
+
else {
|
|
732
|
+
if (toStart += lastCommonSep, to.charCodeAt(toStart) === 47)
|
|
733
|
+
++toStart;
|
|
734
|
+
return to.slice(toStart);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
function _makeLong(path) {
|
|
738
|
+
return path;
|
|
739
|
+
}
|
|
740
|
+
function dirname(path) {
|
|
741
|
+
if (assertPath(path), path.length === 0)
|
|
742
|
+
return ".";
|
|
743
|
+
var code = path.charCodeAt(0), hasRoot = code === 47, end = -1, matchedSlash = true;
|
|
744
|
+
for (var i = path.length - 1;i >= 1; --i)
|
|
745
|
+
if (code = path.charCodeAt(i), code === 47) {
|
|
746
|
+
if (!matchedSlash) {
|
|
747
|
+
end = i;
|
|
748
|
+
break;
|
|
749
|
+
}
|
|
750
|
+
} else
|
|
751
|
+
matchedSlash = false;
|
|
752
|
+
if (end === -1)
|
|
753
|
+
return hasRoot ? "/" : ".";
|
|
754
|
+
if (hasRoot && end === 1)
|
|
755
|
+
return "//";
|
|
756
|
+
return path.slice(0, end);
|
|
757
|
+
}
|
|
758
|
+
function basename(path, ext) {
|
|
759
|
+
if (ext !== undefined && typeof ext !== "string")
|
|
760
|
+
throw TypeError('"ext" argument must be a string');
|
|
761
|
+
assertPath(path);
|
|
762
|
+
var start = 0, end = -1, matchedSlash = true, i;
|
|
763
|
+
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
|
|
764
|
+
if (ext.length === path.length && ext === path)
|
|
765
|
+
return "";
|
|
766
|
+
var extIdx = ext.length - 1, firstNonSlashEnd = -1;
|
|
767
|
+
for (i = path.length - 1;i >= 0; --i) {
|
|
768
|
+
var code = path.charCodeAt(i);
|
|
769
|
+
if (code === 47) {
|
|
770
|
+
if (!matchedSlash) {
|
|
771
|
+
start = i + 1;
|
|
772
|
+
break;
|
|
773
|
+
}
|
|
774
|
+
} else {
|
|
775
|
+
if (firstNonSlashEnd === -1)
|
|
776
|
+
matchedSlash = false, firstNonSlashEnd = i + 1;
|
|
777
|
+
if (extIdx >= 0)
|
|
778
|
+
if (code === ext.charCodeAt(extIdx)) {
|
|
779
|
+
if (--extIdx === -1)
|
|
780
|
+
end = i;
|
|
781
|
+
} else
|
|
782
|
+
extIdx = -1, end = firstNonSlashEnd;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
if (start === end)
|
|
786
|
+
end = firstNonSlashEnd;
|
|
787
|
+
else if (end === -1)
|
|
788
|
+
end = path.length;
|
|
789
|
+
return path.slice(start, end);
|
|
790
|
+
} else {
|
|
791
|
+
for (i = path.length - 1;i >= 0; --i)
|
|
792
|
+
if (path.charCodeAt(i) === 47) {
|
|
793
|
+
if (!matchedSlash) {
|
|
794
|
+
start = i + 1;
|
|
795
|
+
break;
|
|
796
|
+
}
|
|
797
|
+
} else if (end === -1)
|
|
798
|
+
matchedSlash = false, end = i + 1;
|
|
799
|
+
if (end === -1)
|
|
800
|
+
return "";
|
|
801
|
+
return path.slice(start, end);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
function extname(path) {
|
|
805
|
+
assertPath(path);
|
|
806
|
+
var startDot = -1, startPart = 0, end = -1, matchedSlash = true, preDotState = 0;
|
|
807
|
+
for (var i = path.length - 1;i >= 0; --i) {
|
|
808
|
+
var code = path.charCodeAt(i);
|
|
809
|
+
if (code === 47) {
|
|
810
|
+
if (!matchedSlash) {
|
|
811
|
+
startPart = i + 1;
|
|
812
|
+
break;
|
|
813
|
+
}
|
|
814
|
+
continue;
|
|
815
|
+
}
|
|
816
|
+
if (end === -1)
|
|
817
|
+
matchedSlash = false, end = i + 1;
|
|
818
|
+
if (code === 46) {
|
|
819
|
+
if (startDot === -1)
|
|
820
|
+
startDot = i;
|
|
821
|
+
else if (preDotState !== 1)
|
|
822
|
+
preDotState = 1;
|
|
823
|
+
} else if (startDot !== -1)
|
|
824
|
+
preDotState = -1;
|
|
825
|
+
}
|
|
826
|
+
if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
|
|
827
|
+
return "";
|
|
828
|
+
return path.slice(startDot, end);
|
|
829
|
+
}
|
|
830
|
+
function format(pathObject) {
|
|
831
|
+
if (pathObject === null || typeof pathObject !== "object")
|
|
832
|
+
throw TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
|
|
833
|
+
return _format("/", pathObject);
|
|
834
|
+
}
|
|
835
|
+
function parse(path) {
|
|
836
|
+
assertPath(path);
|
|
837
|
+
var ret = { root: "", dir: "", base: "", ext: "", name: "" };
|
|
838
|
+
if (path.length === 0)
|
|
839
|
+
return ret;
|
|
840
|
+
var code = path.charCodeAt(0), isAbsolute2 = code === 47, start;
|
|
841
|
+
if (isAbsolute2)
|
|
842
|
+
ret.root = "/", start = 1;
|
|
843
|
+
else
|
|
844
|
+
start = 0;
|
|
845
|
+
var startDot = -1, startPart = 0, end = -1, matchedSlash = true, i = path.length - 1, preDotState = 0;
|
|
846
|
+
for (;i >= start; --i) {
|
|
847
|
+
if (code = path.charCodeAt(i), code === 47) {
|
|
848
|
+
if (!matchedSlash) {
|
|
849
|
+
startPart = i + 1;
|
|
850
|
+
break;
|
|
851
|
+
}
|
|
852
|
+
continue;
|
|
853
|
+
}
|
|
854
|
+
if (end === -1)
|
|
855
|
+
matchedSlash = false, end = i + 1;
|
|
856
|
+
if (code === 46) {
|
|
857
|
+
if (startDot === -1)
|
|
858
|
+
startDot = i;
|
|
859
|
+
else if (preDotState !== 1)
|
|
860
|
+
preDotState = 1;
|
|
861
|
+
} else if (startDot !== -1)
|
|
862
|
+
preDotState = -1;
|
|
863
|
+
}
|
|
864
|
+
if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
865
|
+
if (end !== -1)
|
|
866
|
+
if (startPart === 0 && isAbsolute2)
|
|
867
|
+
ret.base = ret.name = path.slice(1, end);
|
|
868
|
+
else
|
|
869
|
+
ret.base = ret.name = path.slice(startPart, end);
|
|
870
|
+
} else {
|
|
871
|
+
if (startPart === 0 && isAbsolute2)
|
|
872
|
+
ret.name = path.slice(1, startDot), ret.base = path.slice(1, end);
|
|
873
|
+
else
|
|
874
|
+
ret.name = path.slice(startPart, startDot), ret.base = path.slice(startPart, end);
|
|
875
|
+
ret.ext = path.slice(startDot, end);
|
|
876
|
+
}
|
|
877
|
+
if (startPart > 0)
|
|
878
|
+
ret.dir = path.slice(0, startPart - 1);
|
|
879
|
+
else if (isAbsolute2)
|
|
880
|
+
ret.dir = "/";
|
|
881
|
+
return ret;
|
|
882
|
+
}
|
|
883
|
+
var sep = "/", delimiter = ":", posix, path_default;
|
|
884
|
+
var init_path = __esm(() => {
|
|
885
|
+
posix = ((p) => (p.posix = p, p))({ resolve, normalize, isAbsolute, join, relative, _makeLong, dirname, basename, extname, format, parse, sep, delimiter, win32: null, posix: null });
|
|
886
|
+
path_default = posix;
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
// node:process
|
|
890
|
+
var exports_process = {};
|
|
891
|
+
__export(exports_process, {
|
|
892
|
+
versions: () => versions,
|
|
893
|
+
version: () => version,
|
|
894
|
+
umask: () => umask,
|
|
895
|
+
title: () => title,
|
|
896
|
+
removeListener: () => removeListener,
|
|
897
|
+
removeAllListeners: () => removeAllListeners,
|
|
898
|
+
prependOnceListener: () => prependOnceListener,
|
|
899
|
+
prependListener: () => prependListener,
|
|
900
|
+
once: () => once,
|
|
901
|
+
on: () => on,
|
|
902
|
+
off: () => off,
|
|
903
|
+
nextTick: () => nextTick,
|
|
904
|
+
listeners: () => listeners,
|
|
905
|
+
env: () => env,
|
|
906
|
+
emit: () => emit,
|
|
907
|
+
cwd: () => cwd,
|
|
908
|
+
chdir: () => chdir,
|
|
909
|
+
browser: () => browser,
|
|
910
|
+
binding: () => binding,
|
|
911
|
+
argv: () => argv,
|
|
912
|
+
addListener: () => addListener
|
|
913
|
+
});
|
|
914
|
+
function cleanUpNextTick() {
|
|
915
|
+
if (!draining || !currentQueue)
|
|
916
|
+
return;
|
|
917
|
+
if (draining = false, currentQueue.length)
|
|
918
|
+
queue = currentQueue.concat(queue);
|
|
919
|
+
else
|
|
920
|
+
queueIndex = -1;
|
|
921
|
+
if (queue.length)
|
|
922
|
+
drainQueue();
|
|
923
|
+
}
|
|
924
|
+
function drainQueue() {
|
|
925
|
+
if (draining)
|
|
926
|
+
return;
|
|
927
|
+
var timeout = setTimeout(cleanUpNextTick, 0);
|
|
928
|
+
draining = true;
|
|
929
|
+
var len = queue.length;
|
|
930
|
+
while (len) {
|
|
931
|
+
currentQueue = queue, queue = [];
|
|
932
|
+
while (++queueIndex < len)
|
|
933
|
+
if (currentQueue) {
|
|
934
|
+
var item = currentQueue[queueIndex];
|
|
935
|
+
item.fun.apply(null, item.array);
|
|
936
|
+
}
|
|
937
|
+
queueIndex = -1, len = queue.length;
|
|
938
|
+
}
|
|
939
|
+
currentQueue = null, draining = false, clearTimeout(timeout, 0);
|
|
940
|
+
}
|
|
941
|
+
function nextTick(fun) {
|
|
942
|
+
var args = Array(arguments.length - 1);
|
|
943
|
+
if (arguments.length > 1)
|
|
944
|
+
for (var i = 1;i < arguments.length; i++)
|
|
945
|
+
args[i - 1] = arguments[i];
|
|
946
|
+
if (queue.push({ fun, args }), queue.length === 1 && !draining)
|
|
947
|
+
setTimeout(drainQueue, 0);
|
|
948
|
+
}
|
|
949
|
+
function noop() {}
|
|
950
|
+
var queue, draining = false, currentQueue, queueIndex = -1, title = "browser", browser = true, env, argv, version = "", versions, on, addListener, once, off, removeListener, removeAllListeners, emit, prependListener, prependOnceListener, listeners = function(name) {
|
|
951
|
+
return [];
|
|
952
|
+
}, binding = function(name) {
|
|
953
|
+
throw Error("process.binding is not supported in browser polyfill");
|
|
954
|
+
}, cwd = function() {
|
|
955
|
+
return "/";
|
|
956
|
+
}, chdir = function(dir) {
|
|
957
|
+
throw Error("process.chdir is not supported in browser polyfill");
|
|
958
|
+
}, umask = function() {
|
|
959
|
+
return 0;
|
|
960
|
+
};
|
|
961
|
+
var init_process = __esm(() => {
|
|
962
|
+
queue = [];
|
|
963
|
+
env = {};
|
|
964
|
+
argv = [];
|
|
965
|
+
versions = {};
|
|
966
|
+
on = noop;
|
|
967
|
+
addListener = noop;
|
|
968
|
+
once = noop;
|
|
969
|
+
off = noop;
|
|
970
|
+
removeListener = noop;
|
|
971
|
+
removeAllListeners = noop;
|
|
972
|
+
emit = noop;
|
|
973
|
+
prependListener = noop;
|
|
974
|
+
prependOnceListener = noop;
|
|
975
|
+
});
|
|
976
|
+
|
|
977
|
+
// node_modules/commander/lib/help.js
|
|
978
|
+
var require_help = __commonJS((exports) => {
|
|
979
|
+
var { humanReadableArgName } = require_argument();
|
|
980
|
+
|
|
981
|
+
class Help {
|
|
982
|
+
constructor() {
|
|
983
|
+
this.helpWidth = undefined;
|
|
984
|
+
this.minWidthToWrap = 40;
|
|
985
|
+
this.sortSubcommands = false;
|
|
986
|
+
this.sortOptions = false;
|
|
987
|
+
this.showGlobalOptions = false;
|
|
988
|
+
}
|
|
989
|
+
prepareContext(contextOptions) {
|
|
990
|
+
this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
|
|
991
|
+
}
|
|
992
|
+
visibleCommands(cmd) {
|
|
993
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
994
|
+
const helpCommand = cmd._getHelpCommand();
|
|
995
|
+
if (helpCommand && !helpCommand._hidden) {
|
|
996
|
+
visibleCommands.push(helpCommand);
|
|
997
|
+
}
|
|
998
|
+
if (this.sortSubcommands) {
|
|
999
|
+
visibleCommands.sort((a, b) => {
|
|
1000
|
+
return a.name().localeCompare(b.name());
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
return visibleCommands;
|
|
1004
|
+
}
|
|
1005
|
+
compareOptions(a, b) {
|
|
1006
|
+
const getSortKey = (option) => {
|
|
1007
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
1008
|
+
};
|
|
1009
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
1010
|
+
}
|
|
1011
|
+
visibleOptions(cmd) {
|
|
1012
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
1013
|
+
const helpOption = cmd._getHelpOption();
|
|
1014
|
+
if (helpOption && !helpOption.hidden) {
|
|
1015
|
+
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
1016
|
+
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
1017
|
+
if (!removeShort && !removeLong) {
|
|
1018
|
+
visibleOptions.push(helpOption);
|
|
1019
|
+
} else if (helpOption.long && !removeLong) {
|
|
1020
|
+
visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
|
|
1021
|
+
} else if (helpOption.short && !removeShort) {
|
|
1022
|
+
visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
if (this.sortOptions) {
|
|
1026
|
+
visibleOptions.sort(this.compareOptions);
|
|
1027
|
+
}
|
|
1028
|
+
return visibleOptions;
|
|
1029
|
+
}
|
|
1030
|
+
visibleGlobalOptions(cmd) {
|
|
1031
|
+
if (!this.showGlobalOptions)
|
|
1032
|
+
return [];
|
|
1033
|
+
const globalOptions = [];
|
|
1034
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
1035
|
+
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
|
|
1036
|
+
globalOptions.push(...visibleOptions);
|
|
1037
|
+
}
|
|
1038
|
+
if (this.sortOptions) {
|
|
1039
|
+
globalOptions.sort(this.compareOptions);
|
|
1040
|
+
}
|
|
1041
|
+
return globalOptions;
|
|
1042
|
+
}
|
|
1043
|
+
visibleArguments(cmd) {
|
|
1044
|
+
if (cmd._argsDescription) {
|
|
1045
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
1046
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
1050
|
+
return cmd.registeredArguments;
|
|
1051
|
+
}
|
|
1052
|
+
return [];
|
|
1053
|
+
}
|
|
1054
|
+
subcommandTerm(cmd) {
|
|
1055
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
1056
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
1057
|
+
}
|
|
1058
|
+
optionTerm(option) {
|
|
1059
|
+
return option.flags;
|
|
1060
|
+
}
|
|
1061
|
+
argumentTerm(argument) {
|
|
1062
|
+
return argument.name();
|
|
1063
|
+
}
|
|
1064
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
1065
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
1066
|
+
return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
|
|
1067
|
+
}, 0);
|
|
1068
|
+
}
|
|
1069
|
+
longestOptionTermLength(cmd, helper) {
|
|
1070
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
1071
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
1072
|
+
}, 0);
|
|
1073
|
+
}
|
|
1074
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
1075
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
1076
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
1077
|
+
}, 0);
|
|
1078
|
+
}
|
|
1079
|
+
longestArgumentTermLength(cmd, helper) {
|
|
1080
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
1081
|
+
return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
|
|
1082
|
+
}, 0);
|
|
1083
|
+
}
|
|
1084
|
+
commandUsage(cmd) {
|
|
1085
|
+
let cmdName = cmd._name;
|
|
1086
|
+
if (cmd._aliases[0]) {
|
|
1087
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
1088
|
+
}
|
|
1089
|
+
let ancestorCmdNames = "";
|
|
1090
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
1091
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
1092
|
+
}
|
|
1093
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
1094
|
+
}
|
|
1095
|
+
commandDescription(cmd) {
|
|
1096
|
+
return cmd.description();
|
|
1097
|
+
}
|
|
1098
|
+
subcommandDescription(cmd) {
|
|
1099
|
+
return cmd.summary() || cmd.description();
|
|
1100
|
+
}
|
|
1101
|
+
optionDescription(option) {
|
|
1102
|
+
const extraInfo = [];
|
|
1103
|
+
if (option.argChoices) {
|
|
1104
|
+
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
1105
|
+
}
|
|
1106
|
+
if (option.defaultValue !== undefined) {
|
|
1107
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
1108
|
+
if (showDefault) {
|
|
1109
|
+
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
if (option.presetArg !== undefined && option.optional) {
|
|
1113
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
1114
|
+
}
|
|
1115
|
+
if (option.envVar !== undefined) {
|
|
1116
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
1117
|
+
}
|
|
1118
|
+
if (extraInfo.length > 0) {
|
|
1119
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
1120
|
+
if (option.description) {
|
|
1121
|
+
return `${option.description} ${extraDescription}`;
|
|
1122
|
+
}
|
|
1123
|
+
return extraDescription;
|
|
1124
|
+
}
|
|
1125
|
+
return option.description;
|
|
1126
|
+
}
|
|
1127
|
+
argumentDescription(argument) {
|
|
1128
|
+
const extraInfo = [];
|
|
1129
|
+
if (argument.argChoices) {
|
|
1130
|
+
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
1131
|
+
}
|
|
1132
|
+
if (argument.defaultValue !== undefined) {
|
|
1133
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
1134
|
+
}
|
|
1135
|
+
if (extraInfo.length > 0) {
|
|
1136
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
1137
|
+
if (argument.description) {
|
|
1138
|
+
return `${argument.description} ${extraDescription}`;
|
|
1139
|
+
}
|
|
1140
|
+
return extraDescription;
|
|
1141
|
+
}
|
|
1142
|
+
return argument.description;
|
|
1143
|
+
}
|
|
1144
|
+
formatItemList(heading, items, helper) {
|
|
1145
|
+
if (items.length === 0)
|
|
1146
|
+
return [];
|
|
1147
|
+
return [helper.styleTitle(heading), ...items, ""];
|
|
1148
|
+
}
|
|
1149
|
+
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
1150
|
+
const result = new Map;
|
|
1151
|
+
unsortedItems.forEach((item) => {
|
|
1152
|
+
const group = getGroup(item);
|
|
1153
|
+
if (!result.has(group))
|
|
1154
|
+
result.set(group, []);
|
|
1155
|
+
});
|
|
1156
|
+
visibleItems.forEach((item) => {
|
|
1157
|
+
const group = getGroup(item);
|
|
1158
|
+
if (!result.has(group)) {
|
|
1159
|
+
result.set(group, []);
|
|
1160
|
+
}
|
|
1161
|
+
result.get(group).push(item);
|
|
1162
|
+
});
|
|
1163
|
+
return result;
|
|
1164
|
+
}
|
|
1165
|
+
formatHelp(cmd, helper) {
|
|
1166
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
1167
|
+
const helpWidth = helper.helpWidth ?? 80;
|
|
1168
|
+
function callFormatItem(term, description) {
|
|
1169
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
1170
|
+
}
|
|
1171
|
+
let output = [
|
|
1172
|
+
`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
|
|
1173
|
+
""
|
|
1174
|
+
];
|
|
1175
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
1176
|
+
if (commandDescription.length > 0) {
|
|
1177
|
+
output = output.concat([
|
|
1178
|
+
helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth),
|
|
1179
|
+
""
|
|
1180
|
+
]);
|
|
1181
|
+
}
|
|
1182
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
1183
|
+
return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
|
|
1184
|
+
});
|
|
1185
|
+
output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
|
|
1186
|
+
const optionGroups = this.groupItems(cmd.options, helper.visibleOptions(cmd), (option) => option.helpGroupHeading ?? "Options:");
|
|
1187
|
+
optionGroups.forEach((options, group) => {
|
|
1188
|
+
const optionList = options.map((option) => {
|
|
1189
|
+
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
1190
|
+
});
|
|
1191
|
+
output = output.concat(this.formatItemList(group, optionList, helper));
|
|
1192
|
+
});
|
|
1193
|
+
if (helper.showGlobalOptions) {
|
|
1194
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
1195
|
+
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
1196
|
+
});
|
|
1197
|
+
output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
|
|
1198
|
+
}
|
|
1199
|
+
const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
|
|
1200
|
+
commandGroups.forEach((commands, group) => {
|
|
1201
|
+
const commandList = commands.map((sub) => {
|
|
1202
|
+
return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
|
|
1203
|
+
});
|
|
1204
|
+
output = output.concat(this.formatItemList(group, commandList, helper));
|
|
1205
|
+
});
|
|
1206
|
+
return output.join(`
|
|
1207
|
+
`);
|
|
1208
|
+
}
|
|
1209
|
+
displayWidth(str) {
|
|
1210
|
+
return stripColor(str).length;
|
|
1211
|
+
}
|
|
1212
|
+
styleTitle(str) {
|
|
1213
|
+
return str;
|
|
1214
|
+
}
|
|
1215
|
+
styleUsage(str) {
|
|
1216
|
+
return str.split(" ").map((word) => {
|
|
1217
|
+
if (word === "[options]")
|
|
1218
|
+
return this.styleOptionText(word);
|
|
1219
|
+
if (word === "[command]")
|
|
1220
|
+
return this.styleSubcommandText(word);
|
|
1221
|
+
if (word[0] === "[" || word[0] === "<")
|
|
1222
|
+
return this.styleArgumentText(word);
|
|
1223
|
+
return this.styleCommandText(word);
|
|
1224
|
+
}).join(" ");
|
|
1225
|
+
}
|
|
1226
|
+
styleCommandDescription(str) {
|
|
1227
|
+
return this.styleDescriptionText(str);
|
|
1228
|
+
}
|
|
1229
|
+
styleOptionDescription(str) {
|
|
1230
|
+
return this.styleDescriptionText(str);
|
|
1231
|
+
}
|
|
1232
|
+
styleSubcommandDescription(str) {
|
|
1233
|
+
return this.styleDescriptionText(str);
|
|
1234
|
+
}
|
|
1235
|
+
styleArgumentDescription(str) {
|
|
1236
|
+
return this.styleDescriptionText(str);
|
|
1237
|
+
}
|
|
1238
|
+
styleDescriptionText(str) {
|
|
1239
|
+
return str;
|
|
1240
|
+
}
|
|
1241
|
+
styleOptionTerm(str) {
|
|
1242
|
+
return this.styleOptionText(str);
|
|
1243
|
+
}
|
|
1244
|
+
styleSubcommandTerm(str) {
|
|
1245
|
+
return str.split(" ").map((word) => {
|
|
1246
|
+
if (word === "[options]")
|
|
1247
|
+
return this.styleOptionText(word);
|
|
1248
|
+
if (word[0] === "[" || word[0] === "<")
|
|
1249
|
+
return this.styleArgumentText(word);
|
|
1250
|
+
return this.styleSubcommandText(word);
|
|
1251
|
+
}).join(" ");
|
|
1252
|
+
}
|
|
1253
|
+
styleArgumentTerm(str) {
|
|
1254
|
+
return this.styleArgumentText(str);
|
|
1255
|
+
}
|
|
1256
|
+
styleOptionText(str) {
|
|
1257
|
+
return str;
|
|
1258
|
+
}
|
|
1259
|
+
styleArgumentText(str) {
|
|
1260
|
+
return str;
|
|
1261
|
+
}
|
|
1262
|
+
styleSubcommandText(str) {
|
|
1263
|
+
return str;
|
|
1264
|
+
}
|
|
1265
|
+
styleCommandText(str) {
|
|
1266
|
+
return str;
|
|
1267
|
+
}
|
|
1268
|
+
padWidth(cmd, helper) {
|
|
1269
|
+
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
1270
|
+
}
|
|
1271
|
+
preformatted(str) {
|
|
1272
|
+
return /\n[^\S\r\n]/.test(str);
|
|
1273
|
+
}
|
|
1274
|
+
formatItem(term, termWidth, description, helper) {
|
|
1275
|
+
const itemIndent = 2;
|
|
1276
|
+
const itemIndentStr = " ".repeat(itemIndent);
|
|
1277
|
+
if (!description)
|
|
1278
|
+
return itemIndentStr + term;
|
|
1279
|
+
const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
|
|
1280
|
+
const spacerWidth = 2;
|
|
1281
|
+
const helpWidth = this.helpWidth ?? 80;
|
|
1282
|
+
const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
|
|
1283
|
+
let formattedDescription;
|
|
1284
|
+
if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
|
|
1285
|
+
formattedDescription = description;
|
|
1286
|
+
} else {
|
|
1287
|
+
const wrappedDescription = helper.boxWrap(description, remainingWidth);
|
|
1288
|
+
formattedDescription = wrappedDescription.replace(/\n/g, `
|
|
1289
|
+
` + " ".repeat(termWidth + spacerWidth));
|
|
1290
|
+
}
|
|
1291
|
+
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
|
|
1292
|
+
${itemIndentStr}`);
|
|
1293
|
+
}
|
|
1294
|
+
boxWrap(str, width) {
|
|
1295
|
+
if (width < this.minWidthToWrap)
|
|
1296
|
+
return str;
|
|
1297
|
+
const rawLines = str.split(/\r\n|\n/);
|
|
1298
|
+
const chunkPattern = /[\s]*[^\s]+/g;
|
|
1299
|
+
const wrappedLines = [];
|
|
1300
|
+
rawLines.forEach((line) => {
|
|
1301
|
+
const chunks = line.match(chunkPattern);
|
|
1302
|
+
if (chunks === null) {
|
|
1303
|
+
wrappedLines.push("");
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
let sumChunks = [chunks.shift()];
|
|
1307
|
+
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
1308
|
+
chunks.forEach((chunk) => {
|
|
1309
|
+
const visibleWidth = this.displayWidth(chunk);
|
|
1310
|
+
if (sumWidth + visibleWidth <= width) {
|
|
1311
|
+
sumChunks.push(chunk);
|
|
1312
|
+
sumWidth += visibleWidth;
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
wrappedLines.push(sumChunks.join(""));
|
|
1316
|
+
const nextChunk = chunk.trimStart();
|
|
1317
|
+
sumChunks = [nextChunk];
|
|
1318
|
+
sumWidth = this.displayWidth(nextChunk);
|
|
1319
|
+
});
|
|
1320
|
+
wrappedLines.push(sumChunks.join(""));
|
|
1321
|
+
});
|
|
1322
|
+
return wrappedLines.join(`
|
|
1323
|
+
`);
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
function stripColor(str) {
|
|
1327
|
+
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
1328
|
+
return str.replace(sgrPattern, "");
|
|
1329
|
+
}
|
|
1330
|
+
exports.Help = Help;
|
|
1331
|
+
exports.stripColor = stripColor;
|
|
1332
|
+
});
|
|
1333
|
+
|
|
1334
|
+
// node_modules/commander/lib/option.js
|
|
1335
|
+
var require_option = __commonJS((exports) => {
|
|
1336
|
+
var { InvalidArgumentError } = require_error();
|
|
1337
|
+
|
|
1338
|
+
class Option {
|
|
1339
|
+
constructor(flags, description) {
|
|
1340
|
+
this.flags = flags;
|
|
1341
|
+
this.description = description || "";
|
|
1342
|
+
this.required = flags.includes("<");
|
|
1343
|
+
this.optional = flags.includes("[");
|
|
1344
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
1345
|
+
this.mandatory = false;
|
|
1346
|
+
const optionFlags = splitOptionFlags(flags);
|
|
1347
|
+
this.short = optionFlags.shortFlag;
|
|
1348
|
+
this.long = optionFlags.longFlag;
|
|
1349
|
+
this.negate = false;
|
|
1350
|
+
if (this.long) {
|
|
1351
|
+
this.negate = this.long.startsWith("--no-");
|
|
1352
|
+
}
|
|
1353
|
+
this.defaultValue = undefined;
|
|
1354
|
+
this.defaultValueDescription = undefined;
|
|
1355
|
+
this.presetArg = undefined;
|
|
1356
|
+
this.envVar = undefined;
|
|
1357
|
+
this.parseArg = undefined;
|
|
1358
|
+
this.hidden = false;
|
|
1359
|
+
this.argChoices = undefined;
|
|
1360
|
+
this.conflictsWith = [];
|
|
1361
|
+
this.implied = undefined;
|
|
1362
|
+
this.helpGroupHeading = undefined;
|
|
1363
|
+
}
|
|
1364
|
+
default(value, description) {
|
|
1365
|
+
this.defaultValue = value;
|
|
1366
|
+
this.defaultValueDescription = description;
|
|
1367
|
+
return this;
|
|
1368
|
+
}
|
|
1369
|
+
preset(arg) {
|
|
1370
|
+
this.presetArg = arg;
|
|
1371
|
+
return this;
|
|
1372
|
+
}
|
|
1373
|
+
conflicts(names) {
|
|
1374
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
1375
|
+
return this;
|
|
1376
|
+
}
|
|
1377
|
+
implies(impliedOptionValues) {
|
|
1378
|
+
let newImplied = impliedOptionValues;
|
|
1379
|
+
if (typeof impliedOptionValues === "string") {
|
|
1380
|
+
newImplied = { [impliedOptionValues]: true };
|
|
1381
|
+
}
|
|
1382
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
1383
|
+
return this;
|
|
1384
|
+
}
|
|
1385
|
+
env(name) {
|
|
1386
|
+
this.envVar = name;
|
|
1387
|
+
return this;
|
|
1388
|
+
}
|
|
1389
|
+
argParser(fn) {
|
|
1390
|
+
this.parseArg = fn;
|
|
1391
|
+
return this;
|
|
1392
|
+
}
|
|
1393
|
+
makeOptionMandatory(mandatory = true) {
|
|
1394
|
+
this.mandatory = !!mandatory;
|
|
1395
|
+
return this;
|
|
1396
|
+
}
|
|
1397
|
+
hideHelp(hide = true) {
|
|
1398
|
+
this.hidden = !!hide;
|
|
1399
|
+
return this;
|
|
1400
|
+
}
|
|
1401
|
+
_collectValue(value, previous) {
|
|
1402
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
1403
|
+
return [value];
|
|
1404
|
+
}
|
|
1405
|
+
previous.push(value);
|
|
1406
|
+
return previous;
|
|
1407
|
+
}
|
|
1408
|
+
choices(values) {
|
|
1409
|
+
this.argChoices = values.slice();
|
|
1410
|
+
this.parseArg = (arg, previous) => {
|
|
1411
|
+
if (!this.argChoices.includes(arg)) {
|
|
1412
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
1413
|
+
}
|
|
1414
|
+
if (this.variadic) {
|
|
1415
|
+
return this._collectValue(arg, previous);
|
|
1416
|
+
}
|
|
1417
|
+
return arg;
|
|
1418
|
+
};
|
|
1419
|
+
return this;
|
|
1420
|
+
}
|
|
1421
|
+
name() {
|
|
1422
|
+
if (this.long) {
|
|
1423
|
+
return this.long.replace(/^--/, "");
|
|
1424
|
+
}
|
|
1425
|
+
return this.short.replace(/^-/, "");
|
|
1426
|
+
}
|
|
1427
|
+
attributeName() {
|
|
1428
|
+
if (this.negate) {
|
|
1429
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
1430
|
+
}
|
|
1431
|
+
return camelcase(this.name());
|
|
1432
|
+
}
|
|
1433
|
+
helpGroup(heading) {
|
|
1434
|
+
this.helpGroupHeading = heading;
|
|
1435
|
+
return this;
|
|
1436
|
+
}
|
|
1437
|
+
is(arg) {
|
|
1438
|
+
return this.short === arg || this.long === arg;
|
|
1439
|
+
}
|
|
1440
|
+
isBoolean() {
|
|
1441
|
+
return !this.required && !this.optional && !this.negate;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
class DualOptions {
|
|
1446
|
+
constructor(options) {
|
|
1447
|
+
this.positiveOptions = new Map;
|
|
1448
|
+
this.negativeOptions = new Map;
|
|
1449
|
+
this.dualOptions = new Set;
|
|
1450
|
+
options.forEach((option) => {
|
|
1451
|
+
if (option.negate) {
|
|
1452
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
1453
|
+
} else {
|
|
1454
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
1455
|
+
}
|
|
1456
|
+
});
|
|
1457
|
+
this.negativeOptions.forEach((value, key) => {
|
|
1458
|
+
if (this.positiveOptions.has(key)) {
|
|
1459
|
+
this.dualOptions.add(key);
|
|
1460
|
+
}
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
valueFromOption(value, option) {
|
|
1464
|
+
const optionKey = option.attributeName();
|
|
1465
|
+
if (!this.dualOptions.has(optionKey))
|
|
1466
|
+
return true;
|
|
1467
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
1468
|
+
const negativeValue = preset !== undefined ? preset : false;
|
|
1469
|
+
return option.negate === (negativeValue === value);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
function camelcase(str) {
|
|
1473
|
+
return str.split("-").reduce((str2, word) => {
|
|
1474
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
function splitOptionFlags(flags) {
|
|
1478
|
+
let shortFlag;
|
|
1479
|
+
let longFlag;
|
|
1480
|
+
const shortFlagExp = /^-[^-]$/;
|
|
1481
|
+
const longFlagExp = /^--[^-]/;
|
|
1482
|
+
const flagParts = flags.split(/[ |,]+/).concat("guard");
|
|
1483
|
+
if (shortFlagExp.test(flagParts[0]))
|
|
1484
|
+
shortFlag = flagParts.shift();
|
|
1485
|
+
if (longFlagExp.test(flagParts[0]))
|
|
1486
|
+
longFlag = flagParts.shift();
|
|
1487
|
+
if (!shortFlag && shortFlagExp.test(flagParts[0]))
|
|
1488
|
+
shortFlag = flagParts.shift();
|
|
1489
|
+
if (!shortFlag && longFlagExp.test(flagParts[0])) {
|
|
1490
|
+
shortFlag = longFlag;
|
|
1491
|
+
longFlag = flagParts.shift();
|
|
1492
|
+
}
|
|
1493
|
+
if (flagParts[0].startsWith("-")) {
|
|
1494
|
+
const unsupportedFlag = flagParts[0];
|
|
1495
|
+
const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
1496
|
+
if (/^-[^-][^-]/.test(unsupportedFlag))
|
|
1497
|
+
throw new Error(`${baseError}
|
|
1498
|
+
- a short flag is a single dash and a single character
|
|
1499
|
+
- either use a single dash and a single character (for a short flag)
|
|
1500
|
+
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`);
|
|
1501
|
+
if (shortFlagExp.test(unsupportedFlag))
|
|
1502
|
+
throw new Error(`${baseError}
|
|
1503
|
+
- too many short flags`);
|
|
1504
|
+
if (longFlagExp.test(unsupportedFlag))
|
|
1505
|
+
throw new Error(`${baseError}
|
|
1506
|
+
- too many long flags`);
|
|
1507
|
+
throw new Error(`${baseError}
|
|
1508
|
+
- unrecognised flag format`);
|
|
1509
|
+
}
|
|
1510
|
+
if (shortFlag === undefined && longFlag === undefined)
|
|
1511
|
+
throw new Error(`option creation failed due to no flags found in '${flags}'.`);
|
|
1512
|
+
return { shortFlag, longFlag };
|
|
1513
|
+
}
|
|
1514
|
+
exports.Option = Option;
|
|
1515
|
+
exports.DualOptions = DualOptions;
|
|
1516
|
+
});
|
|
1517
|
+
|
|
1518
|
+
// node_modules/commander/lib/suggestSimilar.js
|
|
1519
|
+
var require_suggestSimilar = __commonJS((exports) => {
|
|
1520
|
+
var maxDistance = 3;
|
|
1521
|
+
function editDistance(a, b) {
|
|
1522
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
1523
|
+
return Math.max(a.length, b.length);
|
|
1524
|
+
const d = [];
|
|
1525
|
+
for (let i = 0;i <= a.length; i++) {
|
|
1526
|
+
d[i] = [i];
|
|
1527
|
+
}
|
|
1528
|
+
for (let j = 0;j <= b.length; j++) {
|
|
1529
|
+
d[0][j] = j;
|
|
1530
|
+
}
|
|
1531
|
+
for (let j = 1;j <= b.length; j++) {
|
|
1532
|
+
for (let i = 1;i <= a.length; i++) {
|
|
1533
|
+
let cost = 1;
|
|
1534
|
+
if (a[i - 1] === b[j - 1]) {
|
|
1535
|
+
cost = 0;
|
|
1536
|
+
} else {
|
|
1537
|
+
cost = 1;
|
|
1538
|
+
}
|
|
1539
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
1540
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
1541
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
return d[a.length][b.length];
|
|
1546
|
+
}
|
|
1547
|
+
function suggestSimilar(word, candidates) {
|
|
1548
|
+
if (!candidates || candidates.length === 0)
|
|
1549
|
+
return "";
|
|
1550
|
+
candidates = Array.from(new Set(candidates));
|
|
1551
|
+
const searchingOptions = word.startsWith("--");
|
|
1552
|
+
if (searchingOptions) {
|
|
1553
|
+
word = word.slice(2);
|
|
1554
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
1555
|
+
}
|
|
1556
|
+
let similar = [];
|
|
1557
|
+
let bestDistance = maxDistance;
|
|
1558
|
+
const minSimilarity = 0.4;
|
|
1559
|
+
candidates.forEach((candidate) => {
|
|
1560
|
+
if (candidate.length <= 1)
|
|
1561
|
+
return;
|
|
1562
|
+
const distance = editDistance(word, candidate);
|
|
1563
|
+
const length = Math.max(word.length, candidate.length);
|
|
1564
|
+
const similarity = (length - distance) / length;
|
|
1565
|
+
if (similarity > minSimilarity) {
|
|
1566
|
+
if (distance < bestDistance) {
|
|
1567
|
+
bestDistance = distance;
|
|
1568
|
+
similar = [candidate];
|
|
1569
|
+
} else if (distance === bestDistance) {
|
|
1570
|
+
similar.push(candidate);
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
});
|
|
1574
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
1575
|
+
if (searchingOptions) {
|
|
1576
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
1577
|
+
}
|
|
1578
|
+
if (similar.length > 1) {
|
|
1579
|
+
return `
|
|
1580
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
1581
|
+
}
|
|
1582
|
+
if (similar.length === 1) {
|
|
1583
|
+
return `
|
|
1584
|
+
(Did you mean ${similar[0]}?)`;
|
|
1585
|
+
}
|
|
1586
|
+
return "";
|
|
1587
|
+
}
|
|
1588
|
+
exports.suggestSimilar = suggestSimilar;
|
|
1589
|
+
});
|
|
1590
|
+
|
|
1591
|
+
// node_modules/commander/lib/command.js
|
|
1592
|
+
var require_command = __commonJS((exports) => {
|
|
1593
|
+
var EventEmitter2 = (init_events(), __toCommonJS(exports_events)).EventEmitter;
|
|
1594
|
+
var childProcess = (() => ({}));
|
|
1595
|
+
var path = (init_path(), __toCommonJS(exports_path));
|
|
1596
|
+
var fs = (() => ({}));
|
|
1597
|
+
var process2 = (init_process(), __toCommonJS(exports_process));
|
|
1598
|
+
var { Argument, humanReadableArgName } = require_argument();
|
|
1599
|
+
var { CommanderError } = require_error();
|
|
1600
|
+
var { Help, stripColor } = require_help();
|
|
1601
|
+
var { Option, DualOptions } = require_option();
|
|
1602
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
1603
|
+
|
|
1604
|
+
class Command extends EventEmitter2 {
|
|
1605
|
+
constructor(name) {
|
|
1606
|
+
super();
|
|
1607
|
+
this.commands = [];
|
|
1608
|
+
this.options = [];
|
|
1609
|
+
this.parent = null;
|
|
1610
|
+
this._allowUnknownOption = false;
|
|
1611
|
+
this._allowExcessArguments = false;
|
|
1612
|
+
this.registeredArguments = [];
|
|
1613
|
+
this._args = this.registeredArguments;
|
|
1614
|
+
this.args = [];
|
|
1615
|
+
this.rawArgs = [];
|
|
1616
|
+
this.processedArgs = [];
|
|
1617
|
+
this._scriptPath = null;
|
|
1618
|
+
this._name = name || "";
|
|
1619
|
+
this._optionValues = {};
|
|
1620
|
+
this._optionValueSources = {};
|
|
1621
|
+
this._storeOptionsAsProperties = false;
|
|
1622
|
+
this._actionHandler = null;
|
|
1623
|
+
this._executableHandler = false;
|
|
1624
|
+
this._executableFile = null;
|
|
1625
|
+
this._executableDir = null;
|
|
1626
|
+
this._defaultCommandName = null;
|
|
1627
|
+
this._exitCallback = null;
|
|
1628
|
+
this._aliases = [];
|
|
1629
|
+
this._combineFlagAndOptionalValue = true;
|
|
1630
|
+
this._description = "";
|
|
1631
|
+
this._summary = "";
|
|
1632
|
+
this._argsDescription = undefined;
|
|
1633
|
+
this._enablePositionalOptions = false;
|
|
1634
|
+
this._passThroughOptions = false;
|
|
1635
|
+
this._lifeCycleHooks = {};
|
|
1636
|
+
this._showHelpAfterError = false;
|
|
1637
|
+
this._showSuggestionAfterError = true;
|
|
1638
|
+
this._savedState = null;
|
|
1639
|
+
this._outputConfiguration = {
|
|
1640
|
+
writeOut: (str) => process2.stdout.write(str),
|
|
1641
|
+
writeErr: (str) => process2.stderr.write(str),
|
|
1642
|
+
outputError: (str, write) => write(str),
|
|
1643
|
+
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
|
|
1644
|
+
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
|
|
1645
|
+
getOutHasColors: () => useColor() ?? (process2.stdout.isTTY && process2.stdout.hasColors?.()),
|
|
1646
|
+
getErrHasColors: () => useColor() ?? (process2.stderr.isTTY && process2.stderr.hasColors?.()),
|
|
1647
|
+
stripColor: (str) => stripColor(str)
|
|
1648
|
+
};
|
|
1649
|
+
this._hidden = false;
|
|
1650
|
+
this._helpOption = undefined;
|
|
1651
|
+
this._addImplicitHelpCommand = undefined;
|
|
1652
|
+
this._helpCommand = undefined;
|
|
1653
|
+
this._helpConfiguration = {};
|
|
1654
|
+
this._helpGroupHeading = undefined;
|
|
1655
|
+
this._defaultCommandGroup = undefined;
|
|
1656
|
+
this._defaultOptionGroup = undefined;
|
|
1657
|
+
}
|
|
1658
|
+
copyInheritedSettings(sourceCommand) {
|
|
1659
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
1660
|
+
this._helpOption = sourceCommand._helpOption;
|
|
1661
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
1662
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
1663
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
1664
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
1665
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
1666
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
1667
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
1668
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
1669
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
1670
|
+
return this;
|
|
1671
|
+
}
|
|
1672
|
+
_getCommandAndAncestors() {
|
|
1673
|
+
const result = [];
|
|
1674
|
+
for (let command = this;command; command = command.parent) {
|
|
1675
|
+
result.push(command);
|
|
1676
|
+
}
|
|
1677
|
+
return result;
|
|
1678
|
+
}
|
|
1679
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
1680
|
+
let desc = actionOptsOrExecDesc;
|
|
1681
|
+
let opts = execOpts;
|
|
1682
|
+
if (typeof desc === "object" && desc !== null) {
|
|
1683
|
+
opts = desc;
|
|
1684
|
+
desc = null;
|
|
1685
|
+
}
|
|
1686
|
+
opts = opts || {};
|
|
1687
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1688
|
+
const cmd = this.createCommand(name);
|
|
1689
|
+
if (desc) {
|
|
1690
|
+
cmd.description(desc);
|
|
1691
|
+
cmd._executableHandler = true;
|
|
1692
|
+
}
|
|
1693
|
+
if (opts.isDefault)
|
|
1694
|
+
this._defaultCommandName = cmd._name;
|
|
1695
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
1696
|
+
cmd._executableFile = opts.executableFile || null;
|
|
1697
|
+
if (args)
|
|
1698
|
+
cmd.arguments(args);
|
|
1699
|
+
this._registerCommand(cmd);
|
|
1700
|
+
cmd.parent = this;
|
|
1701
|
+
cmd.copyInheritedSettings(this);
|
|
1702
|
+
if (desc)
|
|
1703
|
+
return this;
|
|
1704
|
+
return cmd;
|
|
1705
|
+
}
|
|
1706
|
+
createCommand(name) {
|
|
1707
|
+
return new Command(name);
|
|
1708
|
+
}
|
|
1709
|
+
createHelp() {
|
|
1710
|
+
return Object.assign(new Help, this.configureHelp());
|
|
1711
|
+
}
|
|
1712
|
+
configureHelp(configuration) {
|
|
1713
|
+
if (configuration === undefined)
|
|
1714
|
+
return this._helpConfiguration;
|
|
1715
|
+
this._helpConfiguration = configuration;
|
|
1716
|
+
return this;
|
|
1717
|
+
}
|
|
1718
|
+
configureOutput(configuration) {
|
|
1719
|
+
if (configuration === undefined)
|
|
1720
|
+
return this._outputConfiguration;
|
|
1721
|
+
this._outputConfiguration = {
|
|
1722
|
+
...this._outputConfiguration,
|
|
1723
|
+
...configuration
|
|
1724
|
+
};
|
|
1725
|
+
return this;
|
|
1726
|
+
}
|
|
1727
|
+
showHelpAfterError(displayHelp = true) {
|
|
1728
|
+
if (typeof displayHelp !== "string")
|
|
1729
|
+
displayHelp = !!displayHelp;
|
|
1730
|
+
this._showHelpAfterError = displayHelp;
|
|
1731
|
+
return this;
|
|
1732
|
+
}
|
|
1733
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
1734
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
1735
|
+
return this;
|
|
1736
|
+
}
|
|
1737
|
+
addCommand(cmd, opts) {
|
|
1738
|
+
if (!cmd._name) {
|
|
1739
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
1740
|
+
- specify the name in Command constructor or using .name()`);
|
|
1741
|
+
}
|
|
1742
|
+
opts = opts || {};
|
|
1743
|
+
if (opts.isDefault)
|
|
1744
|
+
this._defaultCommandName = cmd._name;
|
|
1745
|
+
if (opts.noHelp || opts.hidden)
|
|
1746
|
+
cmd._hidden = true;
|
|
1747
|
+
this._registerCommand(cmd);
|
|
1748
|
+
cmd.parent = this;
|
|
1749
|
+
cmd._checkForBrokenPassThrough();
|
|
1750
|
+
return this;
|
|
1751
|
+
}
|
|
1752
|
+
createArgument(name, description) {
|
|
1753
|
+
return new Argument(name, description);
|
|
1754
|
+
}
|
|
1755
|
+
argument(name, description, parseArg, defaultValue) {
|
|
1756
|
+
const argument = this.createArgument(name, description);
|
|
1757
|
+
if (typeof parseArg === "function") {
|
|
1758
|
+
argument.default(defaultValue).argParser(parseArg);
|
|
1759
|
+
} else {
|
|
1760
|
+
argument.default(parseArg);
|
|
1761
|
+
}
|
|
1762
|
+
this.addArgument(argument);
|
|
1763
|
+
return this;
|
|
1764
|
+
}
|
|
1765
|
+
arguments(names) {
|
|
1766
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
1767
|
+
this.argument(detail);
|
|
1768
|
+
});
|
|
1769
|
+
return this;
|
|
1770
|
+
}
|
|
1771
|
+
addArgument(argument) {
|
|
1772
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
1773
|
+
if (previousArgument?.variadic) {
|
|
1774
|
+
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
1775
|
+
}
|
|
1776
|
+
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
1777
|
+
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
1778
|
+
}
|
|
1779
|
+
this.registeredArguments.push(argument);
|
|
1780
|
+
return this;
|
|
1781
|
+
}
|
|
1782
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
1783
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
1784
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
1785
|
+
if (enableOrNameAndArgs && this._defaultCommandGroup) {
|
|
1786
|
+
this._initCommandGroup(this._getHelpCommand());
|
|
1787
|
+
}
|
|
1788
|
+
return this;
|
|
1789
|
+
}
|
|
1790
|
+
const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
1791
|
+
const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1792
|
+
const helpDescription = description ?? "display help for command";
|
|
1793
|
+
const helpCommand = this.createCommand(helpName);
|
|
1794
|
+
helpCommand.helpOption(false);
|
|
1795
|
+
if (helpArgs)
|
|
1796
|
+
helpCommand.arguments(helpArgs);
|
|
1797
|
+
if (helpDescription)
|
|
1798
|
+
helpCommand.description(helpDescription);
|
|
1799
|
+
this._addImplicitHelpCommand = true;
|
|
1800
|
+
this._helpCommand = helpCommand;
|
|
1801
|
+
if (enableOrNameAndArgs || description)
|
|
1802
|
+
this._initCommandGroup(helpCommand);
|
|
1803
|
+
return this;
|
|
1804
|
+
}
|
|
1805
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
1806
|
+
if (typeof helpCommand !== "object") {
|
|
1807
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
1808
|
+
return this;
|
|
1809
|
+
}
|
|
1810
|
+
this._addImplicitHelpCommand = true;
|
|
1811
|
+
this._helpCommand = helpCommand;
|
|
1812
|
+
this._initCommandGroup(helpCommand);
|
|
1813
|
+
return this;
|
|
1814
|
+
}
|
|
1815
|
+
_getHelpCommand() {
|
|
1816
|
+
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
1817
|
+
if (hasImplicitHelpCommand) {
|
|
1818
|
+
if (this._helpCommand === undefined) {
|
|
1819
|
+
this.helpCommand(undefined, undefined);
|
|
1820
|
+
}
|
|
1821
|
+
return this._helpCommand;
|
|
1822
|
+
}
|
|
1823
|
+
return null;
|
|
1824
|
+
}
|
|
1825
|
+
hook(event, listener) {
|
|
1826
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
1827
|
+
if (!allowedValues.includes(event)) {
|
|
1828
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
1829
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1830
|
+
}
|
|
1831
|
+
if (this._lifeCycleHooks[event]) {
|
|
1832
|
+
this._lifeCycleHooks[event].push(listener);
|
|
1833
|
+
} else {
|
|
1834
|
+
this._lifeCycleHooks[event] = [listener];
|
|
1835
|
+
}
|
|
1836
|
+
return this;
|
|
1837
|
+
}
|
|
1838
|
+
exitOverride(fn) {
|
|
1839
|
+
if (fn) {
|
|
1840
|
+
this._exitCallback = fn;
|
|
1841
|
+
} else {
|
|
1842
|
+
this._exitCallback = (err) => {
|
|
1843
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
1844
|
+
throw err;
|
|
1845
|
+
} else {}
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
return this;
|
|
1849
|
+
}
|
|
1850
|
+
_exit(exitCode, code, message) {
|
|
1851
|
+
if (this._exitCallback) {
|
|
1852
|
+
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
1853
|
+
}
|
|
1854
|
+
process2.exit(exitCode);
|
|
1855
|
+
}
|
|
1856
|
+
action(fn) {
|
|
1857
|
+
const listener = (args) => {
|
|
1858
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
1859
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
1860
|
+
if (this._storeOptionsAsProperties) {
|
|
1861
|
+
actionArgs[expectedArgsCount] = this;
|
|
1862
|
+
} else {
|
|
1863
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
1864
|
+
}
|
|
1865
|
+
actionArgs.push(this);
|
|
1866
|
+
return fn.apply(this, actionArgs);
|
|
1867
|
+
};
|
|
1868
|
+
this._actionHandler = listener;
|
|
1869
|
+
return this;
|
|
1870
|
+
}
|
|
1871
|
+
createOption(flags, description) {
|
|
1872
|
+
return new Option(flags, description);
|
|
1873
|
+
}
|
|
1874
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
1875
|
+
try {
|
|
1876
|
+
return target.parseArg(value, previous);
|
|
1877
|
+
} catch (err) {
|
|
1878
|
+
if (err.code === "commander.invalidArgument") {
|
|
1879
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
1880
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
1881
|
+
}
|
|
1882
|
+
throw err;
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
_registerOption(option) {
|
|
1886
|
+
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
1887
|
+
if (matchingOption) {
|
|
1888
|
+
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
1889
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
1890
|
+
- already used by option '${matchingOption.flags}'`);
|
|
1891
|
+
}
|
|
1892
|
+
this._initOptionGroup(option);
|
|
1893
|
+
this.options.push(option);
|
|
1894
|
+
}
|
|
1895
|
+
_registerCommand(command) {
|
|
1896
|
+
const knownBy = (cmd) => {
|
|
1897
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
1898
|
+
};
|
|
1899
|
+
const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
|
|
1900
|
+
if (alreadyUsed) {
|
|
1901
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
1902
|
+
const newCmd = knownBy(command).join("|");
|
|
1903
|
+
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
1904
|
+
}
|
|
1905
|
+
this._initCommandGroup(command);
|
|
1906
|
+
this.commands.push(command);
|
|
1907
|
+
}
|
|
1908
|
+
addOption(option) {
|
|
1909
|
+
this._registerOption(option);
|
|
1910
|
+
const oname = option.name();
|
|
1911
|
+
const name = option.attributeName();
|
|
1912
|
+
if (option.negate) {
|
|
1913
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
1914
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
1915
|
+
this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
|
|
1916
|
+
}
|
|
1917
|
+
} else if (option.defaultValue !== undefined) {
|
|
1918
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
1919
|
+
}
|
|
1920
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
1921
|
+
if (val == null && option.presetArg !== undefined) {
|
|
1922
|
+
val = option.presetArg;
|
|
1923
|
+
}
|
|
1924
|
+
const oldValue = this.getOptionValue(name);
|
|
1925
|
+
if (val !== null && option.parseArg) {
|
|
1926
|
+
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
1927
|
+
} else if (val !== null && option.variadic) {
|
|
1928
|
+
val = option._collectValue(val, oldValue);
|
|
1929
|
+
}
|
|
1930
|
+
if (val == null) {
|
|
1931
|
+
if (option.negate) {
|
|
1932
|
+
val = false;
|
|
1933
|
+
} else if (option.isBoolean() || option.optional) {
|
|
1934
|
+
val = true;
|
|
1935
|
+
} else {
|
|
1936
|
+
val = "";
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
1940
|
+
};
|
|
1941
|
+
this.on("option:" + oname, (val) => {
|
|
1942
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
1943
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
1944
|
+
});
|
|
1945
|
+
if (option.envVar) {
|
|
1946
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
1947
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
1948
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
return this;
|
|
1952
|
+
}
|
|
1953
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
1954
|
+
if (typeof flags === "object" && flags instanceof Option) {
|
|
1955
|
+
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
1956
|
+
}
|
|
1957
|
+
const option = this.createOption(flags, description);
|
|
1958
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
1959
|
+
if (typeof fn === "function") {
|
|
1960
|
+
option.default(defaultValue).argParser(fn);
|
|
1961
|
+
} else if (fn instanceof RegExp) {
|
|
1962
|
+
const regex = fn;
|
|
1963
|
+
fn = (val, def) => {
|
|
1964
|
+
const m = regex.exec(val);
|
|
1965
|
+
return m ? m[0] : def;
|
|
1966
|
+
};
|
|
1967
|
+
option.default(defaultValue).argParser(fn);
|
|
1968
|
+
} else {
|
|
1969
|
+
option.default(fn);
|
|
1970
|
+
}
|
|
1971
|
+
return this.addOption(option);
|
|
1972
|
+
}
|
|
1973
|
+
option(flags, description, parseArg, defaultValue) {
|
|
1974
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
1975
|
+
}
|
|
1976
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
1977
|
+
return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
|
|
1978
|
+
}
|
|
1979
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
1980
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
1981
|
+
return this;
|
|
1982
|
+
}
|
|
1983
|
+
allowUnknownOption(allowUnknown = true) {
|
|
1984
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
1985
|
+
return this;
|
|
1986
|
+
}
|
|
1987
|
+
allowExcessArguments(allowExcess = true) {
|
|
1988
|
+
this._allowExcessArguments = !!allowExcess;
|
|
1989
|
+
return this;
|
|
1990
|
+
}
|
|
1991
|
+
enablePositionalOptions(positional = true) {
|
|
1992
|
+
this._enablePositionalOptions = !!positional;
|
|
1993
|
+
return this;
|
|
1994
|
+
}
|
|
1995
|
+
passThroughOptions(passThrough = true) {
|
|
1996
|
+
this._passThroughOptions = !!passThrough;
|
|
1997
|
+
this._checkForBrokenPassThrough();
|
|
1998
|
+
return this;
|
|
1999
|
+
}
|
|
2000
|
+
_checkForBrokenPassThrough() {
|
|
2001
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
2002
|
+
throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
2006
|
+
if (this.options.length) {
|
|
2007
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
2008
|
+
}
|
|
2009
|
+
if (Object.keys(this._optionValues).length) {
|
|
2010
|
+
throw new Error("call .storeOptionsAsProperties() before setting option values");
|
|
2011
|
+
}
|
|
2012
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
2013
|
+
return this;
|
|
2014
|
+
}
|
|
2015
|
+
getOptionValue(key) {
|
|
2016
|
+
if (this._storeOptionsAsProperties) {
|
|
2017
|
+
return this[key];
|
|
2018
|
+
}
|
|
2019
|
+
return this._optionValues[key];
|
|
2020
|
+
}
|
|
2021
|
+
setOptionValue(key, value) {
|
|
2022
|
+
return this.setOptionValueWithSource(key, value, undefined);
|
|
2023
|
+
}
|
|
2024
|
+
setOptionValueWithSource(key, value, source) {
|
|
2025
|
+
if (this._storeOptionsAsProperties) {
|
|
2026
|
+
this[key] = value;
|
|
2027
|
+
} else {
|
|
2028
|
+
this._optionValues[key] = value;
|
|
2029
|
+
}
|
|
2030
|
+
this._optionValueSources[key] = source;
|
|
2031
|
+
return this;
|
|
2032
|
+
}
|
|
2033
|
+
getOptionValueSource(key) {
|
|
2034
|
+
return this._optionValueSources[key];
|
|
2035
|
+
}
|
|
2036
|
+
getOptionValueSourceWithGlobals(key) {
|
|
2037
|
+
let source;
|
|
2038
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2039
|
+
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
2040
|
+
source = cmd.getOptionValueSource(key);
|
|
2041
|
+
}
|
|
2042
|
+
});
|
|
2043
|
+
return source;
|
|
2044
|
+
}
|
|
2045
|
+
_prepareUserArgs(argv2, parseOptions) {
|
|
2046
|
+
if (argv2 !== undefined && !Array.isArray(argv2)) {
|
|
2047
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
2048
|
+
}
|
|
2049
|
+
parseOptions = parseOptions || {};
|
|
2050
|
+
if (argv2 === undefined && parseOptions.from === undefined) {
|
|
2051
|
+
if (process2.versions?.electron) {
|
|
2052
|
+
parseOptions.from = "electron";
|
|
2053
|
+
}
|
|
2054
|
+
const execArgv = process2.execArgv ?? [];
|
|
2055
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
2056
|
+
parseOptions.from = "eval";
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
if (argv2 === undefined) {
|
|
2060
|
+
argv2 = process2.argv;
|
|
2061
|
+
}
|
|
2062
|
+
this.rawArgs = argv2.slice();
|
|
2063
|
+
let userArgs;
|
|
2064
|
+
switch (parseOptions.from) {
|
|
2065
|
+
case undefined:
|
|
2066
|
+
case "node":
|
|
2067
|
+
this._scriptPath = argv2[1];
|
|
2068
|
+
userArgs = argv2.slice(2);
|
|
2069
|
+
break;
|
|
2070
|
+
case "electron":
|
|
2071
|
+
if (process2.defaultApp) {
|
|
2072
|
+
this._scriptPath = argv2[1];
|
|
2073
|
+
userArgs = argv2.slice(2);
|
|
2074
|
+
} else {
|
|
2075
|
+
userArgs = argv2.slice(1);
|
|
2076
|
+
}
|
|
2077
|
+
break;
|
|
2078
|
+
case "user":
|
|
2079
|
+
userArgs = argv2.slice(0);
|
|
2080
|
+
break;
|
|
2081
|
+
case "eval":
|
|
2082
|
+
userArgs = argv2.slice(1);
|
|
2083
|
+
break;
|
|
2084
|
+
default:
|
|
2085
|
+
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
2086
|
+
}
|
|
2087
|
+
if (!this._name && this._scriptPath)
|
|
2088
|
+
this.nameFromFilename(this._scriptPath);
|
|
2089
|
+
this._name = this._name || "program";
|
|
2090
|
+
return userArgs;
|
|
2091
|
+
}
|
|
2092
|
+
parse(argv2, parseOptions) {
|
|
2093
|
+
this._prepareForParse();
|
|
2094
|
+
const userArgs = this._prepareUserArgs(argv2, parseOptions);
|
|
2095
|
+
this._parseCommand([], userArgs);
|
|
2096
|
+
return this;
|
|
2097
|
+
}
|
|
2098
|
+
async parseAsync(argv2, parseOptions) {
|
|
2099
|
+
this._prepareForParse();
|
|
2100
|
+
const userArgs = this._prepareUserArgs(argv2, parseOptions);
|
|
2101
|
+
await this._parseCommand([], userArgs);
|
|
2102
|
+
return this;
|
|
2103
|
+
}
|
|
2104
|
+
_prepareForParse() {
|
|
2105
|
+
if (this._savedState === null) {
|
|
2106
|
+
this.saveStateBeforeParse();
|
|
2107
|
+
} else {
|
|
2108
|
+
this.restoreStateBeforeParse();
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
saveStateBeforeParse() {
|
|
2112
|
+
this._savedState = {
|
|
2113
|
+
_name: this._name,
|
|
2114
|
+
_optionValues: { ...this._optionValues },
|
|
2115
|
+
_optionValueSources: { ...this._optionValueSources }
|
|
2116
|
+
};
|
|
2117
|
+
}
|
|
2118
|
+
restoreStateBeforeParse() {
|
|
2119
|
+
if (this._storeOptionsAsProperties)
|
|
2120
|
+
throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
2121
|
+
- either make a new Command for each call to parse, or stop storing options as properties`);
|
|
2122
|
+
this._name = this._savedState._name;
|
|
2123
|
+
this._scriptPath = null;
|
|
2124
|
+
this.rawArgs = [];
|
|
2125
|
+
this._optionValues = { ...this._savedState._optionValues };
|
|
2126
|
+
this._optionValueSources = { ...this._savedState._optionValueSources };
|
|
2127
|
+
this.args = [];
|
|
2128
|
+
this.processedArgs = [];
|
|
2129
|
+
}
|
|
2130
|
+
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
2131
|
+
if (fs.existsSync(executableFile))
|
|
2132
|
+
return;
|
|
2133
|
+
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";
|
|
2134
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
2135
|
+
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
2136
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
2137
|
+
- ${executableDirMessage}`;
|
|
2138
|
+
throw new Error(executableMissing);
|
|
2139
|
+
}
|
|
2140
|
+
_executeSubCommand(subcommand, args) {
|
|
2141
|
+
args = args.slice();
|
|
2142
|
+
let launchWithNode = false;
|
|
2143
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
2144
|
+
function findFile(baseDir, baseName) {
|
|
2145
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
2146
|
+
if (fs.existsSync(localBin))
|
|
2147
|
+
return localBin;
|
|
2148
|
+
if (sourceExt.includes(path.extname(baseName)))
|
|
2149
|
+
return;
|
|
2150
|
+
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
2151
|
+
if (foundExt)
|
|
2152
|
+
return `${localBin}${foundExt}`;
|
|
2153
|
+
return;
|
|
2154
|
+
}
|
|
2155
|
+
this._checkForMissingMandatoryOptions();
|
|
2156
|
+
this._checkForConflictingOptions();
|
|
2157
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
2158
|
+
let executableDir = this._executableDir || "";
|
|
2159
|
+
if (this._scriptPath) {
|
|
2160
|
+
let resolvedScriptPath;
|
|
2161
|
+
try {
|
|
2162
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
2163
|
+
} catch {
|
|
2164
|
+
resolvedScriptPath = this._scriptPath;
|
|
2165
|
+
}
|
|
2166
|
+
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
2167
|
+
}
|
|
2168
|
+
if (executableDir) {
|
|
2169
|
+
let localFile = findFile(executableDir, executableFile);
|
|
2170
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
2171
|
+
const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
2172
|
+
if (legacyName !== this._name) {
|
|
2173
|
+
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
executableFile = localFile || executableFile;
|
|
2177
|
+
}
|
|
2178
|
+
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
2179
|
+
let proc;
|
|
2180
|
+
if (process2.platform !== "win32") {
|
|
2181
|
+
if (launchWithNode) {
|
|
2182
|
+
args.unshift(executableFile);
|
|
2183
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
2184
|
+
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
2185
|
+
} else {
|
|
2186
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
2187
|
+
}
|
|
2188
|
+
} else {
|
|
2189
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
2190
|
+
args.unshift(executableFile);
|
|
2191
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
2192
|
+
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
2193
|
+
}
|
|
2194
|
+
if (!proc.killed) {
|
|
2195
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
2196
|
+
signals.forEach((signal) => {
|
|
2197
|
+
process2.on(signal, () => {
|
|
2198
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
2199
|
+
proc.kill(signal);
|
|
2200
|
+
}
|
|
2201
|
+
});
|
|
2202
|
+
});
|
|
2203
|
+
}
|
|
2204
|
+
const exitCallback = this._exitCallback;
|
|
2205
|
+
proc.on("close", (code) => {
|
|
2206
|
+
code = code ?? 1;
|
|
2207
|
+
if (!exitCallback) {
|
|
2208
|
+
process2.exit(code);
|
|
2209
|
+
} else {
|
|
2210
|
+
exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
|
|
2211
|
+
}
|
|
2212
|
+
});
|
|
2213
|
+
proc.on("error", (err) => {
|
|
2214
|
+
if (err.code === "ENOENT") {
|
|
2215
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
2216
|
+
} else if (err.code === "EACCES") {
|
|
2217
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
2218
|
+
}
|
|
2219
|
+
if (!exitCallback) {
|
|
2220
|
+
process2.exit(1);
|
|
2221
|
+
} else {
|
|
2222
|
+
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
2223
|
+
wrappedError.nestedError = err;
|
|
2224
|
+
exitCallback(wrappedError);
|
|
2225
|
+
}
|
|
2226
|
+
});
|
|
2227
|
+
this.runningCommand = proc;
|
|
2228
|
+
}
|
|
2229
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
2230
|
+
const subCommand = this._findCommand(commandName);
|
|
2231
|
+
if (!subCommand)
|
|
2232
|
+
this.help({ error: true });
|
|
2233
|
+
subCommand._prepareForParse();
|
|
2234
|
+
let promiseChain;
|
|
2235
|
+
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
|
|
2236
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
2237
|
+
if (subCommand._executableHandler) {
|
|
2238
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
2239
|
+
} else {
|
|
2240
|
+
return subCommand._parseCommand(operands, unknown);
|
|
2241
|
+
}
|
|
2242
|
+
});
|
|
2243
|
+
return promiseChain;
|
|
2244
|
+
}
|
|
2245
|
+
_dispatchHelpCommand(subcommandName) {
|
|
2246
|
+
if (!subcommandName) {
|
|
2247
|
+
this.help();
|
|
2248
|
+
}
|
|
2249
|
+
const subCommand = this._findCommand(subcommandName);
|
|
2250
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
2251
|
+
subCommand.help();
|
|
2252
|
+
}
|
|
2253
|
+
return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
|
|
2254
|
+
}
|
|
2255
|
+
_checkNumberOfArguments() {
|
|
2256
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
2257
|
+
if (arg.required && this.args[i] == null) {
|
|
2258
|
+
this.missingArgument(arg.name());
|
|
2259
|
+
}
|
|
2260
|
+
});
|
|
2261
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
2262
|
+
return;
|
|
2263
|
+
}
|
|
2264
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
2265
|
+
this._excessArguments(this.args);
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
_processArguments() {
|
|
2269
|
+
const myParseArg = (argument, value, previous) => {
|
|
2270
|
+
let parsedValue = value;
|
|
2271
|
+
if (value !== null && argument.parseArg) {
|
|
2272
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
2273
|
+
parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
|
|
2274
|
+
}
|
|
2275
|
+
return parsedValue;
|
|
2276
|
+
};
|
|
2277
|
+
this._checkNumberOfArguments();
|
|
2278
|
+
const processedArgs = [];
|
|
2279
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
2280
|
+
let value = declaredArg.defaultValue;
|
|
2281
|
+
if (declaredArg.variadic) {
|
|
2282
|
+
if (index < this.args.length) {
|
|
2283
|
+
value = this.args.slice(index);
|
|
2284
|
+
if (declaredArg.parseArg) {
|
|
2285
|
+
value = value.reduce((processed, v) => {
|
|
2286
|
+
return myParseArg(declaredArg, v, processed);
|
|
2287
|
+
}, declaredArg.defaultValue);
|
|
2288
|
+
}
|
|
2289
|
+
} else if (value === undefined) {
|
|
2290
|
+
value = [];
|
|
2291
|
+
}
|
|
2292
|
+
} else if (index < this.args.length) {
|
|
2293
|
+
value = this.args[index];
|
|
2294
|
+
if (declaredArg.parseArg) {
|
|
2295
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
processedArgs[index] = value;
|
|
2299
|
+
});
|
|
2300
|
+
this.processedArgs = processedArgs;
|
|
2301
|
+
}
|
|
2302
|
+
_chainOrCall(promise, fn) {
|
|
2303
|
+
if (promise?.then && typeof promise.then === "function") {
|
|
2304
|
+
return promise.then(() => fn());
|
|
2305
|
+
}
|
|
2306
|
+
return fn();
|
|
2307
|
+
}
|
|
2308
|
+
_chainOrCallHooks(promise, event) {
|
|
2309
|
+
let result = promise;
|
|
2310
|
+
const hooks = [];
|
|
2311
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
|
|
2312
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
2313
|
+
hooks.push({ hookedCommand, callback });
|
|
2314
|
+
});
|
|
2315
|
+
});
|
|
2316
|
+
if (event === "postAction") {
|
|
2317
|
+
hooks.reverse();
|
|
2318
|
+
}
|
|
2319
|
+
hooks.forEach((hookDetail) => {
|
|
2320
|
+
result = this._chainOrCall(result, () => {
|
|
2321
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
2322
|
+
});
|
|
2323
|
+
});
|
|
2324
|
+
return result;
|
|
2325
|
+
}
|
|
2326
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
2327
|
+
let result = promise;
|
|
2328
|
+
if (this._lifeCycleHooks[event] !== undefined) {
|
|
2329
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
2330
|
+
result = this._chainOrCall(result, () => {
|
|
2331
|
+
return hook(this, subCommand);
|
|
2332
|
+
});
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2335
|
+
return result;
|
|
2336
|
+
}
|
|
2337
|
+
_parseCommand(operands, unknown) {
|
|
2338
|
+
const parsed = this.parseOptions(unknown);
|
|
2339
|
+
this._parseOptionsEnv();
|
|
2340
|
+
this._parseOptionsImplied();
|
|
2341
|
+
operands = operands.concat(parsed.operands);
|
|
2342
|
+
unknown = parsed.unknown;
|
|
2343
|
+
this.args = operands.concat(unknown);
|
|
2344
|
+
if (operands && this._findCommand(operands[0])) {
|
|
2345
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
2346
|
+
}
|
|
2347
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
2348
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
2349
|
+
}
|
|
2350
|
+
if (this._defaultCommandName) {
|
|
2351
|
+
this._outputHelpIfRequested(unknown);
|
|
2352
|
+
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
2353
|
+
}
|
|
2354
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
2355
|
+
this.help({ error: true });
|
|
2356
|
+
}
|
|
2357
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
2358
|
+
this._checkForMissingMandatoryOptions();
|
|
2359
|
+
this._checkForConflictingOptions();
|
|
2360
|
+
const checkForUnknownOptions = () => {
|
|
2361
|
+
if (parsed.unknown.length > 0) {
|
|
2362
|
+
this.unknownOption(parsed.unknown[0]);
|
|
2363
|
+
}
|
|
2364
|
+
};
|
|
2365
|
+
const commandEvent = `command:${this.name()}`;
|
|
2366
|
+
if (this._actionHandler) {
|
|
2367
|
+
checkForUnknownOptions();
|
|
2368
|
+
this._processArguments();
|
|
2369
|
+
let promiseChain;
|
|
2370
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
2371
|
+
promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
|
|
2372
|
+
if (this.parent) {
|
|
2373
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
2374
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
2375
|
+
});
|
|
2376
|
+
}
|
|
2377
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
2378
|
+
return promiseChain;
|
|
2379
|
+
}
|
|
2380
|
+
if (this.parent?.listenerCount(commandEvent)) {
|
|
2381
|
+
checkForUnknownOptions();
|
|
2382
|
+
this._processArguments();
|
|
2383
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
2384
|
+
} else if (operands.length) {
|
|
2385
|
+
if (this._findCommand("*")) {
|
|
2386
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
2387
|
+
}
|
|
2388
|
+
if (this.listenerCount("command:*")) {
|
|
2389
|
+
this.emit("command:*", operands, unknown);
|
|
2390
|
+
} else if (this.commands.length) {
|
|
2391
|
+
this.unknownCommand();
|
|
2392
|
+
} else {
|
|
2393
|
+
checkForUnknownOptions();
|
|
2394
|
+
this._processArguments();
|
|
2395
|
+
}
|
|
2396
|
+
} else if (this.commands.length) {
|
|
2397
|
+
checkForUnknownOptions();
|
|
2398
|
+
this.help({ error: true });
|
|
2399
|
+
} else {
|
|
2400
|
+
checkForUnknownOptions();
|
|
2401
|
+
this._processArguments();
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
_findCommand(name) {
|
|
2405
|
+
if (!name)
|
|
2406
|
+
return;
|
|
2407
|
+
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
2408
|
+
}
|
|
2409
|
+
_findOption(arg) {
|
|
2410
|
+
return this.options.find((option) => option.is(arg));
|
|
2411
|
+
}
|
|
2412
|
+
_checkForMissingMandatoryOptions() {
|
|
2413
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2414
|
+
cmd.options.forEach((anOption) => {
|
|
2415
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
|
|
2416
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
2417
|
+
}
|
|
2418
|
+
});
|
|
2419
|
+
});
|
|
2420
|
+
}
|
|
2421
|
+
_checkForConflictingLocalOptions() {
|
|
2422
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
2423
|
+
const optionKey = option.attributeName();
|
|
2424
|
+
if (this.getOptionValue(optionKey) === undefined) {
|
|
2425
|
+
return false;
|
|
2426
|
+
}
|
|
2427
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
2428
|
+
});
|
|
2429
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
2430
|
+
optionsWithConflicting.forEach((option) => {
|
|
2431
|
+
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
2432
|
+
if (conflictingAndDefined) {
|
|
2433
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
2434
|
+
}
|
|
2435
|
+
});
|
|
2436
|
+
}
|
|
2437
|
+
_checkForConflictingOptions() {
|
|
2438
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2439
|
+
cmd._checkForConflictingLocalOptions();
|
|
2440
|
+
});
|
|
2441
|
+
}
|
|
2442
|
+
parseOptions(args) {
|
|
2443
|
+
const operands = [];
|
|
2444
|
+
const unknown = [];
|
|
2445
|
+
let dest = operands;
|
|
2446
|
+
function maybeOption(arg) {
|
|
2447
|
+
return arg.length > 1 && arg[0] === "-";
|
|
2448
|
+
}
|
|
2449
|
+
const negativeNumberArg = (arg) => {
|
|
2450
|
+
if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg))
|
|
2451
|
+
return false;
|
|
2452
|
+
return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
|
|
2453
|
+
};
|
|
2454
|
+
let activeVariadicOption = null;
|
|
2455
|
+
let activeGroup = null;
|
|
2456
|
+
let i = 0;
|
|
2457
|
+
while (i < args.length || activeGroup) {
|
|
2458
|
+
const arg = activeGroup ?? args[i++];
|
|
2459
|
+
activeGroup = null;
|
|
2460
|
+
if (arg === "--") {
|
|
2461
|
+
if (dest === unknown)
|
|
2462
|
+
dest.push(arg);
|
|
2463
|
+
dest.push(...args.slice(i));
|
|
2464
|
+
break;
|
|
2465
|
+
}
|
|
2466
|
+
if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
|
|
2467
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
2468
|
+
continue;
|
|
2469
|
+
}
|
|
2470
|
+
activeVariadicOption = null;
|
|
2471
|
+
if (maybeOption(arg)) {
|
|
2472
|
+
const option = this._findOption(arg);
|
|
2473
|
+
if (option) {
|
|
2474
|
+
if (option.required) {
|
|
2475
|
+
const value = args[i++];
|
|
2476
|
+
if (value === undefined)
|
|
2477
|
+
this.optionMissingArgument(option);
|
|
2478
|
+
this.emit(`option:${option.name()}`, value);
|
|
2479
|
+
} else if (option.optional) {
|
|
2480
|
+
let value = null;
|
|
2481
|
+
if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
|
|
2482
|
+
value = args[i++];
|
|
2483
|
+
}
|
|
2484
|
+
this.emit(`option:${option.name()}`, value);
|
|
2485
|
+
} else {
|
|
2486
|
+
this.emit(`option:${option.name()}`);
|
|
2487
|
+
}
|
|
2488
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
2489
|
+
continue;
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
2493
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
2494
|
+
if (option) {
|
|
2495
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
2496
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
2497
|
+
} else {
|
|
2498
|
+
this.emit(`option:${option.name()}`);
|
|
2499
|
+
activeGroup = `-${arg.slice(2)}`;
|
|
2500
|
+
}
|
|
2501
|
+
continue;
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
2505
|
+
const index = arg.indexOf("=");
|
|
2506
|
+
const option = this._findOption(arg.slice(0, index));
|
|
2507
|
+
if (option && (option.required || option.optional)) {
|
|
2508
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
2509
|
+
continue;
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
|
|
2513
|
+
dest = unknown;
|
|
2514
|
+
}
|
|
2515
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
2516
|
+
if (this._findCommand(arg)) {
|
|
2517
|
+
operands.push(arg);
|
|
2518
|
+
unknown.push(...args.slice(i));
|
|
2519
|
+
break;
|
|
2520
|
+
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
2521
|
+
operands.push(arg, ...args.slice(i));
|
|
2522
|
+
break;
|
|
2523
|
+
} else if (this._defaultCommandName) {
|
|
2524
|
+
unknown.push(arg, ...args.slice(i));
|
|
2525
|
+
break;
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
if (this._passThroughOptions) {
|
|
2529
|
+
dest.push(arg, ...args.slice(i));
|
|
2530
|
+
break;
|
|
2531
|
+
}
|
|
2532
|
+
dest.push(arg);
|
|
2533
|
+
}
|
|
2534
|
+
return { operands, unknown };
|
|
2535
|
+
}
|
|
2536
|
+
opts() {
|
|
2537
|
+
if (this._storeOptionsAsProperties) {
|
|
2538
|
+
const result = {};
|
|
2539
|
+
const len = this.options.length;
|
|
2540
|
+
for (let i = 0;i < len; i++) {
|
|
2541
|
+
const key = this.options[i].attributeName();
|
|
2542
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
2543
|
+
}
|
|
2544
|
+
return result;
|
|
2545
|
+
}
|
|
2546
|
+
return this._optionValues;
|
|
2547
|
+
}
|
|
2548
|
+
optsWithGlobals() {
|
|
2549
|
+
return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
2550
|
+
}
|
|
2551
|
+
error(message, errorOptions) {
|
|
2552
|
+
this._outputConfiguration.outputError(`${message}
|
|
2553
|
+
`, this._outputConfiguration.writeErr);
|
|
2554
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
2555
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
2556
|
+
`);
|
|
2557
|
+
} else if (this._showHelpAfterError) {
|
|
2558
|
+
this._outputConfiguration.writeErr(`
|
|
2559
|
+
`);
|
|
2560
|
+
this.outputHelp({ error: true });
|
|
2561
|
+
}
|
|
2562
|
+
const config = errorOptions || {};
|
|
2563
|
+
const exitCode = config.exitCode || 1;
|
|
2564
|
+
const code = config.code || "commander.error";
|
|
2565
|
+
this._exit(exitCode, code, message);
|
|
2566
|
+
}
|
|
2567
|
+
_parseOptionsEnv() {
|
|
2568
|
+
this.options.forEach((option) => {
|
|
2569
|
+
if (option.envVar && option.envVar in process2.env) {
|
|
2570
|
+
const optionKey = option.attributeName();
|
|
2571
|
+
if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
2572
|
+
if (option.required || option.optional) {
|
|
2573
|
+
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
2574
|
+
} else {
|
|
2575
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
});
|
|
2580
|
+
}
|
|
2581
|
+
_parseOptionsImplied() {
|
|
2582
|
+
const dualHelper = new DualOptions(this.options);
|
|
2583
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
2584
|
+
return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
2585
|
+
};
|
|
2586
|
+
this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
2587
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
2588
|
+
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
2589
|
+
});
|
|
2590
|
+
});
|
|
2591
|
+
}
|
|
2592
|
+
missingArgument(name) {
|
|
2593
|
+
const message = `error: missing required argument '${name}'`;
|
|
2594
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
2595
|
+
}
|
|
2596
|
+
optionMissingArgument(option) {
|
|
2597
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
2598
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
2599
|
+
}
|
|
2600
|
+
missingMandatoryOptionValue(option) {
|
|
2601
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
2602
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
2603
|
+
}
|
|
2604
|
+
_conflictingOption(option, conflictingOption) {
|
|
2605
|
+
const findBestOptionFromValue = (option2) => {
|
|
2606
|
+
const optionKey = option2.attributeName();
|
|
2607
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
2608
|
+
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
2609
|
+
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
2610
|
+
if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
|
|
2611
|
+
return negativeOption;
|
|
2612
|
+
}
|
|
2613
|
+
return positiveOption || option2;
|
|
2614
|
+
};
|
|
2615
|
+
const getErrorMessage = (option2) => {
|
|
2616
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
2617
|
+
const optionKey = bestOption.attributeName();
|
|
2618
|
+
const source = this.getOptionValueSource(optionKey);
|
|
2619
|
+
if (source === "env") {
|
|
2620
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
2621
|
+
}
|
|
2622
|
+
return `option '${bestOption.flags}'`;
|
|
2623
|
+
};
|
|
2624
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
2625
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
2626
|
+
}
|
|
2627
|
+
unknownOption(flag) {
|
|
2628
|
+
if (this._allowUnknownOption)
|
|
2629
|
+
return;
|
|
2630
|
+
let suggestion = "";
|
|
2631
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
2632
|
+
let candidateFlags = [];
|
|
2633
|
+
let command = this;
|
|
2634
|
+
do {
|
|
2635
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
2636
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
2637
|
+
command = command.parent;
|
|
2638
|
+
} while (command && !command._enablePositionalOptions);
|
|
2639
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
2640
|
+
}
|
|
2641
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
2642
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
2643
|
+
}
|
|
2644
|
+
_excessArguments(receivedArgs) {
|
|
2645
|
+
if (this._allowExcessArguments)
|
|
2646
|
+
return;
|
|
2647
|
+
const expected = this.registeredArguments.length;
|
|
2648
|
+
const s = expected === 1 ? "" : "s";
|
|
2649
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
2650
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
2651
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
2652
|
+
}
|
|
2653
|
+
unknownCommand() {
|
|
2654
|
+
const unknownName = this.args[0];
|
|
2655
|
+
let suggestion = "";
|
|
2656
|
+
if (this._showSuggestionAfterError) {
|
|
2657
|
+
const candidateNames = [];
|
|
2658
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
2659
|
+
candidateNames.push(command.name());
|
|
2660
|
+
if (command.alias())
|
|
2661
|
+
candidateNames.push(command.alias());
|
|
2662
|
+
});
|
|
2663
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
2664
|
+
}
|
|
2665
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
2666
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
2667
|
+
}
|
|
2668
|
+
version(str, flags, description) {
|
|
2669
|
+
if (str === undefined)
|
|
2670
|
+
return this._version;
|
|
2671
|
+
this._version = str;
|
|
2672
|
+
flags = flags || "-V, --version";
|
|
2673
|
+
description = description || "output the version number";
|
|
2674
|
+
const versionOption = this.createOption(flags, description);
|
|
2675
|
+
this._versionOptionName = versionOption.attributeName();
|
|
2676
|
+
this._registerOption(versionOption);
|
|
2677
|
+
this.on("option:" + versionOption.name(), () => {
|
|
2678
|
+
this._outputConfiguration.writeOut(`${str}
|
|
2679
|
+
`);
|
|
2680
|
+
this._exit(0, "commander.version", str);
|
|
2681
|
+
});
|
|
2682
|
+
return this;
|
|
2683
|
+
}
|
|
2684
|
+
description(str, argsDescription) {
|
|
2685
|
+
if (str === undefined && argsDescription === undefined)
|
|
2686
|
+
return this._description;
|
|
2687
|
+
this._description = str;
|
|
2688
|
+
if (argsDescription) {
|
|
2689
|
+
this._argsDescription = argsDescription;
|
|
2690
|
+
}
|
|
2691
|
+
return this;
|
|
2692
|
+
}
|
|
2693
|
+
summary(str) {
|
|
2694
|
+
if (str === undefined)
|
|
2695
|
+
return this._summary;
|
|
2696
|
+
this._summary = str;
|
|
2697
|
+
return this;
|
|
2698
|
+
}
|
|
2699
|
+
alias(alias) {
|
|
2700
|
+
if (alias === undefined)
|
|
2701
|
+
return this._aliases[0];
|
|
2702
|
+
let command = this;
|
|
2703
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
2704
|
+
command = this.commands[this.commands.length - 1];
|
|
2705
|
+
}
|
|
2706
|
+
if (alias === command._name)
|
|
2707
|
+
throw new Error("Command alias can't be the same as its name");
|
|
2708
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
2709
|
+
if (matchingCommand) {
|
|
2710
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
2711
|
+
throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
|
|
2712
|
+
}
|
|
2713
|
+
command._aliases.push(alias);
|
|
2714
|
+
return this;
|
|
2715
|
+
}
|
|
2716
|
+
aliases(aliases) {
|
|
2717
|
+
if (aliases === undefined)
|
|
2718
|
+
return this._aliases;
|
|
2719
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
2720
|
+
return this;
|
|
2721
|
+
}
|
|
2722
|
+
usage(str) {
|
|
2723
|
+
if (str === undefined) {
|
|
2724
|
+
if (this._usage)
|
|
2725
|
+
return this._usage;
|
|
2726
|
+
const args = this.registeredArguments.map((arg) => {
|
|
2727
|
+
return humanReadableArgName(arg);
|
|
2728
|
+
});
|
|
2729
|
+
return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
|
|
2730
|
+
}
|
|
2731
|
+
this._usage = str;
|
|
2732
|
+
return this;
|
|
2733
|
+
}
|
|
2734
|
+
name(str) {
|
|
2735
|
+
if (str === undefined)
|
|
2736
|
+
return this._name;
|
|
2737
|
+
this._name = str;
|
|
2738
|
+
return this;
|
|
2739
|
+
}
|
|
2740
|
+
helpGroup(heading) {
|
|
2741
|
+
if (heading === undefined)
|
|
2742
|
+
return this._helpGroupHeading ?? "";
|
|
2743
|
+
this._helpGroupHeading = heading;
|
|
2744
|
+
return this;
|
|
2745
|
+
}
|
|
2746
|
+
commandsGroup(heading) {
|
|
2747
|
+
if (heading === undefined)
|
|
2748
|
+
return this._defaultCommandGroup ?? "";
|
|
2749
|
+
this._defaultCommandGroup = heading;
|
|
2750
|
+
return this;
|
|
2751
|
+
}
|
|
2752
|
+
optionsGroup(heading) {
|
|
2753
|
+
if (heading === undefined)
|
|
2754
|
+
return this._defaultOptionGroup ?? "";
|
|
2755
|
+
this._defaultOptionGroup = heading;
|
|
2756
|
+
return this;
|
|
2757
|
+
}
|
|
2758
|
+
_initOptionGroup(option) {
|
|
2759
|
+
if (this._defaultOptionGroup && !option.helpGroupHeading)
|
|
2760
|
+
option.helpGroup(this._defaultOptionGroup);
|
|
2761
|
+
}
|
|
2762
|
+
_initCommandGroup(cmd) {
|
|
2763
|
+
if (this._defaultCommandGroup && !cmd.helpGroup())
|
|
2764
|
+
cmd.helpGroup(this._defaultCommandGroup);
|
|
2765
|
+
}
|
|
2766
|
+
nameFromFilename(filename) {
|
|
2767
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
2768
|
+
return this;
|
|
2769
|
+
}
|
|
2770
|
+
executableDir(path2) {
|
|
2771
|
+
if (path2 === undefined)
|
|
2772
|
+
return this._executableDir;
|
|
2773
|
+
this._executableDir = path2;
|
|
2774
|
+
return this;
|
|
2775
|
+
}
|
|
2776
|
+
helpInformation(contextOptions) {
|
|
2777
|
+
const helper = this.createHelp();
|
|
2778
|
+
const context = this._getOutputContext(contextOptions);
|
|
2779
|
+
helper.prepareContext({
|
|
2780
|
+
error: context.error,
|
|
2781
|
+
helpWidth: context.helpWidth,
|
|
2782
|
+
outputHasColors: context.hasColors
|
|
2783
|
+
});
|
|
2784
|
+
const text = helper.formatHelp(this, helper);
|
|
2785
|
+
if (context.hasColors)
|
|
2786
|
+
return text;
|
|
2787
|
+
return this._outputConfiguration.stripColor(text);
|
|
2788
|
+
}
|
|
2789
|
+
_getOutputContext(contextOptions) {
|
|
2790
|
+
contextOptions = contextOptions || {};
|
|
2791
|
+
const error = !!contextOptions.error;
|
|
2792
|
+
let baseWrite;
|
|
2793
|
+
let hasColors;
|
|
2794
|
+
let helpWidth;
|
|
2795
|
+
if (error) {
|
|
2796
|
+
baseWrite = (str) => this._outputConfiguration.writeErr(str);
|
|
2797
|
+
hasColors = this._outputConfiguration.getErrHasColors();
|
|
2798
|
+
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
2799
|
+
} else {
|
|
2800
|
+
baseWrite = (str) => this._outputConfiguration.writeOut(str);
|
|
2801
|
+
hasColors = this._outputConfiguration.getOutHasColors();
|
|
2802
|
+
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
2803
|
+
}
|
|
2804
|
+
const write = (str) => {
|
|
2805
|
+
if (!hasColors)
|
|
2806
|
+
str = this._outputConfiguration.stripColor(str);
|
|
2807
|
+
return baseWrite(str);
|
|
2808
|
+
};
|
|
2809
|
+
return { error, write, hasColors, helpWidth };
|
|
2810
|
+
}
|
|
2811
|
+
outputHelp(contextOptions) {
|
|
2812
|
+
let deprecatedCallback;
|
|
2813
|
+
if (typeof contextOptions === "function") {
|
|
2814
|
+
deprecatedCallback = contextOptions;
|
|
2815
|
+
contextOptions = undefined;
|
|
2816
|
+
}
|
|
2817
|
+
const outputContext = this._getOutputContext(contextOptions);
|
|
2818
|
+
const eventContext = {
|
|
2819
|
+
error: outputContext.error,
|
|
2820
|
+
write: outputContext.write,
|
|
2821
|
+
command: this
|
|
2822
|
+
};
|
|
2823
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
|
|
2824
|
+
this.emit("beforeHelp", eventContext);
|
|
2825
|
+
let helpInformation = this.helpInformation({ error: outputContext.error });
|
|
2826
|
+
if (deprecatedCallback) {
|
|
2827
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
2828
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
2829
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
outputContext.write(helpInformation);
|
|
2833
|
+
if (this._getHelpOption()?.long) {
|
|
2834
|
+
this.emit(this._getHelpOption().long);
|
|
2835
|
+
}
|
|
2836
|
+
this.emit("afterHelp", eventContext);
|
|
2837
|
+
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", eventContext));
|
|
2838
|
+
}
|
|
2839
|
+
helpOption(flags, description) {
|
|
2840
|
+
if (typeof flags === "boolean") {
|
|
2841
|
+
if (flags) {
|
|
2842
|
+
if (this._helpOption === null)
|
|
2843
|
+
this._helpOption = undefined;
|
|
2844
|
+
if (this._defaultOptionGroup) {
|
|
2845
|
+
this._initOptionGroup(this._getHelpOption());
|
|
2846
|
+
}
|
|
2847
|
+
} else {
|
|
2848
|
+
this._helpOption = null;
|
|
2849
|
+
}
|
|
2850
|
+
return this;
|
|
2851
|
+
}
|
|
2852
|
+
this._helpOption = this.createOption(flags ?? "-h, --help", description ?? "display help for command");
|
|
2853
|
+
if (flags || description)
|
|
2854
|
+
this._initOptionGroup(this._helpOption);
|
|
2855
|
+
return this;
|
|
2856
|
+
}
|
|
2857
|
+
_getHelpOption() {
|
|
2858
|
+
if (this._helpOption === undefined) {
|
|
2859
|
+
this.helpOption(undefined, undefined);
|
|
2860
|
+
}
|
|
2861
|
+
return this._helpOption;
|
|
2862
|
+
}
|
|
2863
|
+
addHelpOption(option) {
|
|
2864
|
+
this._helpOption = option;
|
|
2865
|
+
this._initOptionGroup(option);
|
|
2866
|
+
return this;
|
|
2867
|
+
}
|
|
2868
|
+
help(contextOptions) {
|
|
2869
|
+
this.outputHelp(contextOptions);
|
|
2870
|
+
let exitCode = Number(process2.exitCode ?? 0);
|
|
2871
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
2872
|
+
exitCode = 1;
|
|
2873
|
+
}
|
|
2874
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
2875
|
+
}
|
|
2876
|
+
addHelpText(position, text) {
|
|
2877
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
2878
|
+
if (!allowedValues.includes(position)) {
|
|
2879
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
2880
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
2881
|
+
}
|
|
2882
|
+
const helpEvent = `${position}Help`;
|
|
2883
|
+
this.on(helpEvent, (context) => {
|
|
2884
|
+
let helpStr;
|
|
2885
|
+
if (typeof text === "function") {
|
|
2886
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
2887
|
+
} else {
|
|
2888
|
+
helpStr = text;
|
|
2889
|
+
}
|
|
2890
|
+
if (helpStr) {
|
|
2891
|
+
context.write(`${helpStr}
|
|
2892
|
+
`);
|
|
2893
|
+
}
|
|
2894
|
+
});
|
|
2895
|
+
return this;
|
|
2896
|
+
}
|
|
2897
|
+
_outputHelpIfRequested(args) {
|
|
2898
|
+
const helpOption = this._getHelpOption();
|
|
2899
|
+
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
2900
|
+
if (helpRequested) {
|
|
2901
|
+
this.outputHelp();
|
|
2902
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
function incrementNodeInspectorPort(args) {
|
|
2907
|
+
return args.map((arg) => {
|
|
2908
|
+
if (!arg.startsWith("--inspect")) {
|
|
2909
|
+
return arg;
|
|
2910
|
+
}
|
|
2911
|
+
let debugOption;
|
|
2912
|
+
let debugHost = "127.0.0.1";
|
|
2913
|
+
let debugPort = "9229";
|
|
2914
|
+
let match;
|
|
2915
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
2916
|
+
debugOption = match[1];
|
|
2917
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
2918
|
+
debugOption = match[1];
|
|
2919
|
+
if (/^\d+$/.test(match[3])) {
|
|
2920
|
+
debugPort = match[3];
|
|
2921
|
+
} else {
|
|
2922
|
+
debugHost = match[3];
|
|
2923
|
+
}
|
|
2924
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
2925
|
+
debugOption = match[1];
|
|
2926
|
+
debugHost = match[3];
|
|
2927
|
+
debugPort = match[4];
|
|
2928
|
+
}
|
|
2929
|
+
if (debugOption && debugPort !== "0") {
|
|
2930
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
2931
|
+
}
|
|
2932
|
+
return arg;
|
|
2933
|
+
});
|
|
2934
|
+
}
|
|
2935
|
+
function useColor() {
|
|
2936
|
+
if (process2.env.NO_COLOR || process2.env.FORCE_COLOR === "0" || process2.env.FORCE_COLOR === "false")
|
|
2937
|
+
return false;
|
|
2938
|
+
if (process2.env.FORCE_COLOR || process2.env.CLICOLOR_FORCE !== undefined)
|
|
2939
|
+
return true;
|
|
2940
|
+
return;
|
|
2941
|
+
}
|
|
2942
|
+
exports.Command = Command;
|
|
2943
|
+
exports.useColor = useColor;
|
|
2944
|
+
});
|
|
2945
|
+
|
|
2946
|
+
// node_modules/commander/index.js
|
|
2947
|
+
var require_commander = __commonJS((exports) => {
|
|
2948
|
+
var { Argument } = require_argument();
|
|
2949
|
+
var { Command } = require_command();
|
|
2950
|
+
var { CommanderError, InvalidArgumentError } = require_error();
|
|
2951
|
+
var { Help } = require_help();
|
|
2952
|
+
var { Option } = require_option();
|
|
2953
|
+
exports.program = new Command;
|
|
2954
|
+
exports.createCommand = (name) => new Command(name);
|
|
2955
|
+
exports.createOption = (flags, description) => new Option(flags, description);
|
|
2956
|
+
exports.createArgument = (name, description) => new Argument(name, description);
|
|
2957
|
+
exports.Command = Command;
|
|
2958
|
+
exports.Option = Option;
|
|
2959
|
+
exports.Argument = Argument;
|
|
2960
|
+
exports.Help = Help;
|
|
2961
|
+
exports.CommanderError = CommanderError;
|
|
2962
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
2963
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
2964
|
+
});
|
|
2965
|
+
|
|
2966
|
+
// node_modules/@commander-js/extra-typings/index.js
|
|
2967
|
+
var require_extra_typings = __commonJS((exports, module) => {
|
|
2968
|
+
var commander = require_commander();
|
|
2969
|
+
exports = module.exports = {};
|
|
2970
|
+
exports.program = new commander.Command;
|
|
2971
|
+
exports.Argument = commander.Argument;
|
|
2972
|
+
exports.Command = commander.Command;
|
|
2973
|
+
exports.CommanderError = commander.CommanderError;
|
|
2974
|
+
exports.Help = commander.Help;
|
|
2975
|
+
exports.InvalidArgumentError = commander.InvalidArgumentError;
|
|
2976
|
+
exports.InvalidOptionArgumentError = commander.InvalidArgumentError;
|
|
2977
|
+
exports.Option = commander.Option;
|
|
2978
|
+
exports.createCommand = (name) => new commander.Command(name);
|
|
2979
|
+
exports.createOption = (flags, description) => new commander.Option(flags, description);
|
|
2980
|
+
exports.createArgument = (name, description) => new commander.Argument(name, description);
|
|
2981
|
+
});
|
|
2982
|
+
|
|
2983
|
+
// node_modules/@commander-js/extra-typings/esm.mjs
|
|
2984
|
+
var import__ = __toESM(require_extra_typings(), 1);
|
|
2985
|
+
var {
|
|
2986
|
+
program,
|
|
2987
|
+
createCommand,
|
|
2988
|
+
createArgument,
|
|
2989
|
+
createOption,
|
|
2990
|
+
CommanderError,
|
|
2991
|
+
InvalidArgumentError,
|
|
2992
|
+
InvalidOptionArgumentError,
|
|
2993
|
+
Command,
|
|
2994
|
+
Argument,
|
|
2995
|
+
Option,
|
|
2996
|
+
Help
|
|
2997
|
+
} = import__.default;
|
|
2998
|
+
|
|
2999
|
+
// node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
3000
|
+
var ANSI_BACKGROUND_OFFSET = 10;
|
|
3001
|
+
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
3002
|
+
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
3003
|
+
var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
|
|
3004
|
+
var styles = {
|
|
3005
|
+
modifier: {
|
|
3006
|
+
reset: [0, 0],
|
|
3007
|
+
bold: [1, 22],
|
|
3008
|
+
dim: [2, 22],
|
|
3009
|
+
italic: [3, 23],
|
|
3010
|
+
underline: [4, 24],
|
|
3011
|
+
overline: [53, 55],
|
|
3012
|
+
inverse: [7, 27],
|
|
3013
|
+
hidden: [8, 28],
|
|
3014
|
+
strikethrough: [9, 29]
|
|
3015
|
+
},
|
|
3016
|
+
color: {
|
|
3017
|
+
black: [30, 39],
|
|
3018
|
+
red: [31, 39],
|
|
3019
|
+
green: [32, 39],
|
|
3020
|
+
yellow: [33, 39],
|
|
3021
|
+
blue: [34, 39],
|
|
3022
|
+
magenta: [35, 39],
|
|
3023
|
+
cyan: [36, 39],
|
|
3024
|
+
white: [37, 39],
|
|
3025
|
+
blackBright: [90, 39],
|
|
3026
|
+
gray: [90, 39],
|
|
3027
|
+
grey: [90, 39],
|
|
3028
|
+
redBright: [91, 39],
|
|
3029
|
+
greenBright: [92, 39],
|
|
3030
|
+
yellowBright: [93, 39],
|
|
3031
|
+
blueBright: [94, 39],
|
|
3032
|
+
magentaBright: [95, 39],
|
|
3033
|
+
cyanBright: [96, 39],
|
|
3034
|
+
whiteBright: [97, 39]
|
|
3035
|
+
},
|
|
3036
|
+
bgColor: {
|
|
3037
|
+
bgBlack: [40, 49],
|
|
3038
|
+
bgRed: [41, 49],
|
|
3039
|
+
bgGreen: [42, 49],
|
|
3040
|
+
bgYellow: [43, 49],
|
|
3041
|
+
bgBlue: [44, 49],
|
|
3042
|
+
bgMagenta: [45, 49],
|
|
3043
|
+
bgCyan: [46, 49],
|
|
3044
|
+
bgWhite: [47, 49],
|
|
3045
|
+
bgBlackBright: [100, 49],
|
|
3046
|
+
bgGray: [100, 49],
|
|
3047
|
+
bgGrey: [100, 49],
|
|
3048
|
+
bgRedBright: [101, 49],
|
|
3049
|
+
bgGreenBright: [102, 49],
|
|
3050
|
+
bgYellowBright: [103, 49],
|
|
3051
|
+
bgBlueBright: [104, 49],
|
|
3052
|
+
bgMagentaBright: [105, 49],
|
|
3053
|
+
bgCyanBright: [106, 49],
|
|
3054
|
+
bgWhiteBright: [107, 49]
|
|
3055
|
+
}
|
|
3056
|
+
};
|
|
3057
|
+
var modifierNames = Object.keys(styles.modifier);
|
|
3058
|
+
var foregroundColorNames = Object.keys(styles.color);
|
|
3059
|
+
var backgroundColorNames = Object.keys(styles.bgColor);
|
|
3060
|
+
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
3061
|
+
function assembleStyles() {
|
|
3062
|
+
const codes = new Map;
|
|
3063
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
3064
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
3065
|
+
styles[styleName] = {
|
|
3066
|
+
open: `\x1B[${style[0]}m`,
|
|
3067
|
+
close: `\x1B[${style[1]}m`
|
|
3068
|
+
};
|
|
3069
|
+
group[styleName] = styles[styleName];
|
|
3070
|
+
codes.set(style[0], style[1]);
|
|
3071
|
+
}
|
|
3072
|
+
Object.defineProperty(styles, groupName, {
|
|
3073
|
+
value: group,
|
|
3074
|
+
enumerable: false
|
|
3075
|
+
});
|
|
3076
|
+
}
|
|
3077
|
+
Object.defineProperty(styles, "codes", {
|
|
3078
|
+
value: codes,
|
|
3079
|
+
enumerable: false
|
|
3080
|
+
});
|
|
3081
|
+
styles.color.close = "\x1B[39m";
|
|
3082
|
+
styles.bgColor.close = "\x1B[49m";
|
|
3083
|
+
styles.color.ansi = wrapAnsi16();
|
|
3084
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
3085
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
3086
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
3087
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
3088
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
3089
|
+
Object.defineProperties(styles, {
|
|
3090
|
+
rgbToAnsi256: {
|
|
3091
|
+
value(red, green, blue) {
|
|
3092
|
+
if (red === green && green === blue) {
|
|
3093
|
+
if (red < 8) {
|
|
3094
|
+
return 16;
|
|
3095
|
+
}
|
|
3096
|
+
if (red > 248) {
|
|
3097
|
+
return 231;
|
|
3098
|
+
}
|
|
3099
|
+
return Math.round((red - 8) / 247 * 24) + 232;
|
|
3100
|
+
}
|
|
3101
|
+
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
3102
|
+
},
|
|
3103
|
+
enumerable: false
|
|
3104
|
+
},
|
|
3105
|
+
hexToRgb: {
|
|
3106
|
+
value(hex) {
|
|
3107
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
3108
|
+
if (!matches) {
|
|
3109
|
+
return [0, 0, 0];
|
|
3110
|
+
}
|
|
3111
|
+
let [colorString] = matches;
|
|
3112
|
+
if (colorString.length === 3) {
|
|
3113
|
+
colorString = [...colorString].map((character) => character + character).join("");
|
|
3114
|
+
}
|
|
3115
|
+
const integer = Number.parseInt(colorString, 16);
|
|
3116
|
+
return [
|
|
3117
|
+
integer >> 16 & 255,
|
|
3118
|
+
integer >> 8 & 255,
|
|
3119
|
+
integer & 255
|
|
3120
|
+
];
|
|
3121
|
+
},
|
|
3122
|
+
enumerable: false
|
|
3123
|
+
},
|
|
3124
|
+
hexToAnsi256: {
|
|
3125
|
+
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
3126
|
+
enumerable: false
|
|
3127
|
+
},
|
|
3128
|
+
ansi256ToAnsi: {
|
|
3129
|
+
value(code) {
|
|
3130
|
+
if (code < 8) {
|
|
3131
|
+
return 30 + code;
|
|
3132
|
+
}
|
|
3133
|
+
if (code < 16) {
|
|
3134
|
+
return 90 + (code - 8);
|
|
3135
|
+
}
|
|
3136
|
+
let red;
|
|
3137
|
+
let green;
|
|
3138
|
+
let blue;
|
|
3139
|
+
if (code >= 232) {
|
|
3140
|
+
red = ((code - 232) * 10 + 8) / 255;
|
|
3141
|
+
green = red;
|
|
3142
|
+
blue = red;
|
|
3143
|
+
} else {
|
|
3144
|
+
code -= 16;
|
|
3145
|
+
const remainder = code % 36;
|
|
3146
|
+
red = Math.floor(code / 36) / 5;
|
|
3147
|
+
green = Math.floor(remainder / 6) / 5;
|
|
3148
|
+
blue = remainder % 6 / 5;
|
|
3149
|
+
}
|
|
3150
|
+
const value = Math.max(red, green, blue) * 2;
|
|
3151
|
+
if (value === 0) {
|
|
3152
|
+
return 30;
|
|
3153
|
+
}
|
|
3154
|
+
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
3155
|
+
if (value === 2) {
|
|
3156
|
+
result += 60;
|
|
3157
|
+
}
|
|
3158
|
+
return result;
|
|
3159
|
+
},
|
|
3160
|
+
enumerable: false
|
|
3161
|
+
},
|
|
3162
|
+
rgbToAnsi: {
|
|
3163
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
3164
|
+
enumerable: false
|
|
3165
|
+
},
|
|
3166
|
+
hexToAnsi: {
|
|
3167
|
+
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
3168
|
+
enumerable: false
|
|
3169
|
+
}
|
|
3170
|
+
});
|
|
3171
|
+
return styles;
|
|
3172
|
+
}
|
|
3173
|
+
var ansiStyles = assembleStyles();
|
|
3174
|
+
var ansi_styles_default = ansiStyles;
|
|
3175
|
+
|
|
3176
|
+
// node_modules/chalk/source/vendor/supports-color/browser.js
|
|
3177
|
+
var level = (() => {
|
|
3178
|
+
if (!("navigator" in globalThis)) {
|
|
3179
|
+
return 0;
|
|
3180
|
+
}
|
|
3181
|
+
if (globalThis.navigator.userAgentData) {
|
|
3182
|
+
const brand = navigator.userAgentData.brands.find(({ brand: brand2 }) => brand2 === "Chromium");
|
|
3183
|
+
if (brand && brand.version > 93) {
|
|
3184
|
+
return 3;
|
|
3185
|
+
}
|
|
3186
|
+
}
|
|
3187
|
+
if (/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)) {
|
|
3188
|
+
return 1;
|
|
3189
|
+
}
|
|
3190
|
+
return 0;
|
|
3191
|
+
})();
|
|
3192
|
+
var colorSupport = level !== 0 && {
|
|
3193
|
+
level,
|
|
3194
|
+
hasBasic: true,
|
|
3195
|
+
has256: level >= 2,
|
|
3196
|
+
has16m: level >= 3
|
|
3197
|
+
};
|
|
3198
|
+
var supportsColor = {
|
|
3199
|
+
stdout: colorSupport,
|
|
3200
|
+
stderr: colorSupport
|
|
3201
|
+
};
|
|
3202
|
+
var browser_default = supportsColor;
|
|
3203
|
+
|
|
3204
|
+
// node_modules/chalk/source/utilities.js
|
|
3205
|
+
function stringReplaceAll(string, substring, replacer) {
|
|
3206
|
+
let index = string.indexOf(substring);
|
|
3207
|
+
if (index === -1) {
|
|
3208
|
+
return string;
|
|
3209
|
+
}
|
|
3210
|
+
const substringLength = substring.length;
|
|
3211
|
+
let endIndex = 0;
|
|
3212
|
+
let returnValue = "";
|
|
3213
|
+
do {
|
|
3214
|
+
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
3215
|
+
endIndex = index + substringLength;
|
|
3216
|
+
index = string.indexOf(substring, endIndex);
|
|
3217
|
+
} while (index !== -1);
|
|
3218
|
+
returnValue += string.slice(endIndex);
|
|
3219
|
+
return returnValue;
|
|
3220
|
+
}
|
|
3221
|
+
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
3222
|
+
let endIndex = 0;
|
|
3223
|
+
let returnValue = "";
|
|
3224
|
+
do {
|
|
3225
|
+
const gotCR = string[index - 1] === "\r";
|
|
3226
|
+
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? `\r
|
|
3227
|
+
` : `
|
|
3228
|
+
`) + postfix;
|
|
3229
|
+
endIndex = index + 1;
|
|
3230
|
+
index = string.indexOf(`
|
|
3231
|
+
`, endIndex);
|
|
3232
|
+
} while (index !== -1);
|
|
3233
|
+
returnValue += string.slice(endIndex);
|
|
3234
|
+
return returnValue;
|
|
3235
|
+
}
|
|
3236
|
+
|
|
3237
|
+
// node_modules/chalk/source/index.js
|
|
3238
|
+
var { stdout: stdoutColor, stderr: stderrColor } = browser_default;
|
|
3239
|
+
var GENERATOR = Symbol("GENERATOR");
|
|
3240
|
+
var STYLER = Symbol("STYLER");
|
|
3241
|
+
var IS_EMPTY = Symbol("IS_EMPTY");
|
|
3242
|
+
var levelMapping = [
|
|
3243
|
+
"ansi",
|
|
3244
|
+
"ansi",
|
|
3245
|
+
"ansi256",
|
|
3246
|
+
"ansi16m"
|
|
3247
|
+
];
|
|
3248
|
+
var styles2 = Object.create(null);
|
|
3249
|
+
var applyOptions = (object, options = {}) => {
|
|
3250
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
3251
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
3252
|
+
}
|
|
3253
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
3254
|
+
object.level = options.level === undefined ? colorLevel : options.level;
|
|
3255
|
+
};
|
|
3256
|
+
var chalkFactory = (options) => {
|
|
3257
|
+
const chalk = (...strings) => strings.join(" ");
|
|
3258
|
+
applyOptions(chalk, options);
|
|
3259
|
+
Object.setPrototypeOf(chalk, createChalk.prototype);
|
|
3260
|
+
return chalk;
|
|
3261
|
+
};
|
|
3262
|
+
function createChalk(options) {
|
|
3263
|
+
return chalkFactory(options);
|
|
3264
|
+
}
|
|
3265
|
+
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
3266
|
+
for (const [styleName, style] of Object.entries(ansi_styles_default)) {
|
|
3267
|
+
styles2[styleName] = {
|
|
3268
|
+
get() {
|
|
3269
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
3270
|
+
Object.defineProperty(this, styleName, { value: builder });
|
|
3271
|
+
return builder;
|
|
3272
|
+
}
|
|
3273
|
+
};
|
|
3274
|
+
}
|
|
3275
|
+
styles2.visible = {
|
|
3276
|
+
get() {
|
|
3277
|
+
const builder = createBuilder(this, this[STYLER], true);
|
|
3278
|
+
Object.defineProperty(this, "visible", { value: builder });
|
|
3279
|
+
return builder;
|
|
3280
|
+
}
|
|
3281
|
+
};
|
|
3282
|
+
var getModelAnsi = (model, level2, type, ...arguments_) => {
|
|
3283
|
+
if (model === "rgb") {
|
|
3284
|
+
if (level2 === "ansi16m") {
|
|
3285
|
+
return ansi_styles_default[type].ansi16m(...arguments_);
|
|
3286
|
+
}
|
|
3287
|
+
if (level2 === "ansi256") {
|
|
3288
|
+
return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
|
|
3289
|
+
}
|
|
3290
|
+
return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
|
|
3291
|
+
}
|
|
3292
|
+
if (model === "hex") {
|
|
3293
|
+
return getModelAnsi("rgb", level2, type, ...ansi_styles_default.hexToRgb(...arguments_));
|
|
3294
|
+
}
|
|
3295
|
+
return ansi_styles_default[type][model](...arguments_);
|
|
3296
|
+
};
|
|
3297
|
+
var usedModels = ["rgb", "hex", "ansi256"];
|
|
3298
|
+
for (const model of usedModels) {
|
|
3299
|
+
styles2[model] = {
|
|
3300
|
+
get() {
|
|
3301
|
+
const { level: level2 } = this;
|
|
3302
|
+
return function(...arguments_) {
|
|
3303
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level2], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
|
3304
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
3305
|
+
};
|
|
3306
|
+
}
|
|
3307
|
+
};
|
|
3308
|
+
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
3309
|
+
styles2[bgModel] = {
|
|
3310
|
+
get() {
|
|
3311
|
+
const { level: level2 } = this;
|
|
3312
|
+
return function(...arguments_) {
|
|
3313
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level2], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
|
|
3314
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
3315
|
+
};
|
|
3316
|
+
}
|
|
3317
|
+
};
|
|
3318
|
+
}
|
|
3319
|
+
var proto = Object.defineProperties(() => {}, {
|
|
3320
|
+
...styles2,
|
|
3321
|
+
level: {
|
|
3322
|
+
enumerable: true,
|
|
3323
|
+
get() {
|
|
3324
|
+
return this[GENERATOR].level;
|
|
3325
|
+
},
|
|
3326
|
+
set(level2) {
|
|
3327
|
+
this[GENERATOR].level = level2;
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
});
|
|
3331
|
+
var createStyler = (open, close, parent) => {
|
|
3332
|
+
let openAll;
|
|
3333
|
+
let closeAll;
|
|
3334
|
+
if (parent === undefined) {
|
|
3335
|
+
openAll = open;
|
|
3336
|
+
closeAll = close;
|
|
3337
|
+
} else {
|
|
3338
|
+
openAll = parent.openAll + open;
|
|
3339
|
+
closeAll = close + parent.closeAll;
|
|
3340
|
+
}
|
|
3341
|
+
return {
|
|
3342
|
+
open,
|
|
3343
|
+
close,
|
|
3344
|
+
openAll,
|
|
3345
|
+
closeAll,
|
|
3346
|
+
parent
|
|
3347
|
+
};
|
|
3348
|
+
};
|
|
3349
|
+
var createBuilder = (self, _styler, _isEmpty) => {
|
|
3350
|
+
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
3351
|
+
Object.setPrototypeOf(builder, proto);
|
|
3352
|
+
builder[GENERATOR] = self;
|
|
3353
|
+
builder[STYLER] = _styler;
|
|
3354
|
+
builder[IS_EMPTY] = _isEmpty;
|
|
3355
|
+
return builder;
|
|
3356
|
+
};
|
|
3357
|
+
var applyStyle = (self, string) => {
|
|
3358
|
+
if (self.level <= 0 || !string) {
|
|
3359
|
+
return self[IS_EMPTY] ? "" : string;
|
|
3360
|
+
}
|
|
3361
|
+
let styler = self[STYLER];
|
|
3362
|
+
if (styler === undefined) {
|
|
3363
|
+
return string;
|
|
3364
|
+
}
|
|
3365
|
+
const { openAll, closeAll } = styler;
|
|
3366
|
+
if (string.includes("\x1B")) {
|
|
3367
|
+
while (styler !== undefined) {
|
|
3368
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
3369
|
+
styler = styler.parent;
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
const lfIndex = string.indexOf(`
|
|
3373
|
+
`);
|
|
3374
|
+
if (lfIndex !== -1) {
|
|
3375
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
3376
|
+
}
|
|
3377
|
+
return openAll + string + closeAll;
|
|
3378
|
+
};
|
|
3379
|
+
Object.defineProperties(createChalk.prototype, styles2);
|
|
3380
|
+
var chalk = createChalk();
|
|
3381
|
+
var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
3382
|
+
var source_default = chalk;
|
|
3383
|
+
|
|
3384
|
+
// src/cli/index.ts
|
|
3385
|
+
init_path();
|
|
3386
|
+
var { default: fs3} = (() => ({}));
|
|
3387
|
+
|
|
3388
|
+
// src/utils/fs.ts
|
|
3389
|
+
var { default: fs} = (() => ({}));
|
|
3390
|
+
function assertFilepathExists(pathStr, msg) {
|
|
3391
|
+
if (fs.existsSync(pathStr) && fs.statSync(pathStr).isFile())
|
|
3392
|
+
return pathStr;
|
|
3393
|
+
const msgRes = msg ? typeof msg === "string" ? msg : msg(pathStr) : "Path not found or is not a file: " + pathStr;
|
|
3394
|
+
throw new Error(msgRes);
|
|
3395
|
+
}
|
|
3396
|
+
function assertDirpathExists(pathStr, msg) {
|
|
3397
|
+
if (fs.existsSync(pathStr) && fs.statSync(pathStr).isDirectory())
|
|
3398
|
+
return pathStr;
|
|
3399
|
+
const msgRes = msg ? typeof msg === "string" ? msg : msg(pathStr) : "Path not found or is not a directory: " + pathStr;
|
|
3400
|
+
throw new Error(msgRes);
|
|
3401
|
+
}
|
|
3402
|
+
|
|
3403
|
+
// src/utils/clamp.ts
|
|
3404
|
+
function clamp(value, min, max) {
|
|
3405
|
+
return Math.max(Math.min(value, max), min);
|
|
3406
|
+
}
|
|
3407
|
+
|
|
3408
|
+
// src/utils/getVersion.ts
|
|
3409
|
+
var { default: fs2} = (() => ({}));
|
|
3410
|
+
function gerVersionOrThrow() {
|
|
3411
|
+
const filename = "package.json";
|
|
3412
|
+
assertFilepathExists(filename, (p) => `Failed to determine version: ${p} not found`);
|
|
3413
|
+
let json;
|
|
3414
|
+
try {
|
|
3415
|
+
json = JSON.parse(fs2.readFileSync(filename, "utf-8"));
|
|
3416
|
+
} catch (err) {
|
|
3417
|
+
throw new Error(`Failed to determine version: failed to parse ${filename}`);
|
|
3418
|
+
}
|
|
3419
|
+
const version2 = json.version;
|
|
3420
|
+
if (!version2)
|
|
3421
|
+
throw new Error("Failed to determine version: version is undefined or an empty string");
|
|
3422
|
+
return version2;
|
|
3423
|
+
}
|
|
3424
|
+
|
|
3425
|
+
// src/cli/index.ts
|
|
3426
|
+
program.name("diff-mindustry-bundles").description("A handy utility to view missing/extra/untranslated keys between bundles.").version(gerVersionOrThrow()).argument("<top-bundle>", `Bundle with your localization (no extension). For example: 'bundle_ru'`).argument("[base-bundle]", `Bundle to compare with.`, "bundle").option("--base-dir <dirpath>", `Path to the directory containing ${source_default.bold("Mindustry")}`, ".").option("--bundles-dir <dirpath>", `Path to the directory containing ${source_default.bold("bundles")}. Relative to the base directory.`, path_default.normalize("./core/assets/bundles")).action((topBundleNameShort, baseBundleNameShort, opts) => {
|
|
3427
|
+
const baseDpResolved = path_default.resolve(opts.baseDir);
|
|
3428
|
+
const bundlesDpResolved = path_default.resolve(path_default.join(baseDpResolved, opts.bundlesDir));
|
|
3429
|
+
console.log(" Mindustry directory: " + baseDpResolved);
|
|
3430
|
+
console.log("Looking for bundles at: " + bundlesDpResolved);
|
|
3431
|
+
assertDirpathExists(baseDpResolved, "Mindustry directory not found.");
|
|
3432
|
+
assertDirpathExists(bundlesDpResolved, "Bundles directory not found.");
|
|
3433
|
+
const topBundleFn = topBundleNameShort + ".properties";
|
|
3434
|
+
const baseBundleFn = baseBundleNameShort + ".properties";
|
|
3435
|
+
const topBundleFp = assertFilepathExists(path_default.join(bundlesDpResolved, topBundleFn), (p) => `Top bundle not found at: ${p}
|
|
3436
|
+
- Bundle filename: ${topBundleFn}`);
|
|
3437
|
+
const baseBundleFp = assertFilepathExists(path_default.join(bundlesDpResolved, baseBundleFn), (p) => `Base bundle not found at: ${p}
|
|
3438
|
+
- Bundle filename: ${baseBundleFn}`);
|
|
3439
|
+
const topBundle = parseBundle(fs3.readFileSync(topBundleFp, "utf-8"));
|
|
3440
|
+
const baseBundle = parseBundle(fs3.readFileSync(baseBundleFp, "utf-8"));
|
|
3441
|
+
const diff = diffBundles(topBundle, baseBundle);
|
|
3442
|
+
const formatDiffLog = (msg, baseBundleName, topBundleName, diff2, prefix) => {
|
|
3443
|
+
const tabSize = 10;
|
|
3444
|
+
const tab = " ".repeat(tabSize);
|
|
3445
|
+
const diffLen = Object.keys(diff2).length;
|
|
3446
|
+
const diffFmted = Object.entries(diff2).map(([key, { string: value, line }]) => {
|
|
3447
|
+
const leftPadSpaces = " ".repeat(clamp(tabSize - line.toString().length, 0, Infinity));
|
|
3448
|
+
const leftPadChars = leftPadSpaces + source_default.gray(line) + " " + prefix + " ";
|
|
3449
|
+
const allNoValue = leftPadChars + key + " = ";
|
|
3450
|
+
return allNoValue + value;
|
|
3451
|
+
}).join(`
|
|
3452
|
+
`);
|
|
3453
|
+
const header = source_default.bold(` ${msg} (${diffLen}):`);
|
|
3454
|
+
const headerEnd = source_default.bold(msg);
|
|
3455
|
+
return `${header}
|
|
3456
|
+
${diffLen === 0 ? tab + source_default.italic("none") : diffFmted}
|
|
3457
|
+
${source_default.bold("END")} ${headerEnd}
|
|
3458
|
+
`;
|
|
3459
|
+
};
|
|
3460
|
+
console.log("");
|
|
3461
|
+
console.log(formatDiffLog(`Untranslated strings`, baseBundleFn, topBundleFn, diff.unchanged, source_default.gray("~")));
|
|
3462
|
+
console.log(formatDiffLog(`Extra strings`, baseBundleFn, topBundleFn, diff.added, source_default.green("+")));
|
|
3463
|
+
console.log(formatDiffLog(`Missing strings`, baseBundleFn, topBundleFn, diff.removed, source_default.red("-")));
|
|
3464
|
+
console.log(`Strings in top bundle: ${Object.keys(topBundle).length}`);
|
|
3465
|
+
console.log(`Strings in base bundle: ${Object.keys(baseBundle).length}`);
|
|
3466
|
+
}).parse();
|
|
3467
|
+
function diffBundles(top, base) {
|
|
3468
|
+
const removed = findMissing(top, base);
|
|
3469
|
+
const added = findMissing(base, top);
|
|
3470
|
+
const unchanged = findMatching(top, base);
|
|
3471
|
+
return { removed, added, unchanged };
|
|
3472
|
+
function findMissing(top2, base2) {
|
|
3473
|
+
const missingInTop = {};
|
|
3474
|
+
for (const key in base2) {
|
|
3475
|
+
if (key in top2) {} else {
|
|
3476
|
+
missingInTop[key] = base2[key];
|
|
3477
|
+
}
|
|
3478
|
+
}
|
|
3479
|
+
return missingInTop;
|
|
3480
|
+
}
|
|
3481
|
+
function findMatching(top2, base2) {
|
|
3482
|
+
const res = {};
|
|
3483
|
+
for (const key in base2) {
|
|
3484
|
+
if (key in top2 && top2[key].string === base2[key].string) {
|
|
3485
|
+
res[key] = base2[key];
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
return res;
|
|
3489
|
+
}
|
|
3490
|
+
}
|
|
3491
|
+
function parseBundle(bundle) {
|
|
3492
|
+
return bundle.split(`
|
|
3493
|
+
`).reduce((acc, line, lineIdx) => {
|
|
3494
|
+
const trimmed = line.trim();
|
|
3495
|
+
if (trimmed === "" || trimmed.startsWith("#"))
|
|
3496
|
+
return acc;
|
|
3497
|
+
let [key, ...value] = trimmed.split("=");
|
|
3498
|
+
if (value.length === 0)
|
|
3499
|
+
throw new Error(`Bundle parsing failed: encountered a line not in key=value format: key '${key}'`);
|
|
3500
|
+
acc[key.trim()] = { string: value.join("=").trim(), line: lineIdx + 1 };
|
|
3501
|
+
return acc;
|
|
3502
|
+
}, {});
|
|
3503
|
+
}
|