@listr2/manager 3.0.0-beta.3 → 3.0.1
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/dist/chunk-DWy1uDak.cjs +39 -0
- package/dist/chunk-Ye9CTm_R.js +27 -0
- package/dist/cli-truncate-BZsUcSxP.cjs +125 -0
- package/dist/cli-truncate-DY-z6Ecp.js +125 -0
- package/dist/index.cjs +2423 -79
- package/dist/index.d.cts +16 -14
- package/dist/index.d.ts +16 -14
- package/dist/index.js +2423 -54
- package/dist/log-update-4uRZgyzJ.cjs +521 -0
- package/dist/log-update-waQufObt.js +520 -0
- package/dist/string-width-BnS-vObO.js +245 -0
- package/dist/string-width-fWmCaoVR.cjs +268 -0
- package/dist/wrap-ansi-CVXwzrKr.js +4 -0
- package/dist/wrap-ansi-CguIj--u.cjs +4 -0
- package/dist/wrap-ansi-DS_DM18W.cjs +134 -0
- package/dist/wrap-ansi-WE3HDX1z.js +129 -0
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,57 +1,2426 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { __commonJS, __toESM } from "./chunk-Ye9CTm_R.js";
|
|
2
|
+
import * as tty from "tty";
|
|
3
|
+
import { format } from "util";
|
|
4
|
+
import { EOL } from "os";
|
|
5
|
+
import { StringDecoder } from "string_decoder";
|
|
6
|
+
import { Writable } from "stream";
|
|
7
|
+
import { randomUUID } from "crypto";
|
|
3
8
|
|
|
4
|
-
|
|
5
|
-
|
|
9
|
+
//#region ../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js
|
|
10
|
+
var require_eventemitter3 = __commonJS({ "../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js"(exports, module) {
|
|
11
|
+
var has = Object.prototype.hasOwnProperty, prefix = "~";
|
|
12
|
+
/**
|
|
13
|
+
* Constructor to create a storage for our `EE` objects.
|
|
14
|
+
* An `Events` instance is a plain object whose properties are event names.
|
|
15
|
+
*
|
|
16
|
+
* @constructor
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
function Events() {}
|
|
20
|
+
if (Object.create) {
|
|
21
|
+
Events.prototype = Object.create(null);
|
|
22
|
+
if (!new Events().__proto__) prefix = false;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Representation of a single event listener.
|
|
26
|
+
*
|
|
27
|
+
* @param {Function} fn The listener function.
|
|
28
|
+
* @param {*} context The context to invoke the listener with.
|
|
29
|
+
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
30
|
+
* @constructor
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
function EE(fn, context, once) {
|
|
34
|
+
this.fn = fn;
|
|
35
|
+
this.context = context;
|
|
36
|
+
this.once = once || false;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Add a listener for a given event.
|
|
40
|
+
*
|
|
41
|
+
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
42
|
+
* @param {(String|Symbol)} event The event name.
|
|
43
|
+
* @param {Function} fn The listener function.
|
|
44
|
+
* @param {*} context The context to invoke the listener with.
|
|
45
|
+
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
46
|
+
* @returns {EventEmitter}
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
function addListener(emitter, event, fn, context, once) {
|
|
50
|
+
if (typeof fn !== "function") throw new TypeError("The listener must be a function");
|
|
51
|
+
var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
|
|
52
|
+
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
53
|
+
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
54
|
+
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
55
|
+
return emitter;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Clear event by name.
|
|
59
|
+
*
|
|
60
|
+
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
61
|
+
* @param {(String|Symbol)} evt The Event name.
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
function clearEvent(emitter, evt) {
|
|
65
|
+
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
66
|
+
else delete emitter._events[evt];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
70
|
+
* `EventEmitter` interface.
|
|
71
|
+
*
|
|
72
|
+
* @constructor
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
function EventEmitter$1() {
|
|
76
|
+
this._events = new Events();
|
|
77
|
+
this._eventsCount = 0;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Return an array listing the events for which the emitter has registered
|
|
81
|
+
* listeners.
|
|
82
|
+
*
|
|
83
|
+
* @returns {Array}
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
EventEmitter$1.prototype.eventNames = function eventNames() {
|
|
87
|
+
var names = [], events, name;
|
|
88
|
+
if (this._eventsCount === 0) return names;
|
|
89
|
+
for (name in events = this._events) if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
90
|
+
if (Object.getOwnPropertySymbols) return names.concat(Object.getOwnPropertySymbols(events));
|
|
91
|
+
return names;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Return the listeners registered for a given event.
|
|
95
|
+
*
|
|
96
|
+
* @param {(String|Symbol)} event The event name.
|
|
97
|
+
* @returns {Array} The registered listeners.
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
EventEmitter$1.prototype.listeners = function listeners(event) {
|
|
101
|
+
var evt = prefix ? prefix + event : event, handlers = this._events[evt];
|
|
102
|
+
if (!handlers) return [];
|
|
103
|
+
if (handlers.fn) return [handlers.fn];
|
|
104
|
+
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) ee[i] = handlers[i].fn;
|
|
105
|
+
return ee;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Return the number of listeners listening to a given event.
|
|
109
|
+
*
|
|
110
|
+
* @param {(String|Symbol)} event The event name.
|
|
111
|
+
* @returns {Number} The number of listeners.
|
|
112
|
+
* @public
|
|
113
|
+
*/
|
|
114
|
+
EventEmitter$1.prototype.listenerCount = function listenerCount(event) {
|
|
115
|
+
var evt = prefix ? prefix + event : event, listeners = this._events[evt];
|
|
116
|
+
if (!listeners) return 0;
|
|
117
|
+
if (listeners.fn) return 1;
|
|
118
|
+
return listeners.length;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Calls each of the listeners registered for a given event.
|
|
122
|
+
*
|
|
123
|
+
* @param {(String|Symbol)} event The event name.
|
|
124
|
+
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
EventEmitter$1.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
128
|
+
var evt = prefix ? prefix + event : event;
|
|
129
|
+
if (!this._events[evt]) return false;
|
|
130
|
+
var listeners = this._events[evt], len = arguments.length, args, i;
|
|
131
|
+
if (listeners.fn) {
|
|
132
|
+
if (listeners.once) this.removeListener(event, listeners.fn, void 0, true);
|
|
133
|
+
switch (len) {
|
|
134
|
+
case 1: return listeners.fn.call(listeners.context), true;
|
|
135
|
+
case 2: return listeners.fn.call(listeners.context, a1), true;
|
|
136
|
+
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
|
137
|
+
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
138
|
+
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
139
|
+
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
140
|
+
}
|
|
141
|
+
for (i = 1, args = new Array(len - 1); i < len; i++) args[i - 1] = arguments[i];
|
|
142
|
+
listeners.fn.apply(listeners.context, args);
|
|
143
|
+
} else {
|
|
144
|
+
var length = listeners.length, j;
|
|
145
|
+
for (i = 0; i < length; i++) {
|
|
146
|
+
if (listeners[i].once) this.removeListener(event, listeners[i].fn, void 0, true);
|
|
147
|
+
switch (len) {
|
|
148
|
+
case 1:
|
|
149
|
+
listeners[i].fn.call(listeners[i].context);
|
|
150
|
+
break;
|
|
151
|
+
case 2:
|
|
152
|
+
listeners[i].fn.call(listeners[i].context, a1);
|
|
153
|
+
break;
|
|
154
|
+
case 3:
|
|
155
|
+
listeners[i].fn.call(listeners[i].context, a1, a2);
|
|
156
|
+
break;
|
|
157
|
+
case 4:
|
|
158
|
+
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
|
|
159
|
+
break;
|
|
160
|
+
default:
|
|
161
|
+
if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) args[j - 1] = arguments[j];
|
|
162
|
+
listeners[i].fn.apply(listeners[i].context, args);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Add a listener for a given event.
|
|
170
|
+
*
|
|
171
|
+
* @param {(String|Symbol)} event The event name.
|
|
172
|
+
* @param {Function} fn The listener function.
|
|
173
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
174
|
+
* @returns {EventEmitter} `this`.
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
EventEmitter$1.prototype.on = function on(event, fn, context) {
|
|
178
|
+
return addListener(this, event, fn, context, false);
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Add a one-time listener for a given event.
|
|
182
|
+
*
|
|
183
|
+
* @param {(String|Symbol)} event The event name.
|
|
184
|
+
* @param {Function} fn The listener function.
|
|
185
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
186
|
+
* @returns {EventEmitter} `this`.
|
|
187
|
+
* @public
|
|
188
|
+
*/
|
|
189
|
+
EventEmitter$1.prototype.once = function once(event, fn, context) {
|
|
190
|
+
return addListener(this, event, fn, context, true);
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Remove the listeners of a given event.
|
|
194
|
+
*
|
|
195
|
+
* @param {(String|Symbol)} event The event name.
|
|
196
|
+
* @param {Function} fn Only remove the listeners that match this function.
|
|
197
|
+
* @param {*} context Only remove the listeners that have this context.
|
|
198
|
+
* @param {Boolean} once Only remove one-time listeners.
|
|
199
|
+
* @returns {EventEmitter} `this`.
|
|
200
|
+
* @public
|
|
201
|
+
*/
|
|
202
|
+
EventEmitter$1.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
203
|
+
var evt = prefix ? prefix + event : event;
|
|
204
|
+
if (!this._events[evt]) return this;
|
|
205
|
+
if (!fn) {
|
|
206
|
+
clearEvent(this, evt);
|
|
207
|
+
return this;
|
|
208
|
+
}
|
|
209
|
+
var listeners = this._events[evt];
|
|
210
|
+
if (listeners.fn) {
|
|
211
|
+
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) clearEvent(this, evt);
|
|
212
|
+
} else {
|
|
213
|
+
for (var i = 0, events = [], length = listeners.length; i < length; i++) if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) events.push(listeners[i]);
|
|
214
|
+
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
215
|
+
else clearEvent(this, evt);
|
|
216
|
+
}
|
|
217
|
+
return this;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Remove all listeners, or those of the specified event.
|
|
221
|
+
*
|
|
222
|
+
* @param {(String|Symbol)} [event] The event name.
|
|
223
|
+
* @returns {EventEmitter} `this`.
|
|
224
|
+
* @public
|
|
225
|
+
*/
|
|
226
|
+
EventEmitter$1.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
227
|
+
var evt;
|
|
228
|
+
if (event) {
|
|
229
|
+
evt = prefix ? prefix + event : event;
|
|
230
|
+
if (this._events[evt]) clearEvent(this, evt);
|
|
231
|
+
} else {
|
|
232
|
+
this._events = new Events();
|
|
233
|
+
this._eventsCount = 0;
|
|
234
|
+
}
|
|
235
|
+
return this;
|
|
236
|
+
};
|
|
237
|
+
EventEmitter$1.prototype.off = EventEmitter$1.prototype.removeListener;
|
|
238
|
+
EventEmitter$1.prototype.addListener = EventEmitter$1.prototype.on;
|
|
239
|
+
EventEmitter$1.prefixed = prefix;
|
|
240
|
+
EventEmitter$1.EventEmitter = EventEmitter$1;
|
|
241
|
+
if ("undefined" !== typeof module) module.exports = EventEmitter$1;
|
|
242
|
+
} });
|
|
243
|
+
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region ../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.mjs
|
|
246
|
+
var import_eventemitter3 = __toESM(require_eventemitter3(), 1);
|
|
247
|
+
var eventemitter3_default = import_eventemitter3.default;
|
|
248
|
+
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region ../../node_modules/.pnpm/colorette@2.0.20/node_modules/colorette/index.js
|
|
251
|
+
const { env = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
|
|
252
|
+
const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
|
|
253
|
+
const isForced = "FORCE_COLOR" in env || argv.includes("--color");
|
|
254
|
+
const isWindows = platform === "win32";
|
|
255
|
+
const isDumbTerminal = env.TERM === "dumb";
|
|
256
|
+
const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
|
|
257
|
+
const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
|
|
258
|
+
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
|
259
|
+
const replaceClose = (index, string, close, replace, head = string.substring(0, index) + replace, tail = string.substring(index + close.length), next = tail.indexOf(close)) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
|
260
|
+
const clearBleed = (index, string, open, close, replace) => index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
|
|
261
|
+
const filterEmpty = (open, close, replace = open, at = open.length + 1) => (string) => string || !(string === "" || string === void 0) ? clearBleed(("" + string).indexOf(close, at), string, open, close, replace) : "";
|
|
262
|
+
const init = (open, close, replace) => filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
|
|
263
|
+
const colors = {
|
|
264
|
+
reset: init(0, 0),
|
|
265
|
+
bold: init(1, 22, "\x1B[22m\x1B[1m"),
|
|
266
|
+
dim: init(2, 22, "\x1B[22m\x1B[2m"),
|
|
267
|
+
italic: init(3, 23),
|
|
268
|
+
underline: init(4, 24),
|
|
269
|
+
inverse: init(7, 27),
|
|
270
|
+
hidden: init(8, 28),
|
|
271
|
+
strikethrough: init(9, 29),
|
|
272
|
+
black: init(30, 39),
|
|
273
|
+
red: init(31, 39),
|
|
274
|
+
green: init(32, 39),
|
|
275
|
+
yellow: init(33, 39),
|
|
276
|
+
blue: init(34, 39),
|
|
277
|
+
magenta: init(35, 39),
|
|
278
|
+
cyan: init(36, 39),
|
|
279
|
+
white: init(37, 39),
|
|
280
|
+
gray: init(90, 39),
|
|
281
|
+
bgBlack: init(40, 49),
|
|
282
|
+
bgRed: init(41, 49),
|
|
283
|
+
bgGreen: init(42, 49),
|
|
284
|
+
bgYellow: init(43, 49),
|
|
285
|
+
bgBlue: init(44, 49),
|
|
286
|
+
bgMagenta: init(45, 49),
|
|
287
|
+
bgCyan: init(46, 49),
|
|
288
|
+
bgWhite: init(47, 49),
|
|
289
|
+
blackBright: init(90, 39),
|
|
290
|
+
redBright: init(91, 39),
|
|
291
|
+
greenBright: init(92, 39),
|
|
292
|
+
yellowBright: init(93, 39),
|
|
293
|
+
blueBright: init(94, 39),
|
|
294
|
+
magentaBright: init(95, 39),
|
|
295
|
+
cyanBright: init(96, 39),
|
|
296
|
+
whiteBright: init(97, 39),
|
|
297
|
+
bgBlackBright: init(100, 49),
|
|
298
|
+
bgRedBright: init(101, 49),
|
|
299
|
+
bgGreenBright: init(102, 49),
|
|
300
|
+
bgYellowBright: init(103, 49),
|
|
301
|
+
bgBlueBright: init(104, 49),
|
|
302
|
+
bgMagentaBright: init(105, 49),
|
|
303
|
+
bgCyanBright: init(106, 49),
|
|
304
|
+
bgWhiteBright: init(107, 49)
|
|
305
|
+
};
|
|
306
|
+
const createColors = ({ useColor = isColorSupported } = {}) => useColor ? colors : Object.keys(colors).reduce((colors$1, key) => ({
|
|
307
|
+
...colors$1,
|
|
308
|
+
[key]: String
|
|
309
|
+
}), {});
|
|
310
|
+
const { reset, bold, dim, italic, underline, inverse, hidden, strikethrough, black, red, green, yellow, blue, magenta, cyan, white, gray, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, blackBright, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlackBright, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright } = createColors();
|
|
311
|
+
|
|
312
|
+
//#endregion
|
|
313
|
+
//#region ../../node_modules/.pnpm/rfdc@1.4.1/node_modules/rfdc/index.js
|
|
314
|
+
var require_rfdc = __commonJS({ "../../node_modules/.pnpm/rfdc@1.4.1/node_modules/rfdc/index.js"(exports, module) {
|
|
315
|
+
module.exports = rfdc$1;
|
|
316
|
+
function copyBuffer(cur) {
|
|
317
|
+
if (cur instanceof Buffer) return Buffer.from(cur);
|
|
318
|
+
return new cur.constructor(cur.buffer.slice(), cur.byteOffset, cur.length);
|
|
319
|
+
}
|
|
320
|
+
function rfdc$1(opts) {
|
|
321
|
+
opts = opts || {};
|
|
322
|
+
if (opts.circles) return rfdcCircles(opts);
|
|
323
|
+
const constructorHandlers = /* @__PURE__ */ new Map();
|
|
324
|
+
constructorHandlers.set(Date, (o) => new Date(o));
|
|
325
|
+
constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)));
|
|
326
|
+
constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)));
|
|
327
|
+
if (opts.constructorHandlers) for (const handler$1 of opts.constructorHandlers) constructorHandlers.set(handler$1[0], handler$1[1]);
|
|
328
|
+
let handler = null;
|
|
329
|
+
return opts.proto ? cloneProto : clone$1;
|
|
330
|
+
function cloneArray(a, fn) {
|
|
331
|
+
const keys = Object.keys(a);
|
|
332
|
+
const a2 = new Array(keys.length);
|
|
333
|
+
for (let i = 0; i < keys.length; i++) {
|
|
334
|
+
const k = keys[i];
|
|
335
|
+
const cur = a[k];
|
|
336
|
+
if (typeof cur !== "object" || cur === null) a2[k] = cur;
|
|
337
|
+
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) a2[k] = handler(cur, fn);
|
|
338
|
+
else if (ArrayBuffer.isView(cur)) a2[k] = copyBuffer(cur);
|
|
339
|
+
else a2[k] = fn(cur);
|
|
340
|
+
}
|
|
341
|
+
return a2;
|
|
342
|
+
}
|
|
343
|
+
function clone$1(o) {
|
|
344
|
+
if (typeof o !== "object" || o === null) return o;
|
|
345
|
+
if (Array.isArray(o)) return cloneArray(o, clone$1);
|
|
346
|
+
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, clone$1);
|
|
347
|
+
const o2 = {};
|
|
348
|
+
for (const k in o) {
|
|
349
|
+
if (Object.hasOwnProperty.call(o, k) === false) continue;
|
|
350
|
+
const cur = o[k];
|
|
351
|
+
if (typeof cur !== "object" || cur === null) o2[k] = cur;
|
|
352
|
+
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, clone$1);
|
|
353
|
+
else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
|
|
354
|
+
else o2[k] = clone$1(cur);
|
|
355
|
+
}
|
|
356
|
+
return o2;
|
|
357
|
+
}
|
|
358
|
+
function cloneProto(o) {
|
|
359
|
+
if (typeof o !== "object" || o === null) return o;
|
|
360
|
+
if (Array.isArray(o)) return cloneArray(o, cloneProto);
|
|
361
|
+
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, cloneProto);
|
|
362
|
+
const o2 = {};
|
|
363
|
+
for (const k in o) {
|
|
364
|
+
const cur = o[k];
|
|
365
|
+
if (typeof cur !== "object" || cur === null) o2[k] = cur;
|
|
366
|
+
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, cloneProto);
|
|
367
|
+
else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
|
|
368
|
+
else o2[k] = cloneProto(cur);
|
|
369
|
+
}
|
|
370
|
+
return o2;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
function rfdcCircles(opts) {
|
|
374
|
+
const refs = [];
|
|
375
|
+
const refsNew = [];
|
|
376
|
+
const constructorHandlers = /* @__PURE__ */ new Map();
|
|
377
|
+
constructorHandlers.set(Date, (o) => new Date(o));
|
|
378
|
+
constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)));
|
|
379
|
+
constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)));
|
|
380
|
+
if (opts.constructorHandlers) for (const handler$1 of opts.constructorHandlers) constructorHandlers.set(handler$1[0], handler$1[1]);
|
|
381
|
+
let handler = null;
|
|
382
|
+
return opts.proto ? cloneProto : clone$1;
|
|
383
|
+
function cloneArray(a, fn) {
|
|
384
|
+
const keys = Object.keys(a);
|
|
385
|
+
const a2 = new Array(keys.length);
|
|
386
|
+
for (let i = 0; i < keys.length; i++) {
|
|
387
|
+
const k = keys[i];
|
|
388
|
+
const cur = a[k];
|
|
389
|
+
if (typeof cur !== "object" || cur === null) a2[k] = cur;
|
|
390
|
+
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) a2[k] = handler(cur, fn);
|
|
391
|
+
else if (ArrayBuffer.isView(cur)) a2[k] = copyBuffer(cur);
|
|
392
|
+
else {
|
|
393
|
+
const index = refs.indexOf(cur);
|
|
394
|
+
if (index !== -1) a2[k] = refsNew[index];
|
|
395
|
+
else a2[k] = fn(cur);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return a2;
|
|
399
|
+
}
|
|
400
|
+
function clone$1(o) {
|
|
401
|
+
if (typeof o !== "object" || o === null) return o;
|
|
402
|
+
if (Array.isArray(o)) return cloneArray(o, clone$1);
|
|
403
|
+
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, clone$1);
|
|
404
|
+
const o2 = {};
|
|
405
|
+
refs.push(o);
|
|
406
|
+
refsNew.push(o2);
|
|
407
|
+
for (const k in o) {
|
|
408
|
+
if (Object.hasOwnProperty.call(o, k) === false) continue;
|
|
409
|
+
const cur = o[k];
|
|
410
|
+
if (typeof cur !== "object" || cur === null) o2[k] = cur;
|
|
411
|
+
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, clone$1);
|
|
412
|
+
else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
|
|
413
|
+
else {
|
|
414
|
+
const i = refs.indexOf(cur);
|
|
415
|
+
if (i !== -1) o2[k] = refsNew[i];
|
|
416
|
+
else o2[k] = clone$1(cur);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
refs.pop();
|
|
420
|
+
refsNew.pop();
|
|
421
|
+
return o2;
|
|
422
|
+
}
|
|
423
|
+
function cloneProto(o) {
|
|
424
|
+
if (typeof o !== "object" || o === null) return o;
|
|
425
|
+
if (Array.isArray(o)) return cloneArray(o, cloneProto);
|
|
426
|
+
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, cloneProto);
|
|
427
|
+
const o2 = {};
|
|
428
|
+
refs.push(o);
|
|
429
|
+
refsNew.push(o2);
|
|
430
|
+
for (const k in o) {
|
|
431
|
+
const cur = o[k];
|
|
432
|
+
if (typeof cur !== "object" || cur === null) o2[k] = cur;
|
|
433
|
+
else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, cloneProto);
|
|
434
|
+
else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
|
|
435
|
+
else {
|
|
436
|
+
const i = refs.indexOf(cur);
|
|
437
|
+
if (i !== -1) o2[k] = refsNew[i];
|
|
438
|
+
else o2[k] = cloneProto(cur);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
refs.pop();
|
|
442
|
+
refsNew.pop();
|
|
443
|
+
return o2;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
} });
|
|
447
|
+
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region ../listr2/dist/index.js
|
|
450
|
+
var import_rfdc = __toESM(require_rfdc(), 1);
|
|
451
|
+
/**
|
|
452
|
+
* Indicates an UNICODE characters is coming up.
|
|
453
|
+
*/
|
|
454
|
+
const ANSI_ESCAPE = "\x1B[";
|
|
455
|
+
/**
|
|
456
|
+
* Generic ANSI escape characters for terminal based operations.
|
|
457
|
+
*/
|
|
458
|
+
const ANSI_ESCAPE_CODES = {
|
|
459
|
+
CURSOR_HIDE: ANSI_ESCAPE + "?25l",
|
|
460
|
+
CURSOR_SHOW: ANSI_ESCAPE + "?25h"
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* Environment variables for Listr.
|
|
464
|
+
*/
|
|
465
|
+
let ListrEnvironmentVariables = /* @__PURE__ */ function(ListrEnvironmentVariables$1) {
|
|
466
|
+
ListrEnvironmentVariables$1["FORCE_UNICODE"] = "LISTR_FORCE_UNICODE";
|
|
467
|
+
ListrEnvironmentVariables$1["FORCE_TTY"] = "LISTR_FORCE_TTY";
|
|
468
|
+
ListrEnvironmentVariables$1["DISABLE_COLOR"] = "NO_COLOR";
|
|
469
|
+
ListrEnvironmentVariables$1["FORCE_COLOR"] = "FORCE_COLOR";
|
|
470
|
+
return ListrEnvironmentVariables$1;
|
|
471
|
+
}({});
|
|
472
|
+
/**
|
|
473
|
+
* The actual error type that is collected and to help identify where the error is triggered from.
|
|
474
|
+
*/
|
|
475
|
+
let ListrErrorTypes = /* @__PURE__ */ function(ListrErrorTypes$1) {
|
|
476
|
+
/** Task has failed and will try to retry. */
|
|
477
|
+
ListrErrorTypes$1["WILL_RETRY"] = "WILL_RETRY";
|
|
478
|
+
/** Task has failed and will try to rollback. */
|
|
479
|
+
ListrErrorTypes$1["WILL_ROLLBACK"] = "WILL_ROLLBACK";
|
|
480
|
+
/** Task has failed, ran the rollback action but the rollback action itself has failed. */
|
|
481
|
+
ListrErrorTypes$1["HAS_FAILED_TO_ROLLBACK"] = "HAS_FAILED_TO_ROLLBACK";
|
|
482
|
+
/** Task has failed. */
|
|
483
|
+
ListrErrorTypes$1["HAS_FAILED"] = "HAS_FAILED";
|
|
484
|
+
/** Task has failed, but exitOnError is set to false, so will ignore this error. */
|
|
485
|
+
ListrErrorTypes$1["HAS_FAILED_WITHOUT_ERROR"] = "HAS_FAILED_WITHOUT_ERROR";
|
|
486
|
+
return ListrErrorTypes$1;
|
|
487
|
+
}({});
|
|
488
|
+
/**
|
|
489
|
+
* Events that are triggered by Listr.
|
|
490
|
+
*
|
|
491
|
+
* These are stateful and singleton events by being attached to the main Listr class and propagating to the subtasks.
|
|
492
|
+
*
|
|
493
|
+
* @see {@link https://listr2.kilic.dev/listr/events.html}
|
|
494
|
+
*/
|
|
495
|
+
let ListrEventType = /* @__PURE__ */ function(ListrEventType$1) {
|
|
496
|
+
/** Indicates that underlying renderer should refresh the current render. */
|
|
497
|
+
ListrEventType$1["SHOULD_REFRESH_RENDER"] = "SHOUD_REFRESH_RENDER";
|
|
498
|
+
return ListrEventType$1;
|
|
499
|
+
}({});
|
|
500
|
+
let ListrRendererSelection = /* @__PURE__ */ function(ListrRendererSelection$1) {
|
|
501
|
+
ListrRendererSelection$1["PRIMARY"] = "PRIMARY";
|
|
502
|
+
ListrRendererSelection$1["SECONDARY"] = "SECONDARY";
|
|
503
|
+
ListrRendererSelection$1["SILENT"] = "SILENT";
|
|
504
|
+
return ListrRendererSelection$1;
|
|
505
|
+
}({});
|
|
506
|
+
/**
|
|
507
|
+
* Internal events that are fired from the Task.
|
|
508
|
+
*
|
|
509
|
+
* @see {@link https://listr2.kilic.dev/task/events.html}
|
|
510
|
+
*/
|
|
511
|
+
let ListrTaskEventType = /* @__PURE__ */ function(ListrTaskEventType$1) {
|
|
512
|
+
/** Title has changed for the current Task. */
|
|
513
|
+
ListrTaskEventType$1["TITLE"] = "TITLE";
|
|
514
|
+
/**
|
|
515
|
+
* State has changed for the current Task.
|
|
516
|
+
*
|
|
517
|
+
* @see {@link module:listr2.ListrTaskState}
|
|
518
|
+
*/
|
|
519
|
+
ListrTaskEventType$1["STATE"] = "STATE";
|
|
520
|
+
/** The current Task has been marked as enabled. */
|
|
521
|
+
ListrTaskEventType$1["ENABLED"] = "ENABLED";
|
|
522
|
+
/** The current Task is currently processing subtasks. */
|
|
523
|
+
ListrTaskEventType$1["SUBTASK"] = "SUBTASK";
|
|
524
|
+
/** The current Task is now processing a prompt. */
|
|
525
|
+
ListrTaskEventType$1["PROMPT"] = "PROMPT";
|
|
526
|
+
/** The current Task is now dumping output. */
|
|
527
|
+
ListrTaskEventType$1["OUTPUT"] = "OUTPUT";
|
|
528
|
+
/**
|
|
529
|
+
* The current Task is now dumping a message.
|
|
530
|
+
*
|
|
531
|
+
* @see {module:Listr2.ListrTaskMessage}
|
|
532
|
+
*/
|
|
533
|
+
ListrTaskEventType$1["MESSAGE"] = "MESSAGE";
|
|
534
|
+
/** The current Task is closed and no further action in expected. */
|
|
535
|
+
ListrTaskEventType$1["CLOSED"] = "CLOSED";
|
|
536
|
+
return ListrTaskEventType$1;
|
|
537
|
+
}({});
|
|
538
|
+
/**
|
|
539
|
+
* Tasks can be in various states during the execution.
|
|
540
|
+
*
|
|
541
|
+
* Whenever a state change occurs, the task will emit a {@link module:listr2.ListrTaskEventType.STATE} with the appropriate state.
|
|
542
|
+
*/
|
|
543
|
+
let ListrTaskState = /* @__PURE__ */ function(ListrTaskState$1) {
|
|
544
|
+
/** Task has not started yet, waiting for pick-up. */
|
|
545
|
+
ListrTaskState$1["WAITING"] = "WAITING";
|
|
546
|
+
/** Task has started. */
|
|
547
|
+
ListrTaskState$1["STARTED"] = "STARTED";
|
|
548
|
+
/** Task has been completed. */
|
|
549
|
+
ListrTaskState$1["COMPLETED"] = "COMPLETED";
|
|
550
|
+
/** Task has failed. */
|
|
551
|
+
ListrTaskState$1["FAILED"] = "FAILED";
|
|
552
|
+
/** Task has been skipped. */
|
|
553
|
+
ListrTaskState$1["SKIPPED"] = "SKIPPED";
|
|
554
|
+
/** Task is currently trying to rollback. */
|
|
555
|
+
ListrTaskState$1["ROLLING_BACK"] = "ROLLING_BACK";
|
|
556
|
+
/** Task has rolledback successfully after failing. */
|
|
557
|
+
ListrTaskState$1["ROLLED_BACK"] = "ROLLED_BACK";
|
|
558
|
+
/** Task is currently retrying. */
|
|
559
|
+
ListrTaskState$1["RETRY"] = "RETRY";
|
|
560
|
+
/** Task is currently paused. */
|
|
561
|
+
ListrTaskState$1["PAUSED"] = "PAUSED";
|
|
562
|
+
/** Task is currently trying to process a prompt. */
|
|
563
|
+
ListrTaskState$1["PROMPT"] = "PROMPT";
|
|
564
|
+
/** Task has successfully processed the prompt. */
|
|
565
|
+
ListrTaskState$1["PROMPT_COMPLETED"] = "PROMPT_COMPLETED";
|
|
566
|
+
/** Task has failed to process the prompt. */
|
|
567
|
+
ListrTaskState$1["PROMPT_FAILED"] = "PROMPT_FAILED";
|
|
568
|
+
return ListrTaskState$1;
|
|
569
|
+
}({});
|
|
570
|
+
var EventManager = class {
|
|
571
|
+
emitter = new eventemitter3_default();
|
|
572
|
+
emit(dispatch, args) {
|
|
573
|
+
this.emitter.emit(dispatch, args);
|
|
574
|
+
}
|
|
575
|
+
on(dispatch, handler) {
|
|
576
|
+
this.emitter.addListener(dispatch, handler);
|
|
577
|
+
}
|
|
578
|
+
once(dispatch, handler) {
|
|
579
|
+
this.emitter.once(dispatch, handler);
|
|
580
|
+
}
|
|
581
|
+
off(dispatch, handler) {
|
|
582
|
+
this.emitter.off(dispatch, handler);
|
|
583
|
+
}
|
|
584
|
+
complete() {
|
|
585
|
+
this.emitter.removeAllListeners();
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
/**
|
|
589
|
+
* Tests to see if the object is an RxJS {@link Observable}
|
|
590
|
+
* @param obj the object to test
|
|
591
|
+
*/
|
|
592
|
+
function isObservable(obj) {
|
|
593
|
+
return !!obj && typeof obj === "object" && typeof obj.subscribe === "function";
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Tests to see if the object is an Readable or NodeJS.ReadableStream {@link Readable, NodeJS.ReadableStream}
|
|
597
|
+
* @param obj the object to test
|
|
598
|
+
*/
|
|
599
|
+
function isReadable(obj) {
|
|
600
|
+
return !!obj && typeof obj === "object" && obj.readable === true && typeof obj.read === "function" && typeof obj.on === "function";
|
|
601
|
+
}
|
|
602
|
+
function isUnicodeSupported() {
|
|
603
|
+
/* istanbul ignore next */
|
|
604
|
+
return !!process.env[ListrEnvironmentVariables.FORCE_UNICODE] || process.platform !== "win32" || !!process.env.CI || !!process.env.WT_SESSION || process.env.TERM_PROGRAM === "vscode" || process.env.TERM === "xterm-256color" || process.env.TERM === "alacritty";
|
|
605
|
+
}
|
|
606
|
+
const CLEAR_LINE_REGEX = "(?:\\u001b|\\u009b)\\[[\\=><~/#&.:=?%@~_-]*[0-9]*[\\a-ln-tqyz=><~/#&.:=?%@~_-]+";
|
|
607
|
+
const BELL_REGEX = /\u0007/;
|
|
608
|
+
function cleanseAnsi(chunk) {
|
|
609
|
+
return String(chunk).replace(new RegExp(CLEAR_LINE_REGEX, "gmi"), "").replace(new RegExp(BELL_REGEX, "gmi"), "").trim();
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Creates color palette through underlying dependency of `colorette`.
|
|
613
|
+
*
|
|
614
|
+
* @see {@link https://www.npmjs.com/package/colorette}
|
|
615
|
+
*/
|
|
616
|
+
const color = createColors();
|
|
617
|
+
function indent(string, count) {
|
|
618
|
+
return string.replace(/^(?!\s*$)/gm, " ".repeat(count));
|
|
619
|
+
}
|
|
620
|
+
const FIGURES_MAIN = {
|
|
621
|
+
warning: "⚠",
|
|
622
|
+
cross: "✖",
|
|
623
|
+
arrowDown: "↓",
|
|
624
|
+
tick: "✔",
|
|
625
|
+
arrowRight: "→",
|
|
626
|
+
pointer: "❯",
|
|
627
|
+
checkboxOn: "☒",
|
|
628
|
+
arrowLeft: "←",
|
|
629
|
+
squareSmallFilled: "◼",
|
|
630
|
+
pointerSmall: "›"
|
|
631
|
+
};
|
|
632
|
+
const FIGURES_FALLBACK = {
|
|
633
|
+
...FIGURES_MAIN,
|
|
634
|
+
warning: "‼",
|
|
635
|
+
cross: "×",
|
|
636
|
+
tick: "√",
|
|
637
|
+
pointer: ">",
|
|
638
|
+
checkboxOn: "[×]",
|
|
639
|
+
squareSmallFilled: "■"
|
|
640
|
+
};
|
|
641
|
+
const figures = isUnicodeSupported() ? FIGURES_MAIN : FIGURES_FALLBACK;
|
|
642
|
+
function splat(message, ...splat$1) {
|
|
643
|
+
return format(String(message), ...splat$1);
|
|
644
|
+
}
|
|
645
|
+
/** Default ListrLogLevels for the logger */
|
|
646
|
+
let ListrLogLevels = /* @__PURE__ */ function(ListrLogLevels$1) {
|
|
647
|
+
ListrLogLevels$1["STARTED"] = "STARTED";
|
|
648
|
+
ListrLogLevels$1["COMPLETED"] = "COMPLETED";
|
|
649
|
+
ListrLogLevels$1["FAILED"] = "FAILED";
|
|
650
|
+
ListrLogLevels$1["SKIPPED"] = "SKIPPED";
|
|
651
|
+
ListrLogLevels$1["OUTPUT"] = "OUTPUT";
|
|
652
|
+
ListrLogLevels$1["TITLE"] = "TITLE";
|
|
653
|
+
ListrLogLevels$1["ROLLBACK"] = "ROLLBACK";
|
|
654
|
+
ListrLogLevels$1["RETRY"] = "RETRY";
|
|
655
|
+
ListrLogLevels$1["PROMPT"] = "PROMPT";
|
|
656
|
+
ListrLogLevels$1["PAUSED"] = "PAUSED";
|
|
657
|
+
return ListrLogLevels$1;
|
|
658
|
+
}({});
|
|
659
|
+
const LISTR_LOGGER_STYLE = {
|
|
660
|
+
icon: {
|
|
661
|
+
[ListrLogLevels.STARTED]: figures.pointer,
|
|
662
|
+
[ListrLogLevels.FAILED]: figures.cross,
|
|
663
|
+
[ListrLogLevels.SKIPPED]: figures.arrowDown,
|
|
664
|
+
[ListrLogLevels.COMPLETED]: figures.tick,
|
|
665
|
+
[ListrLogLevels.OUTPUT]: figures.pointerSmall,
|
|
666
|
+
[ListrLogLevels.TITLE]: figures.arrowRight,
|
|
667
|
+
[ListrLogLevels.RETRY]: figures.warning,
|
|
668
|
+
[ListrLogLevels.ROLLBACK]: figures.arrowLeft,
|
|
669
|
+
[ListrLogLevels.PAUSED]: figures.squareSmallFilled
|
|
670
|
+
},
|
|
671
|
+
color: {
|
|
672
|
+
[ListrLogLevels.STARTED]: color.yellow,
|
|
673
|
+
[ListrLogLevels.FAILED]: color.red,
|
|
674
|
+
[ListrLogLevels.SKIPPED]: color.yellow,
|
|
675
|
+
[ListrLogLevels.COMPLETED]: color.green,
|
|
676
|
+
[ListrLogLevels.RETRY]: color.yellowBright,
|
|
677
|
+
[ListrLogLevels.ROLLBACK]: color.redBright,
|
|
678
|
+
[ListrLogLevels.PAUSED]: color.yellowBright
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
const LISTR_LOGGER_STDERR_LEVELS = [
|
|
682
|
+
ListrLogLevels.RETRY,
|
|
683
|
+
ListrLogLevels.ROLLBACK,
|
|
684
|
+
ListrLogLevels.FAILED
|
|
685
|
+
];
|
|
686
|
+
/**
|
|
687
|
+
* Creates a new Listr2 logger.
|
|
688
|
+
*
|
|
689
|
+
* This logger is used throughout the renderers for consistency.
|
|
690
|
+
*
|
|
691
|
+
* @see {@link https://listr2.kilic.dev/renderer/logger.html}
|
|
692
|
+
*/
|
|
693
|
+
var ListrLogger = class {
|
|
694
|
+
process;
|
|
695
|
+
constructor(options) {
|
|
696
|
+
this.options = options;
|
|
697
|
+
this.options = {
|
|
698
|
+
useIcons: true,
|
|
699
|
+
toStderr: [],
|
|
700
|
+
...options ?? {}
|
|
701
|
+
};
|
|
702
|
+
this.options.fields ??= {};
|
|
703
|
+
this.options.fields.prefix ??= [];
|
|
704
|
+
this.options.fields.suffix ??= [];
|
|
705
|
+
this.process = this.options.processOutput ?? new ProcessOutput();
|
|
706
|
+
}
|
|
707
|
+
log(level, message, options) {
|
|
708
|
+
const output = this.format(level, message, options);
|
|
709
|
+
if (this.options.toStderr.includes(level)) {
|
|
710
|
+
this.process.toStderr(output);
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
this.process.toStdout(output);
|
|
714
|
+
}
|
|
715
|
+
toStdout(message, options, eol = true) {
|
|
716
|
+
this.process.toStdout(this.format(null, message, options), eol);
|
|
717
|
+
}
|
|
718
|
+
toStderr(message, options, eol = true) {
|
|
719
|
+
this.process.toStderr(this.format(null, message, options), eol);
|
|
720
|
+
}
|
|
721
|
+
wrap(message, options) {
|
|
722
|
+
if (!message) return message;
|
|
723
|
+
return this.applyFormat(`[${message}]`, options);
|
|
724
|
+
}
|
|
725
|
+
splat(...args) {
|
|
726
|
+
const message = args.shift() ?? "";
|
|
727
|
+
return args.length === 0 ? message : splat(message, args);
|
|
728
|
+
}
|
|
729
|
+
suffix(message, ...suffixes) {
|
|
730
|
+
suffixes.filter(Boolean).forEach((suffix) => {
|
|
731
|
+
message += this.spacing(message);
|
|
732
|
+
if (typeof suffix === "string") message += this.wrap(suffix);
|
|
733
|
+
else if (typeof suffix === "object") {
|
|
734
|
+
suffix.args ??= [];
|
|
735
|
+
if (typeof suffix.condition === "function" ? !suffix.condition(...suffix.args) : !(suffix.condition ?? true)) return message;
|
|
736
|
+
message += this.wrap(typeof suffix.field === "function" ? suffix.field(...suffix.args) : suffix.field, { format: suffix?.format(...suffix.args) });
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
return message;
|
|
740
|
+
}
|
|
741
|
+
prefix(message, ...prefixes) {
|
|
742
|
+
prefixes.filter(Boolean).forEach((prefix$1) => {
|
|
743
|
+
message = this.spacing(message) + message;
|
|
744
|
+
if (typeof prefix$1 === "string") message = this.wrap(prefix$1) + message;
|
|
745
|
+
else if (typeof prefix$1 === "object") {
|
|
746
|
+
prefix$1.args ??= [];
|
|
747
|
+
if (typeof prefix$1.condition === "function" ? !prefix$1.condition(...prefix$1.args) : !(prefix$1.condition ?? true)) return message;
|
|
748
|
+
message = this.wrap(typeof prefix$1.field === "function" ? prefix$1.field(...prefix$1.args) : prefix$1.field, { format: prefix$1?.format() }) + message;
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
return message;
|
|
752
|
+
}
|
|
753
|
+
fields(message, options) {
|
|
754
|
+
if (this.options?.fields?.prefix) message = this.prefix(message, ...this.options.fields.prefix);
|
|
755
|
+
if (options?.prefix) message = this.prefix(message, ...options.prefix);
|
|
756
|
+
if (options?.suffix) message = this.suffix(message, ...options.suffix);
|
|
757
|
+
if (this.options?.fields?.suffix) message = this.suffix(message, ...this.options.fields.suffix);
|
|
758
|
+
return message;
|
|
759
|
+
}
|
|
760
|
+
icon(level, icon) {
|
|
761
|
+
if (!level) return null;
|
|
762
|
+
if (!icon) {
|
|
763
|
+
const i = this.options.icon?.[level];
|
|
764
|
+
icon = typeof i === "function" ? i() : i;
|
|
765
|
+
}
|
|
766
|
+
const coloring = this.options.color?.[level];
|
|
767
|
+
if (icon && coloring) icon = coloring(icon);
|
|
768
|
+
return icon;
|
|
769
|
+
}
|
|
770
|
+
format(level, message, options) {
|
|
771
|
+
if (!Array.isArray(message)) message = [message];
|
|
772
|
+
message = this.splat(message.shift(), ...message).toString().split(EOL).filter((m) => !m || m.trim() !== "").map((m) => {
|
|
773
|
+
return this.style(level, this.fields(m, {
|
|
774
|
+
prefix: Array.isArray(options?.prefix) ? options.prefix : [options?.prefix],
|
|
775
|
+
suffix: Array.isArray(options?.suffix) ? options.suffix : [options?.suffix]
|
|
776
|
+
}));
|
|
777
|
+
}).join(EOL);
|
|
778
|
+
return message;
|
|
779
|
+
}
|
|
780
|
+
style(level, message) {
|
|
781
|
+
if (!level || !message) return message;
|
|
782
|
+
const icon = this.icon(level, !this.options.useIcons && this.wrap(level));
|
|
783
|
+
if (icon) message = icon + " " + message;
|
|
784
|
+
return message;
|
|
785
|
+
}
|
|
786
|
+
applyFormat(message, options) {
|
|
787
|
+
if (options?.format) return options.format(message);
|
|
788
|
+
return message;
|
|
789
|
+
}
|
|
790
|
+
spacing(message) {
|
|
791
|
+
return typeof message === "undefined" || message.trim() === "" ? "" : " ";
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
var ProcessOutputBuffer = class {
|
|
795
|
+
buffer = [];
|
|
796
|
+
decoder = new StringDecoder();
|
|
797
|
+
constructor(options) {
|
|
798
|
+
this.options = options;
|
|
799
|
+
}
|
|
800
|
+
get all() {
|
|
801
|
+
return this.buffer;
|
|
802
|
+
}
|
|
803
|
+
get last() {
|
|
804
|
+
return this.buffer.at(-1);
|
|
805
|
+
}
|
|
806
|
+
get length() {
|
|
807
|
+
return this.buffer.length;
|
|
808
|
+
}
|
|
809
|
+
write(data, ...args) {
|
|
810
|
+
const callback = args[args.length - 1];
|
|
811
|
+
this.buffer.push({
|
|
812
|
+
time: Date.now(),
|
|
813
|
+
stream: this.options?.stream,
|
|
814
|
+
entry: this.decoder.write(typeof data === "string" ? Buffer.from(data, typeof args[0] === "string" ? args[0] : void 0) : Buffer.from(data))
|
|
815
|
+
});
|
|
816
|
+
if (this.options?.limit) this.buffer = this.buffer.slice(-this.options.limit);
|
|
817
|
+
if (typeof callback === "function") callback();
|
|
818
|
+
return true;
|
|
819
|
+
}
|
|
820
|
+
reset() {
|
|
821
|
+
this.buffer = [];
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
var ProcessOutputStream = class {
|
|
825
|
+
method;
|
|
826
|
+
buffer;
|
|
827
|
+
constructor(stream) {
|
|
828
|
+
this.stream = stream;
|
|
829
|
+
this.method = stream.write;
|
|
830
|
+
this.buffer = new ProcessOutputBuffer({ stream });
|
|
831
|
+
}
|
|
832
|
+
get out() {
|
|
833
|
+
return Object.assign({}, this.stream, { write: this.write.bind(this) });
|
|
834
|
+
}
|
|
835
|
+
hijack() {
|
|
836
|
+
this.stream.write = this.buffer.write.bind(this.buffer);
|
|
837
|
+
}
|
|
838
|
+
release() {
|
|
839
|
+
this.stream.write = this.method;
|
|
840
|
+
const buffer = [...this.buffer.all];
|
|
841
|
+
this.buffer.reset();
|
|
842
|
+
return buffer;
|
|
843
|
+
}
|
|
844
|
+
write(...args) {
|
|
845
|
+
return this.method.apply(this.stream, args);
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
/**
|
|
849
|
+
* Creates a new Listr2 process-output controller.
|
|
850
|
+
*
|
|
851
|
+
* This is used to control the flow to `process.stdout` and `process.stderr` for all renderers.
|
|
852
|
+
*
|
|
853
|
+
* @see {@link https://listr2.kilic.dev/renderer/process-output.html}
|
|
854
|
+
*/
|
|
855
|
+
var ProcessOutput = class {
|
|
856
|
+
stream;
|
|
857
|
+
active;
|
|
858
|
+
constructor(stdout, stderr, options) {
|
|
859
|
+
this.options = options;
|
|
860
|
+
this.stream = {
|
|
861
|
+
stdout: new ProcessOutputStream(stdout ?? process.stdout),
|
|
862
|
+
stderr: new ProcessOutputStream(stderr ?? process.stderr)
|
|
863
|
+
};
|
|
864
|
+
this.options = {
|
|
865
|
+
dump: ["stdout", "stderr"],
|
|
866
|
+
leaveEmptyLine: true,
|
|
867
|
+
...options
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
get stdout() {
|
|
871
|
+
return this.stream.stdout.out;
|
|
872
|
+
}
|
|
873
|
+
get stderr() {
|
|
874
|
+
return this.stream.stderr.out;
|
|
875
|
+
}
|
|
876
|
+
hijack() {
|
|
877
|
+
if (this.active) throw new Error("ProcessOutput has been already hijacked!");
|
|
878
|
+
this.stream.stdout.write(ANSI_ESCAPE_CODES.CURSOR_HIDE);
|
|
879
|
+
Object.values(this.stream).forEach((stream) => stream.hijack());
|
|
880
|
+
this.active = true;
|
|
881
|
+
}
|
|
882
|
+
release() {
|
|
883
|
+
const output = Object.entries(this.stream).map(([name, stream]) => ({
|
|
884
|
+
name,
|
|
885
|
+
buffer: stream.release()
|
|
886
|
+
})).filter((output$1) => this.options.dump.includes(output$1.name)).flatMap((output$1) => output$1.buffer).sort((a, b) => a.time - b.time).map((message) => {
|
|
887
|
+
return {
|
|
888
|
+
...message,
|
|
889
|
+
entry: cleanseAnsi(message.entry)
|
|
890
|
+
};
|
|
891
|
+
}).filter((message) => message.entry);
|
|
892
|
+
if (output.length > 0) {
|
|
893
|
+
if (this.options.leaveEmptyLine) this.stdout.write(EOL);
|
|
894
|
+
output.forEach((message) => {
|
|
895
|
+
const stream = message.stream ?? this.stdout;
|
|
896
|
+
stream.write(message.entry + EOL);
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
this.stream.stdout.write(ANSI_ESCAPE_CODES.CURSOR_SHOW);
|
|
900
|
+
this.active = false;
|
|
901
|
+
}
|
|
902
|
+
toStdout(buffer, eol = true) {
|
|
903
|
+
if (eol) buffer = buffer + EOL;
|
|
904
|
+
return this.stream.stdout.write(buffer);
|
|
905
|
+
}
|
|
906
|
+
toStderr(buffer, eol = true) {
|
|
907
|
+
if (eol) buffer = buffer + EOL;
|
|
908
|
+
return this.stream.stderr.write(buffer);
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
/* istanbul ignore next */
|
|
912
|
+
function createWritable(cb) {
|
|
913
|
+
const writable = new Writable();
|
|
914
|
+
writable.rows = Infinity;
|
|
915
|
+
writable.columns = Infinity;
|
|
916
|
+
writable.write = (chunk) => {
|
|
917
|
+
cb(chunk.toString());
|
|
918
|
+
return true;
|
|
919
|
+
};
|
|
920
|
+
return writable;
|
|
921
|
+
}
|
|
922
|
+
/* istanbul ignore next */
|
|
923
|
+
var Spinner = class {
|
|
924
|
+
spinner = !isUnicodeSupported() ? [
|
|
925
|
+
"-",
|
|
926
|
+
"\\",
|
|
927
|
+
"|",
|
|
928
|
+
"/"
|
|
929
|
+
] : [
|
|
930
|
+
"⠋",
|
|
931
|
+
"⠙",
|
|
932
|
+
"⠹",
|
|
933
|
+
"⠸",
|
|
934
|
+
"⠼",
|
|
935
|
+
"⠴",
|
|
936
|
+
"⠦",
|
|
937
|
+
"⠧",
|
|
938
|
+
"⠇",
|
|
939
|
+
"⠏"
|
|
940
|
+
];
|
|
941
|
+
id;
|
|
942
|
+
spinnerPosition = 0;
|
|
943
|
+
spin() {
|
|
944
|
+
this.spinnerPosition = ++this.spinnerPosition % this.spinner.length;
|
|
945
|
+
}
|
|
946
|
+
fetch() {
|
|
947
|
+
return this.spinner[this.spinnerPosition];
|
|
948
|
+
}
|
|
949
|
+
isRunning() {
|
|
950
|
+
return !!this.id;
|
|
951
|
+
}
|
|
952
|
+
start(cb, interval = 100) {
|
|
953
|
+
this.id = setInterval(() => {
|
|
954
|
+
this.spin();
|
|
955
|
+
if (cb) cb();
|
|
956
|
+
}, interval);
|
|
957
|
+
}
|
|
958
|
+
stop() {
|
|
959
|
+
clearInterval(this.id);
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
let ListrDefaultRendererLogLevels = /* @__PURE__ */ function(ListrDefaultRendererLogLevels$1) {
|
|
963
|
+
ListrDefaultRendererLogLevels$1["SKIPPED_WITH_COLLAPSE"] = "SKIPPED_WITH_COLLAPSE";
|
|
964
|
+
ListrDefaultRendererLogLevels$1["SKIPPED_WITHOUT_COLLAPSE"] = "SKIPPED_WITHOUT_COLLAPSE";
|
|
965
|
+
ListrDefaultRendererLogLevels$1["OUTPUT"] = "OUTPUT";
|
|
966
|
+
ListrDefaultRendererLogLevels$1["OUTPUT_WITH_BOTTOMBAR"] = "OUTPUT_WITH_BOTTOMBAR";
|
|
967
|
+
ListrDefaultRendererLogLevels$1["PENDING"] = "PENDING";
|
|
968
|
+
ListrDefaultRendererLogLevels$1["COMPLETED"] = "COMPLETED";
|
|
969
|
+
ListrDefaultRendererLogLevels$1["COMPLETED_WITH_FAILED_SUBTASKS"] = "COMPLETED_WITH_FAILED_SUBTASKS";
|
|
970
|
+
ListrDefaultRendererLogLevels$1["COMPLETED_WITH_FAILED_SISTER_TASKS"] = "COMPLETED_WITH_SISTER_TASKS_FAILED";
|
|
971
|
+
ListrDefaultRendererLogLevels$1["RETRY"] = "RETRY";
|
|
972
|
+
ListrDefaultRendererLogLevels$1["ROLLING_BACK"] = "ROLLING_BACK";
|
|
973
|
+
ListrDefaultRendererLogLevels$1["ROLLED_BACK"] = "ROLLED_BACK";
|
|
974
|
+
ListrDefaultRendererLogLevels$1["FAILED"] = "FAILED";
|
|
975
|
+
ListrDefaultRendererLogLevels$1["FAILED_WITH_FAILED_SUBTASKS"] = "FAILED_WITH_SUBTASKS";
|
|
976
|
+
ListrDefaultRendererLogLevels$1["WAITING"] = "WAITING";
|
|
977
|
+
ListrDefaultRendererLogLevels$1["PAUSED"] = "PAUSED";
|
|
978
|
+
return ListrDefaultRendererLogLevels$1;
|
|
979
|
+
}({});
|
|
980
|
+
const LISTR_DEFAULT_RENDERER_STYLE = {
|
|
981
|
+
icon: {
|
|
982
|
+
[ListrDefaultRendererLogLevels.SKIPPED_WITH_COLLAPSE]: figures.arrowDown,
|
|
983
|
+
[ListrDefaultRendererLogLevels.SKIPPED_WITHOUT_COLLAPSE]: figures.warning,
|
|
984
|
+
[ListrDefaultRendererLogLevels.OUTPUT]: figures.pointerSmall,
|
|
985
|
+
[ListrDefaultRendererLogLevels.OUTPUT_WITH_BOTTOMBAR]: figures.pointerSmall,
|
|
986
|
+
[ListrDefaultRendererLogLevels.PENDING]: figures.pointer,
|
|
987
|
+
[ListrDefaultRendererLogLevels.COMPLETED]: figures.tick,
|
|
988
|
+
[ListrDefaultRendererLogLevels.COMPLETED_WITH_FAILED_SUBTASKS]: figures.warning,
|
|
989
|
+
[ListrDefaultRendererLogLevels.COMPLETED_WITH_FAILED_SISTER_TASKS]: figures.squareSmallFilled,
|
|
990
|
+
[ListrDefaultRendererLogLevels.RETRY]: figures.warning,
|
|
991
|
+
[ListrDefaultRendererLogLevels.ROLLING_BACK]: figures.warning,
|
|
992
|
+
[ListrDefaultRendererLogLevels.ROLLED_BACK]: figures.arrowLeft,
|
|
993
|
+
[ListrDefaultRendererLogLevels.FAILED]: figures.cross,
|
|
994
|
+
[ListrDefaultRendererLogLevels.FAILED_WITH_FAILED_SUBTASKS]: figures.pointer,
|
|
995
|
+
[ListrDefaultRendererLogLevels.WAITING]: figures.squareSmallFilled,
|
|
996
|
+
[ListrDefaultRendererLogLevels.PAUSED]: figures.squareSmallFilled
|
|
997
|
+
},
|
|
998
|
+
color: {
|
|
999
|
+
[ListrDefaultRendererLogLevels.SKIPPED_WITH_COLLAPSE]: color.yellow,
|
|
1000
|
+
[ListrDefaultRendererLogLevels.SKIPPED_WITHOUT_COLLAPSE]: color.yellow,
|
|
1001
|
+
[ListrDefaultRendererLogLevels.PENDING]: color.yellow,
|
|
1002
|
+
[ListrDefaultRendererLogLevels.COMPLETED]: color.green,
|
|
1003
|
+
[ListrDefaultRendererLogLevels.COMPLETED_WITH_FAILED_SUBTASKS]: color.yellow,
|
|
1004
|
+
[ListrDefaultRendererLogLevels.COMPLETED_WITH_FAILED_SISTER_TASKS]: color.red,
|
|
1005
|
+
[ListrDefaultRendererLogLevels.RETRY]: color.yellowBright,
|
|
1006
|
+
[ListrDefaultRendererLogLevels.ROLLING_BACK]: color.redBright,
|
|
1007
|
+
[ListrDefaultRendererLogLevels.ROLLED_BACK]: color.redBright,
|
|
1008
|
+
[ListrDefaultRendererLogLevels.FAILED]: color.red,
|
|
1009
|
+
[ListrDefaultRendererLogLevels.FAILED_WITH_FAILED_SUBTASKS]: color.red,
|
|
1010
|
+
[ListrDefaultRendererLogLevels.WAITING]: color.dim,
|
|
1011
|
+
[ListrDefaultRendererLogLevels.PAUSED]: color.yellowBright
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
/**
|
|
1015
|
+
* A basic function to parse minutes and tasks passed given a duration.
|
|
1016
|
+
* Useful for renderers to show the task time.
|
|
1017
|
+
*/
|
|
1018
|
+
/* istanbul ignore next */
|
|
1019
|
+
function parseTimer(duration) {
|
|
1020
|
+
const seconds = Math.floor(duration / 1e3);
|
|
1021
|
+
const minutes = Math.floor(seconds / 60);
|
|
1022
|
+
let parsedTime;
|
|
1023
|
+
if (seconds === 0 && minutes === 0) parsedTime = `0.${Math.floor(duration / 100)}s`;
|
|
1024
|
+
if (seconds > 0) parsedTime = `${seconds % 60}s`;
|
|
1025
|
+
if (minutes > 0) parsedTime = `${minutes}m${parsedTime}`;
|
|
1026
|
+
return parsedTime;
|
|
1027
|
+
}
|
|
1028
|
+
/* istanbul ignore next */
|
|
1029
|
+
const PRESET_TIMER = {
|
|
1030
|
+
condition: true,
|
|
1031
|
+
field: parseTimer,
|
|
1032
|
+
format: () => color.dim
|
|
1033
|
+
};
|
|
1034
|
+
var DefaultRenderer = class DefaultRenderer$1 {
|
|
1035
|
+
static nonTTY = false;
|
|
1036
|
+
static rendererOptions = {
|
|
1037
|
+
indentation: 2,
|
|
1038
|
+
clearOutput: false,
|
|
1039
|
+
showSubtasks: true,
|
|
1040
|
+
collapseSubtasks: true,
|
|
1041
|
+
collapseSkips: true,
|
|
1042
|
+
showSkipMessage: true,
|
|
1043
|
+
suffixSkips: false,
|
|
1044
|
+
collapseErrors: true,
|
|
1045
|
+
showErrorMessage: true,
|
|
1046
|
+
suffixRetries: true,
|
|
1047
|
+
lazy: false,
|
|
1048
|
+
removeEmptyLines: true,
|
|
1049
|
+
formatOutput: "wrap",
|
|
1050
|
+
pausedTimer: {
|
|
1051
|
+
...PRESET_TIMER,
|
|
1052
|
+
format: () => color.yellowBright
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
1055
|
+
static rendererTaskOptions = { outputBar: true };
|
|
1056
|
+
prompt;
|
|
1057
|
+
activePrompt;
|
|
1058
|
+
spinner;
|
|
1059
|
+
logger;
|
|
1060
|
+
updater;
|
|
1061
|
+
truncate;
|
|
1062
|
+
wrap;
|
|
1063
|
+
buffer = {
|
|
1064
|
+
output: /* @__PURE__ */ new Map(),
|
|
1065
|
+
bottom: /* @__PURE__ */ new Map()
|
|
1066
|
+
};
|
|
1067
|
+
cache = {
|
|
1068
|
+
render: /* @__PURE__ */ new Map(),
|
|
1069
|
+
rendererOptions: /* @__PURE__ */ new Map(),
|
|
1070
|
+
rendererTaskOptions: /* @__PURE__ */ new Map()
|
|
1071
|
+
};
|
|
1072
|
+
constructor(tasks, options, events) {
|
|
1073
|
+
this.tasks = tasks;
|
|
1074
|
+
this.options = options;
|
|
1075
|
+
this.events = events;
|
|
1076
|
+
this.options = {
|
|
1077
|
+
...DefaultRenderer$1.rendererOptions,
|
|
1078
|
+
...this.options,
|
|
1079
|
+
icon: {
|
|
1080
|
+
...LISTR_DEFAULT_RENDERER_STYLE.icon,
|
|
1081
|
+
...options?.icon ?? {}
|
|
1082
|
+
},
|
|
1083
|
+
color: {
|
|
1084
|
+
...LISTR_DEFAULT_RENDERER_STYLE.color,
|
|
1085
|
+
...options?.color ?? {}
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
this.spinner = this.options.spinner ?? new Spinner();
|
|
1089
|
+
this.logger = this.options.logger ?? new ListrLogger({
|
|
1090
|
+
useIcons: true,
|
|
1091
|
+
toStderr: []
|
|
1092
|
+
});
|
|
1093
|
+
this.logger.options.icon = this.options.icon;
|
|
1094
|
+
this.logger.options.color = this.options.color;
|
|
1095
|
+
}
|
|
1096
|
+
async render() {
|
|
1097
|
+
const { createLogUpdate } = await import("./log-update-waQufObt.js");
|
|
1098
|
+
const { default: truncate } = await import("./cli-truncate-DY-z6Ecp.js");
|
|
1099
|
+
const { default: wrap } = await import("./wrap-ansi-CVXwzrKr.js");
|
|
1100
|
+
this.updater = createLogUpdate(this.logger.process.stdout);
|
|
1101
|
+
this.truncate = truncate;
|
|
1102
|
+
this.wrap = wrap;
|
|
1103
|
+
this.logger.process.hijack();
|
|
1104
|
+
/* istanbul ignore if */
|
|
1105
|
+
if (!this.options?.lazy) this.spinner.start(() => {
|
|
1106
|
+
this.update();
|
|
1107
|
+
});
|
|
1108
|
+
this.events.on(ListrEventType.SHOULD_REFRESH_RENDER, () => {
|
|
1109
|
+
this.update();
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
update() {
|
|
1113
|
+
this.updater(this.create());
|
|
1114
|
+
}
|
|
1115
|
+
end() {
|
|
1116
|
+
this.spinner.stop();
|
|
1117
|
+
this.updater.clear();
|
|
1118
|
+
this.updater.done();
|
|
1119
|
+
if (!this.options.clearOutput) this.logger.process.toStdout(this.create({ prompt: false }));
|
|
1120
|
+
this.logger.process.release();
|
|
1121
|
+
}
|
|
1122
|
+
create(options) {
|
|
1123
|
+
options = {
|
|
1124
|
+
tasks: true,
|
|
1125
|
+
bottomBar: true,
|
|
1126
|
+
prompt: true,
|
|
1127
|
+
...options
|
|
1128
|
+
};
|
|
1129
|
+
const render = [];
|
|
1130
|
+
const renderTasks = this.renderer(this.tasks);
|
|
1131
|
+
const renderBottomBar = this.renderBottomBar();
|
|
1132
|
+
const renderPrompt = this.renderPrompt();
|
|
1133
|
+
if (options.tasks && renderTasks.length > 0) render.push(...renderTasks);
|
|
1134
|
+
if (options.bottomBar && renderBottomBar.length > 0) {
|
|
1135
|
+
if (render.length > 0) render.push("");
|
|
1136
|
+
render.push(...renderBottomBar);
|
|
1137
|
+
}
|
|
1138
|
+
if (options.prompt && renderPrompt.length > 0) {
|
|
1139
|
+
if (render.length > 0) render.push("");
|
|
1140
|
+
render.push(...renderPrompt);
|
|
1141
|
+
}
|
|
1142
|
+
return render.join(EOL);
|
|
1143
|
+
}
|
|
1144
|
+
style(task, output = false) {
|
|
1145
|
+
const rendererOptions = this.cache.rendererOptions.get(task.id);
|
|
1146
|
+
if (task.isSkipped()) {
|
|
1147
|
+
if (output || rendererOptions.collapseSkips) return this.logger.icon(ListrDefaultRendererLogLevels.SKIPPED_WITH_COLLAPSE);
|
|
1148
|
+
else if (rendererOptions.collapseSkips === false) return this.logger.icon(ListrDefaultRendererLogLevels.SKIPPED_WITHOUT_COLLAPSE);
|
|
1149
|
+
}
|
|
1150
|
+
if (output) {
|
|
1151
|
+
if (this.shouldOutputToBottomBar(task)) return this.logger.icon(ListrDefaultRendererLogLevels.OUTPUT_WITH_BOTTOMBAR);
|
|
1152
|
+
return this.logger.icon(ListrDefaultRendererLogLevels.OUTPUT);
|
|
1153
|
+
}
|
|
1154
|
+
if (task.hasSubtasks()) {
|
|
1155
|
+
if (task.isStarted() || task.isPrompt() && rendererOptions.showSubtasks !== false && !task.subtasks.every((subtask) => !subtask.hasTitle())) return this.logger.icon(ListrDefaultRendererLogLevels.PENDING);
|
|
1156
|
+
else if (task.isCompleted() && task.subtasks.some((subtask) => subtask.hasFailed())) return this.logger.icon(ListrDefaultRendererLogLevels.COMPLETED_WITH_FAILED_SUBTASKS);
|
|
1157
|
+
else if (task.hasFailed()) return this.logger.icon(ListrDefaultRendererLogLevels.FAILED_WITH_FAILED_SUBTASKS);
|
|
1158
|
+
}
|
|
1159
|
+
if (task.isStarted() || task.isPrompt()) return this.logger.icon(ListrDefaultRendererLogLevels.PENDING, !this.options?.lazy && this.spinner.fetch());
|
|
1160
|
+
else if (task.isCompleted()) return this.logger.icon(ListrDefaultRendererLogLevels.COMPLETED);
|
|
1161
|
+
else if (task.isRetrying()) return this.logger.icon(ListrDefaultRendererLogLevels.RETRY, !this.options?.lazy && this.spinner.fetch());
|
|
1162
|
+
else if (task.isRollingBack()) return this.logger.icon(ListrDefaultRendererLogLevels.ROLLING_BACK, !this.options?.lazy && this.spinner.fetch());
|
|
1163
|
+
else if (task.hasRolledBack()) return this.logger.icon(ListrDefaultRendererLogLevels.ROLLED_BACK);
|
|
1164
|
+
else if (task.hasFailed()) return this.logger.icon(ListrDefaultRendererLogLevels.FAILED);
|
|
1165
|
+
else if (task.isPaused()) return this.logger.icon(ListrDefaultRendererLogLevels.PAUSED);
|
|
1166
|
+
return this.logger.icon(ListrDefaultRendererLogLevels.WAITING);
|
|
1167
|
+
}
|
|
1168
|
+
format(message, icon, level) {
|
|
1169
|
+
if (message.trim() === "") return [];
|
|
1170
|
+
if (icon) message = icon + " " + message;
|
|
1171
|
+
let parsed;
|
|
1172
|
+
const columns = (process.stdout.columns ?? 80) - level * this.options.indentation - 2;
|
|
1173
|
+
switch (this.options.formatOutput) {
|
|
1174
|
+
case "truncate":
|
|
1175
|
+
parsed = message.split(EOL).map((s, i) => {
|
|
1176
|
+
return this.truncate(this.indent(s, i), columns);
|
|
1177
|
+
});
|
|
1178
|
+
break;
|
|
1179
|
+
case "wrap":
|
|
1180
|
+
parsed = this.wrap(message, columns, {
|
|
1181
|
+
hard: true,
|
|
1182
|
+
trim: false
|
|
1183
|
+
}).split(EOL).map((s, i) => this.indent(s, i));
|
|
1184
|
+
break;
|
|
1185
|
+
default: throw new ListrRendererError("Format option for the renderer is wrong.");
|
|
1186
|
+
}
|
|
1187
|
+
if (this.options.removeEmptyLines) parsed = parsed.filter(Boolean);
|
|
1188
|
+
return parsed.map((str) => indent(str, level * this.options.indentation));
|
|
1189
|
+
}
|
|
1190
|
+
shouldOutputToOutputBar(task) {
|
|
1191
|
+
const outputBar = this.cache.rendererTaskOptions.get(task.id).outputBar;
|
|
1192
|
+
return typeof outputBar === "number" && outputBar !== 0 || typeof outputBar === "boolean" && outputBar !== false;
|
|
1193
|
+
}
|
|
1194
|
+
shouldOutputToBottomBar(task) {
|
|
1195
|
+
const bottomBar = this.cache.rendererTaskOptions.get(task.id).bottomBar;
|
|
1196
|
+
return typeof bottomBar === "number" && bottomBar !== 0 || typeof bottomBar === "boolean" && bottomBar !== false || !task.hasTitle();
|
|
1197
|
+
}
|
|
1198
|
+
renderer(tasks, level = 0) {
|
|
1199
|
+
return tasks.flatMap((task) => {
|
|
1200
|
+
if (!task.isEnabled()) return [];
|
|
1201
|
+
if (this.cache.render.has(task.id)) return this.cache.render.get(task.id);
|
|
1202
|
+
this.calculate(task);
|
|
1203
|
+
this.setupBuffer(task);
|
|
1204
|
+
const rendererOptions = this.cache.rendererOptions.get(task.id);
|
|
1205
|
+
const rendererTaskOptions = this.cache.rendererTaskOptions.get(task.id);
|
|
1206
|
+
const output = [];
|
|
1207
|
+
if (task.isPrompt()) {
|
|
1208
|
+
if (this.activePrompt && this.activePrompt !== task.id) throw new ListrRendererError("Only one prompt can be active at the given time, please re-evaluate your task design.");
|
|
1209
|
+
else if (!this.activePrompt) {
|
|
1210
|
+
task.on(ListrTaskEventType.PROMPT, (prompt) => {
|
|
1211
|
+
const cleansed = cleanseAnsi(prompt);
|
|
1212
|
+
if (cleansed) this.prompt = cleansed;
|
|
1213
|
+
});
|
|
1214
|
+
task.on(ListrTaskEventType.STATE, (state) => {
|
|
1215
|
+
if (state === ListrTaskState.PROMPT_COMPLETED || task.hasFinalized() || task.hasReset()) {
|
|
1216
|
+
this.prompt = null;
|
|
1217
|
+
this.activePrompt = null;
|
|
1218
|
+
task.off(ListrTaskEventType.PROMPT);
|
|
1219
|
+
}
|
|
1220
|
+
});
|
|
1221
|
+
this.activePrompt = task.id;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
if (task.hasTitle()) if (!(tasks.some((task$1) => task$1.hasFailed()) && !task.hasFailed() && task.options.exitOnError !== false && !(task.isCompleted() || task.isSkipped()))) if (task.hasFailed() && rendererOptions.collapseErrors) output.push(...this.format(!task.hasSubtasks() && task.message.error && rendererOptions.showErrorMessage ? task.message.error : task.title, this.style(task), level));
|
|
1225
|
+
else if (task.isSkipped() && rendererOptions.collapseSkips) output.push(...this.format(this.logger.suffix(task.message.skip && rendererOptions.showSkipMessage ? task.message.skip : task.title, {
|
|
1226
|
+
field: ListrLogLevels.SKIPPED,
|
|
1227
|
+
condition: rendererOptions.suffixSkips,
|
|
1228
|
+
format: () => color.dim
|
|
1229
|
+
}), this.style(task), level));
|
|
1230
|
+
else if (task.isRetrying()) output.push(...this.format(this.logger.suffix(task.title, {
|
|
1231
|
+
field: `${ListrLogLevels.RETRY}:${task.message.retry.count}`,
|
|
1232
|
+
format: () => color.yellow,
|
|
1233
|
+
condition: rendererOptions.suffixRetries
|
|
1234
|
+
}), this.style(task), level));
|
|
1235
|
+
else if (task.isCompleted() && task.hasTitle() && assertFunctionOrSelf(rendererTaskOptions.timer?.condition, task.message.duration)) output.push(...this.format(this.logger.suffix(task?.title, {
|
|
1236
|
+
...rendererTaskOptions.timer,
|
|
1237
|
+
args: [task.message.duration]
|
|
1238
|
+
}), this.style(task), level));
|
|
1239
|
+
else if (task.isPaused()) output.push(...this.format(this.logger.suffix(task.title, {
|
|
1240
|
+
...rendererOptions.pausedTimer,
|
|
1241
|
+
args: [task.message.paused - Date.now()]
|
|
1242
|
+
}), this.style(task), level));
|
|
1243
|
+
else output.push(...this.format(task.title, this.style(task), level));
|
|
1244
|
+
else output.push(...this.format(task.title, this.logger.icon(ListrDefaultRendererLogLevels.COMPLETED_WITH_FAILED_SISTER_TASKS), level));
|
|
1245
|
+
if (!task.hasSubtasks() || !rendererOptions.showSubtasks) {
|
|
1246
|
+
if (task.hasFailed() && rendererOptions.collapseErrors === false && (rendererOptions.showErrorMessage || !rendererOptions.showSubtasks)) output.push(...this.dump(task, level, ListrLogLevels.FAILED));
|
|
1247
|
+
else if (task.isSkipped() && rendererOptions.collapseSkips === false && (rendererOptions.showSkipMessage || !rendererOptions.showSubtasks)) output.push(...this.dump(task, level, ListrLogLevels.SKIPPED));
|
|
1248
|
+
}
|
|
1249
|
+
if (task.isPending() || rendererTaskOptions.persistentOutput) output.push(...this.renderOutputBar(task, level));
|
|
1250
|
+
if (rendererOptions.showSubtasks !== false && task.hasSubtasks() && (task.isPending() || task.hasFinalized() && !task.hasTitle() || task.isCompleted() && rendererOptions.collapseSubtasks === false && !task.subtasks.some((subtask) => this.cache.rendererOptions.get(subtask.id)?.collapseSubtasks === true) || task.subtasks.some((subtask) => this.cache.rendererOptions.get(subtask.id)?.collapseSubtasks === false) || task.subtasks.some((subtask) => subtask.hasFailed()) || task.subtasks.some((subtask) => subtask.hasRolledBack()))) {
|
|
1251
|
+
const subtaskLevel = !task.hasTitle() ? level : level + 1;
|
|
1252
|
+
const subtaskRender = this.renderer(task.subtasks, subtaskLevel);
|
|
1253
|
+
output.push(...subtaskRender);
|
|
1254
|
+
}
|
|
1255
|
+
if (task.hasFinalized()) {
|
|
1256
|
+
if (!rendererTaskOptions.persistentOutput) {
|
|
1257
|
+
this.buffer.bottom.delete(task.id);
|
|
1258
|
+
this.buffer.output.delete(task.id);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
if (task.isClosed()) {
|
|
1262
|
+
this.cache.render.set(task.id, output);
|
|
1263
|
+
this.reset(task);
|
|
1264
|
+
}
|
|
1265
|
+
return output;
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
renderOutputBar(task, level) {
|
|
1269
|
+
const output = this.buffer.output.get(task.id);
|
|
1270
|
+
if (!output) return [];
|
|
1271
|
+
return output.all.flatMap((o) => this.dump(task, level, ListrLogLevels.OUTPUT, o.entry));
|
|
1272
|
+
}
|
|
1273
|
+
renderBottomBar() {
|
|
1274
|
+
if (this.buffer.bottom.size === 0) return [];
|
|
1275
|
+
return Array.from(this.buffer.bottom.values()).flatMap((output) => output.all).sort((a, b) => a.time - b.time).map((output) => output.entry);
|
|
1276
|
+
}
|
|
1277
|
+
renderPrompt() {
|
|
1278
|
+
if (!this.prompt) return [];
|
|
1279
|
+
return [this.prompt];
|
|
1280
|
+
}
|
|
1281
|
+
calculate(task) {
|
|
1282
|
+
if (this.cache.rendererOptions.has(task.id) && this.cache.rendererTaskOptions.has(task.id)) return;
|
|
1283
|
+
const rendererOptions = {
|
|
1284
|
+
...this.options,
|
|
1285
|
+
...task.rendererOptions
|
|
1286
|
+
};
|
|
1287
|
+
this.cache.rendererOptions.set(task.id, rendererOptions);
|
|
1288
|
+
this.cache.rendererTaskOptions.set(task.id, {
|
|
1289
|
+
...DefaultRenderer$1.rendererTaskOptions,
|
|
1290
|
+
timer: rendererOptions.timer,
|
|
1291
|
+
...task.rendererTaskOptions
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
setupBuffer(task) {
|
|
1295
|
+
if (this.buffer.bottom.has(task.id) || this.buffer.output.has(task.id)) return;
|
|
1296
|
+
const rendererTaskOptions = this.cache.rendererTaskOptions.get(task.id);
|
|
1297
|
+
if (this.shouldOutputToBottomBar(task) && !this.buffer.bottom.has(task.id)) {
|
|
1298
|
+
this.buffer.bottom.set(task.id, new ProcessOutputBuffer({ limit: typeof rendererTaskOptions.bottomBar === "number" ? rendererTaskOptions.bottomBar : 1 }));
|
|
1299
|
+
task.on(ListrTaskEventType.OUTPUT, (output) => {
|
|
1300
|
+
const data = this.dump(task, -1, ListrLogLevels.OUTPUT, output);
|
|
1301
|
+
this.buffer.bottom.get(task.id).write(data.join(EOL));
|
|
1302
|
+
});
|
|
1303
|
+
task.on(ListrTaskEventType.STATE, (state) => {
|
|
1304
|
+
switch (state) {
|
|
1305
|
+
case ListrTaskState.RETRY || ListrTaskState.ROLLING_BACK:
|
|
1306
|
+
this.buffer.bottom.delete(task.id);
|
|
1307
|
+
break;
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
} else if (this.shouldOutputToOutputBar(task) && !this.buffer.output.has(task.id)) {
|
|
1311
|
+
this.buffer.output.set(task.id, new ProcessOutputBuffer({ limit: typeof rendererTaskOptions.outputBar === "number" ? rendererTaskOptions.outputBar : 1 }));
|
|
1312
|
+
task.on(ListrTaskEventType.OUTPUT, (output) => {
|
|
1313
|
+
this.buffer.output.get(task.id).write(output);
|
|
1314
|
+
});
|
|
1315
|
+
task.on(ListrTaskEventType.STATE, (state) => {
|
|
1316
|
+
switch (state) {
|
|
1317
|
+
case ListrTaskState.RETRY || ListrTaskState.ROLLING_BACK:
|
|
1318
|
+
this.buffer.output.delete(task.id);
|
|
1319
|
+
break;
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
reset(task) {
|
|
1325
|
+
this.cache.rendererOptions.delete(task.id);
|
|
1326
|
+
this.cache.rendererTaskOptions.delete(task.id);
|
|
1327
|
+
this.buffer.output.delete(task.id);
|
|
1328
|
+
}
|
|
1329
|
+
dump(task, level, source = ListrLogLevels.OUTPUT, data) {
|
|
1330
|
+
if (!data) switch (source) {
|
|
1331
|
+
case ListrLogLevels.OUTPUT:
|
|
1332
|
+
data = task.output;
|
|
1333
|
+
break;
|
|
1334
|
+
case ListrLogLevels.SKIPPED:
|
|
1335
|
+
data = task.message.skip;
|
|
1336
|
+
break;
|
|
1337
|
+
case ListrLogLevels.FAILED:
|
|
1338
|
+
data = task.message.error;
|
|
1339
|
+
break;
|
|
1340
|
+
}
|
|
1341
|
+
if (task.hasTitle() && source === ListrLogLevels.FAILED && data === task.title || typeof data !== "string") return [];
|
|
1342
|
+
if (source === ListrLogLevels.OUTPUT) data = cleanseAnsi(data);
|
|
1343
|
+
return this.format(data, this.style(task, true), level + 1);
|
|
1344
|
+
}
|
|
1345
|
+
indent(str, i) {
|
|
1346
|
+
return i > 0 ? indent(str.trimEnd(), this.options.indentation) : str.trimEnd();
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
var SilentRenderer = class {
|
|
1350
|
+
static nonTTY = true;
|
|
1351
|
+
static rendererOptions;
|
|
1352
|
+
static rendererTaskOptions;
|
|
1353
|
+
constructor(tasks, options) {
|
|
1354
|
+
this.tasks = tasks;
|
|
1355
|
+
this.options = options;
|
|
1356
|
+
}
|
|
1357
|
+
render() {
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
end() {
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1363
|
+
};
|
|
1364
|
+
var SimpleRenderer = class SimpleRenderer$1 {
|
|
1365
|
+
static nonTTY = true;
|
|
1366
|
+
static rendererOptions = { pausedTimer: {
|
|
1367
|
+
...PRESET_TIMER,
|
|
1368
|
+
field: (time) => `${ListrLogLevels.PAUSED}:${time}`,
|
|
1369
|
+
format: () => color.yellowBright
|
|
1370
|
+
} };
|
|
1371
|
+
static rendererTaskOptions = {};
|
|
1372
|
+
logger;
|
|
1373
|
+
cache = {
|
|
1374
|
+
rendererOptions: /* @__PURE__ */ new Map(),
|
|
1375
|
+
rendererTaskOptions: /* @__PURE__ */ new Map()
|
|
1376
|
+
};
|
|
1377
|
+
constructor(tasks, options) {
|
|
1378
|
+
this.tasks = tasks;
|
|
1379
|
+
this.options = options;
|
|
1380
|
+
this.options = {
|
|
1381
|
+
...SimpleRenderer$1.rendererOptions,
|
|
1382
|
+
...options,
|
|
1383
|
+
icon: {
|
|
1384
|
+
...LISTR_LOGGER_STYLE.icon,
|
|
1385
|
+
...options?.icon ?? {}
|
|
1386
|
+
},
|
|
1387
|
+
color: {
|
|
1388
|
+
...LISTR_LOGGER_STYLE.color,
|
|
1389
|
+
...options?.color ?? {}
|
|
1390
|
+
}
|
|
1391
|
+
};
|
|
1392
|
+
this.logger = this.options.logger ?? new ListrLogger({
|
|
1393
|
+
useIcons: true,
|
|
1394
|
+
toStderr: LISTR_LOGGER_STDERR_LEVELS
|
|
1395
|
+
});
|
|
1396
|
+
this.logger.options.icon = this.options.icon;
|
|
1397
|
+
this.logger.options.color = this.options.color;
|
|
1398
|
+
if (this.options.timestamp) this.logger.options.fields.prefix.unshift(this.options.timestamp);
|
|
1399
|
+
}
|
|
1400
|
+
end() {}
|
|
1401
|
+
render() {
|
|
1402
|
+
this.renderer(this.tasks);
|
|
1403
|
+
}
|
|
1404
|
+
renderer(tasks) {
|
|
1405
|
+
tasks.forEach((task) => {
|
|
1406
|
+
this.calculate(task);
|
|
1407
|
+
task.once(ListrTaskEventType.CLOSED, () => {
|
|
1408
|
+
this.reset(task);
|
|
1409
|
+
});
|
|
1410
|
+
const rendererOptions = this.cache.rendererOptions.get(task.id);
|
|
1411
|
+
const rendererTaskOptions = this.cache.rendererTaskOptions.get(task.id);
|
|
1412
|
+
task.on(ListrTaskEventType.SUBTASK, (subtasks) => {
|
|
1413
|
+
this.renderer(subtasks);
|
|
1414
|
+
});
|
|
1415
|
+
task.on(ListrTaskEventType.STATE, (state) => {
|
|
1416
|
+
if (!task.hasTitle()) return;
|
|
1417
|
+
if (state === ListrTaskState.STARTED) this.logger.log(ListrLogLevels.STARTED, task.title);
|
|
1418
|
+
else if (state === ListrTaskState.COMPLETED) {
|
|
1419
|
+
const timer = rendererTaskOptions?.timer;
|
|
1420
|
+
this.logger.log(ListrLogLevels.COMPLETED, task.title, timer && { suffix: {
|
|
1421
|
+
...timer,
|
|
1422
|
+
condition: !!task.message?.duration && timer.condition,
|
|
1423
|
+
args: [task.message.duration]
|
|
1424
|
+
} });
|
|
1425
|
+
} else if (state === ListrTaskState.PROMPT) {
|
|
1426
|
+
this.logger.process.hijack();
|
|
1427
|
+
task.on(ListrTaskEventType.PROMPT, (prompt) => {
|
|
1428
|
+
this.logger.process.toStderr(prompt, false);
|
|
1429
|
+
});
|
|
1430
|
+
} else if (state === ListrTaskState.PROMPT_COMPLETED) {
|
|
1431
|
+
task.off(ListrTaskEventType.PROMPT);
|
|
1432
|
+
this.logger.process.release();
|
|
1433
|
+
}
|
|
1434
|
+
});
|
|
1435
|
+
task.on(ListrTaskEventType.OUTPUT, (output) => {
|
|
1436
|
+
this.logger.log(ListrLogLevels.OUTPUT, output);
|
|
1437
|
+
});
|
|
1438
|
+
task.on(ListrTaskEventType.MESSAGE, (message) => {
|
|
1439
|
+
if (message.error) this.logger.log(ListrLogLevels.FAILED, task.title, { suffix: {
|
|
1440
|
+
field: `${ListrLogLevels.FAILED}: ${message.error}`,
|
|
1441
|
+
format: () => color.red
|
|
1442
|
+
} });
|
|
1443
|
+
else if (message.skip) this.logger.log(ListrLogLevels.SKIPPED, task.title, { suffix: {
|
|
1444
|
+
field: `${ListrLogLevels.SKIPPED}: ${message.skip}`,
|
|
1445
|
+
format: () => color.yellow
|
|
1446
|
+
} });
|
|
1447
|
+
else if (message.rollback) this.logger.log(ListrLogLevels.ROLLBACK, task.title, { suffix: {
|
|
1448
|
+
field: `${ListrLogLevels.ROLLBACK}: ${message.rollback}`,
|
|
1449
|
+
format: () => color.red
|
|
1450
|
+
} });
|
|
1451
|
+
else if (message.retry) this.logger.log(ListrLogLevels.RETRY, task.title, { suffix: {
|
|
1452
|
+
field: `${ListrLogLevels.RETRY}:${message.retry.count}`,
|
|
1453
|
+
format: () => color.red
|
|
1454
|
+
} });
|
|
1455
|
+
else if (message.paused) {
|
|
1456
|
+
const timer = rendererOptions?.pausedTimer;
|
|
1457
|
+
this.logger.log(ListrLogLevels.PAUSED, task.title, timer && { suffix: {
|
|
1458
|
+
...timer,
|
|
1459
|
+
condition: !!message?.paused && timer.condition,
|
|
1460
|
+
args: [message.paused - Date.now()]
|
|
1461
|
+
} });
|
|
1462
|
+
}
|
|
1463
|
+
});
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
calculate(task) {
|
|
1467
|
+
if (this.cache.rendererOptions.has(task.id) && this.cache.rendererTaskOptions.has(task.id)) return;
|
|
1468
|
+
const rendererOptions = {
|
|
1469
|
+
...this.options,
|
|
1470
|
+
...task.rendererOptions
|
|
1471
|
+
};
|
|
1472
|
+
this.cache.rendererOptions.set(task.id, rendererOptions);
|
|
1473
|
+
this.cache.rendererTaskOptions.set(task.id, {
|
|
1474
|
+
...SimpleRenderer$1.rendererTaskOptions,
|
|
1475
|
+
timer: rendererOptions.timer,
|
|
1476
|
+
...task.rendererTaskOptions
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
reset(task) {
|
|
1480
|
+
this.cache.rendererOptions.delete(task.id);
|
|
1481
|
+
this.cache.rendererTaskOptions.delete(task.id);
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1484
|
+
var TestRendererSerializer = class {
|
|
1485
|
+
constructor(options) {
|
|
1486
|
+
this.options = options;
|
|
1487
|
+
}
|
|
1488
|
+
serialize(event, data, task) {
|
|
1489
|
+
return JSON.stringify(this.generate(event, data, task));
|
|
1490
|
+
}
|
|
1491
|
+
generate(event, data, task) {
|
|
1492
|
+
const output = {
|
|
1493
|
+
event,
|
|
1494
|
+
data
|
|
1495
|
+
};
|
|
1496
|
+
if (typeof this.options?.task !== "boolean") {
|
|
1497
|
+
const t = Object.fromEntries(this.options.task.map((entity) => {
|
|
1498
|
+
const property = task[entity];
|
|
1499
|
+
if (typeof property === "function") return [entity, property.call(task)];
|
|
1500
|
+
return [entity, property];
|
|
1501
|
+
}));
|
|
1502
|
+
if (Object.keys(task).length > 0) output.task = t;
|
|
1503
|
+
}
|
|
1504
|
+
return output;
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
var TestRenderer = class TestRenderer$1 {
|
|
1508
|
+
static nonTTY = true;
|
|
1509
|
+
static rendererOptions = {
|
|
1510
|
+
subtasks: true,
|
|
1511
|
+
state: Object.values(ListrTaskState),
|
|
1512
|
+
output: true,
|
|
1513
|
+
prompt: true,
|
|
1514
|
+
title: true,
|
|
1515
|
+
messages: [
|
|
1516
|
+
"skip",
|
|
1517
|
+
"error",
|
|
1518
|
+
"retry",
|
|
1519
|
+
"rollback",
|
|
1520
|
+
"paused"
|
|
1521
|
+
],
|
|
1522
|
+
messagesToStderr: [
|
|
1523
|
+
"error",
|
|
1524
|
+
"rollback",
|
|
1525
|
+
"retry"
|
|
1526
|
+
],
|
|
1527
|
+
task: [
|
|
1528
|
+
"hasRolledBack",
|
|
1529
|
+
"isRollingBack",
|
|
1530
|
+
"isCompleted",
|
|
1531
|
+
"isSkipped",
|
|
1532
|
+
"hasFinalized",
|
|
1533
|
+
"hasSubtasks",
|
|
1534
|
+
"title",
|
|
1535
|
+
"hasReset",
|
|
1536
|
+
"hasTitle",
|
|
1537
|
+
"isPrompt",
|
|
1538
|
+
"isPaused",
|
|
1539
|
+
"isPending",
|
|
1540
|
+
"isSkipped",
|
|
1541
|
+
"isStarted",
|
|
1542
|
+
"hasFailed",
|
|
1543
|
+
"isEnabled",
|
|
1544
|
+
"isRetrying",
|
|
1545
|
+
"path"
|
|
1546
|
+
]
|
|
1547
|
+
};
|
|
1548
|
+
static rendererTaskOptions;
|
|
1549
|
+
logger;
|
|
1550
|
+
serializer;
|
|
1551
|
+
constructor(tasks, options) {
|
|
1552
|
+
this.tasks = tasks;
|
|
1553
|
+
this.options = options;
|
|
1554
|
+
this.options = {
|
|
1555
|
+
...TestRenderer$1.rendererOptions,
|
|
1556
|
+
...this.options
|
|
1557
|
+
};
|
|
1558
|
+
this.logger = this.options.logger ?? new ListrLogger({ useIcons: false });
|
|
1559
|
+
this.serializer = new TestRendererSerializer(this.options);
|
|
1560
|
+
}
|
|
1561
|
+
render() {
|
|
1562
|
+
this.renderer(this.tasks);
|
|
1563
|
+
}
|
|
1564
|
+
end() {}
|
|
1565
|
+
renderer(tasks) {
|
|
1566
|
+
tasks.forEach((task) => {
|
|
1567
|
+
if (this.options.subtasks) task.on(ListrTaskEventType.SUBTASK, (subtasks) => {
|
|
1568
|
+
this.renderer(subtasks);
|
|
1569
|
+
});
|
|
1570
|
+
if (this.options.state) task.on(ListrTaskEventType.STATE, (state) => {
|
|
1571
|
+
this.logger.toStdout(this.serializer.serialize(ListrTaskEventType.STATE, state, task));
|
|
1572
|
+
});
|
|
1573
|
+
if (this.options.output) task.on(ListrTaskEventType.OUTPUT, (data) => {
|
|
1574
|
+
this.logger.toStdout(this.serializer.serialize(ListrTaskEventType.OUTPUT, data, task));
|
|
1575
|
+
});
|
|
1576
|
+
if (this.options.prompt) task.on(ListrTaskEventType.PROMPT, (prompt) => {
|
|
1577
|
+
this.logger.toStdout(this.serializer.serialize(ListrTaskEventType.PROMPT, prompt, task));
|
|
1578
|
+
});
|
|
1579
|
+
if (this.options.title) task.on(ListrTaskEventType.TITLE, (title) => {
|
|
1580
|
+
this.logger.toStdout(this.serializer.serialize(ListrTaskEventType.TITLE, title, task));
|
|
1581
|
+
});
|
|
1582
|
+
task.on(ListrTaskEventType.MESSAGE, (message) => {
|
|
1583
|
+
const parsed = Object.fromEntries(Object.entries(message).map(([key, value]) => {
|
|
1584
|
+
if (this.options.messages.includes(key)) return [key, value];
|
|
1585
|
+
}).filter(Boolean));
|
|
1586
|
+
if (Object.keys(parsed).length > 0) {
|
|
1587
|
+
const output = this.serializer.serialize(ListrTaskEventType.MESSAGE, parsed, task);
|
|
1588
|
+
if (this.options.messagesToStderr.some((state) => Object.keys(parsed).includes(state))) this.logger.toStderr(output);
|
|
1589
|
+
else this.logger.toStdout(output);
|
|
1590
|
+
}
|
|
1591
|
+
});
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
};
|
|
1595
|
+
var VerboseRenderer = class VerboseRenderer$1 {
|
|
1596
|
+
static nonTTY = true;
|
|
1597
|
+
static rendererOptions = {
|
|
1598
|
+
logTitleChange: false,
|
|
1599
|
+
pausedTimer: {
|
|
1600
|
+
...PRESET_TIMER,
|
|
1601
|
+
format: () => color.yellowBright
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1604
|
+
static rendererTaskOptions;
|
|
1605
|
+
logger;
|
|
1606
|
+
cache = {
|
|
1607
|
+
rendererOptions: /* @__PURE__ */ new Map(),
|
|
1608
|
+
rendererTaskOptions: /* @__PURE__ */ new Map()
|
|
1609
|
+
};
|
|
1610
|
+
constructor(tasks, options) {
|
|
1611
|
+
this.tasks = tasks;
|
|
1612
|
+
this.options = options;
|
|
1613
|
+
this.options = {
|
|
1614
|
+
...VerboseRenderer$1.rendererOptions,
|
|
1615
|
+
...this.options,
|
|
1616
|
+
icon: {
|
|
1617
|
+
...LISTR_LOGGER_STYLE.icon,
|
|
1618
|
+
...options?.icon ?? {}
|
|
1619
|
+
},
|
|
1620
|
+
color: {
|
|
1621
|
+
...LISTR_LOGGER_STYLE.color,
|
|
1622
|
+
...options?.color ?? {}
|
|
1623
|
+
}
|
|
1624
|
+
};
|
|
1625
|
+
this.logger = this.options.logger ?? new ListrLogger({
|
|
1626
|
+
useIcons: false,
|
|
1627
|
+
toStderr: LISTR_LOGGER_STDERR_LEVELS
|
|
1628
|
+
});
|
|
1629
|
+
this.logger.options.icon = this.options.icon;
|
|
1630
|
+
this.logger.options.color = this.options.color;
|
|
1631
|
+
if (this.options.timestamp) this.logger.options.fields.prefix.unshift(this.options.timestamp);
|
|
1632
|
+
}
|
|
1633
|
+
render() {
|
|
1634
|
+
this.renderer(this.tasks);
|
|
1635
|
+
}
|
|
1636
|
+
end() {}
|
|
1637
|
+
renderer(tasks) {
|
|
1638
|
+
tasks.forEach((task) => {
|
|
1639
|
+
this.calculate(task);
|
|
1640
|
+
task.once(ListrTaskEventType.CLOSED, () => {
|
|
1641
|
+
this.reset(task);
|
|
1642
|
+
});
|
|
1643
|
+
const rendererOptions = this.cache.rendererOptions.get(task.id);
|
|
1644
|
+
const rendererTaskOptions = this.cache.rendererTaskOptions.get(task.id);
|
|
1645
|
+
task.on(ListrTaskEventType.SUBTASK, (subtasks) => {
|
|
1646
|
+
this.renderer(subtasks);
|
|
1647
|
+
});
|
|
1648
|
+
task.on(ListrTaskEventType.STATE, (state) => {
|
|
1649
|
+
if (!task.hasTitle()) return;
|
|
1650
|
+
if (state === ListrTaskState.STARTED) this.logger.log(ListrLogLevels.STARTED, task.title);
|
|
1651
|
+
else if (state === ListrTaskState.COMPLETED) {
|
|
1652
|
+
const timer = rendererTaskOptions.timer;
|
|
1653
|
+
this.logger.log(ListrLogLevels.COMPLETED, task.title, timer && { suffix: {
|
|
1654
|
+
...timer,
|
|
1655
|
+
condition: !!task.message?.duration && timer.condition,
|
|
1656
|
+
args: [task.message.duration]
|
|
1657
|
+
} });
|
|
1658
|
+
}
|
|
1659
|
+
});
|
|
1660
|
+
task.on(ListrTaskEventType.OUTPUT, (data) => {
|
|
1661
|
+
this.logger.log(ListrLogLevels.OUTPUT, data);
|
|
1662
|
+
});
|
|
1663
|
+
task.on(ListrTaskEventType.PROMPT, (prompt) => {
|
|
1664
|
+
const cleansed = cleanseAnsi(prompt);
|
|
1665
|
+
if (cleansed) this.logger.log(ListrLogLevels.PROMPT, cleansed);
|
|
1666
|
+
});
|
|
1667
|
+
if (this.options?.logTitleChange !== false) task.on(ListrTaskEventType.TITLE, (title) => {
|
|
1668
|
+
this.logger.log(ListrLogLevels.TITLE, title);
|
|
1669
|
+
});
|
|
1670
|
+
task.on(ListrTaskEventType.MESSAGE, (message) => {
|
|
1671
|
+
if (message?.error) this.logger.log(ListrLogLevels.FAILED, message.error);
|
|
1672
|
+
else if (message?.skip) this.logger.log(ListrLogLevels.SKIPPED, message.skip);
|
|
1673
|
+
else if (message?.rollback) this.logger.log(ListrLogLevels.ROLLBACK, message.rollback);
|
|
1674
|
+
else if (message?.retry) this.logger.log(ListrLogLevels.RETRY, task.title, { suffix: message.retry.count.toString() });
|
|
1675
|
+
else if (message?.paused) {
|
|
1676
|
+
const timer = rendererOptions?.pausedTimer;
|
|
1677
|
+
this.logger.log(ListrLogLevels.PAUSED, task.title, timer && { suffix: {
|
|
1678
|
+
...timer,
|
|
1679
|
+
condition: !!message?.paused && timer.condition,
|
|
1680
|
+
args: [message.paused - Date.now()]
|
|
1681
|
+
} });
|
|
1682
|
+
}
|
|
1683
|
+
});
|
|
1684
|
+
});
|
|
1685
|
+
}
|
|
1686
|
+
calculate(task) {
|
|
1687
|
+
if (this.cache.rendererOptions.has(task.id) && this.cache.rendererTaskOptions.has(task.id)) return;
|
|
1688
|
+
const rendererOptions = {
|
|
1689
|
+
...this.options,
|
|
1690
|
+
...task.rendererOptions
|
|
1691
|
+
};
|
|
1692
|
+
this.cache.rendererOptions.set(task.id, rendererOptions);
|
|
1693
|
+
this.cache.rendererTaskOptions.set(task.id, {
|
|
1694
|
+
...VerboseRenderer$1.rendererTaskOptions,
|
|
1695
|
+
timer: rendererOptions.timer,
|
|
1696
|
+
...task.rendererTaskOptions
|
|
1697
|
+
});
|
|
1698
|
+
}
|
|
1699
|
+
reset(task) {
|
|
1700
|
+
this.cache.rendererOptions.delete(task.id);
|
|
1701
|
+
this.cache.rendererTaskOptions.delete(task.id);
|
|
1702
|
+
}
|
|
1703
|
+
};
|
|
1704
|
+
const RENDERERS = {
|
|
1705
|
+
default: DefaultRenderer,
|
|
1706
|
+
simple: SimpleRenderer,
|
|
1707
|
+
verbose: VerboseRenderer,
|
|
1708
|
+
test: TestRenderer,
|
|
1709
|
+
silent: SilentRenderer
|
|
1710
|
+
};
|
|
1711
|
+
function isRendererSupported(renderer) {
|
|
1712
|
+
return process.stdout.isTTY === true || renderer.nonTTY === true;
|
|
1713
|
+
}
|
|
1714
|
+
function getRendererClass(renderer) {
|
|
1715
|
+
if (typeof renderer === "string") return RENDERERS[renderer] ?? RENDERERS.default;
|
|
1716
|
+
return typeof renderer === "function" ? renderer : RENDERERS.default;
|
|
1717
|
+
}
|
|
1718
|
+
function getRenderer(options) {
|
|
1719
|
+
if (assertFunctionOrSelf(options?.silentRendererCondition)) return {
|
|
1720
|
+
renderer: getRendererClass("silent"),
|
|
1721
|
+
selection: ListrRendererSelection.SILENT
|
|
1722
|
+
};
|
|
1723
|
+
const r = {
|
|
1724
|
+
renderer: getRendererClass(options.renderer),
|
|
1725
|
+
options: options.rendererOptions,
|
|
1726
|
+
selection: ListrRendererSelection.PRIMARY
|
|
1727
|
+
};
|
|
1728
|
+
if (!isRendererSupported(r.renderer) || assertFunctionOrSelf(options?.fallbackRendererCondition)) return {
|
|
1729
|
+
renderer: getRendererClass(options.fallbackRenderer),
|
|
1730
|
+
options: options.fallbackRendererOptions,
|
|
1731
|
+
selection: ListrRendererSelection.SECONDARY
|
|
1732
|
+
};
|
|
1733
|
+
return r;
|
|
1734
|
+
}
|
|
1735
|
+
/**
|
|
1736
|
+
* This function asserts the given value as a function or itself.
|
|
1737
|
+
* If the value itself is a function it will evaluate it with the passed in arguments,
|
|
1738
|
+
* elsewise it will directly return itself.
|
|
1739
|
+
*/
|
|
1740
|
+
function assertFunctionOrSelf(functionOrSelf, ...args) {
|
|
1741
|
+
if (typeof functionOrSelf === "function") return functionOrSelf(...args);
|
|
1742
|
+
else return functionOrSelf;
|
|
1743
|
+
}
|
|
1744
|
+
const clone = (0, import_rfdc.default)({ circles: true });
|
|
1745
|
+
/**
|
|
1746
|
+
* Deep clones a object in the easiest manner.
|
|
1747
|
+
*/
|
|
1748
|
+
function cloneObject(obj) {
|
|
1749
|
+
return clone(obj);
|
|
1750
|
+
}
|
|
1751
|
+
var Concurrency = class {
|
|
1752
|
+
concurrency;
|
|
1753
|
+
count;
|
|
1754
|
+
queue;
|
|
1755
|
+
constructor(options) {
|
|
1756
|
+
this.concurrency = options.concurrency;
|
|
1757
|
+
this.count = 0;
|
|
1758
|
+
this.queue = /* @__PURE__ */ new Set();
|
|
1759
|
+
}
|
|
1760
|
+
add(fn) {
|
|
1761
|
+
if (this.count < this.concurrency) return this.run(fn);
|
|
1762
|
+
return new Promise((resolve) => {
|
|
1763
|
+
const callback = () => resolve(this.run(fn));
|
|
1764
|
+
this.queue.add(callback);
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
flush() {
|
|
1768
|
+
for (const callback of this.queue) {
|
|
1769
|
+
if (this.count >= this.concurrency) break;
|
|
1770
|
+
this.queue.delete(callback);
|
|
1771
|
+
callback();
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
run(fn) {
|
|
1775
|
+
this.count++;
|
|
1776
|
+
const promise = fn();
|
|
1777
|
+
const cleanup = () => {
|
|
1778
|
+
this.count--;
|
|
1779
|
+
this.flush();
|
|
1780
|
+
};
|
|
1781
|
+
promise.then(cleanup, () => {
|
|
1782
|
+
this.queue.clear();
|
|
1783
|
+
});
|
|
1784
|
+
return promise;
|
|
1785
|
+
}
|
|
1786
|
+
};
|
|
1787
|
+
function delay(time) {
|
|
1788
|
+
return new Promise((resolve) => {
|
|
1789
|
+
setTimeout(resolve, time);
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
/**
|
|
1793
|
+
* Internal error handling mechanism for Listr collects the errors and details for a failed task.
|
|
1794
|
+
*
|
|
1795
|
+
* @see {@link https://listr2.kilic.dev/task/error-handling.html}
|
|
1796
|
+
*/
|
|
1797
|
+
var ListrError = class extends Error {
|
|
1798
|
+
path;
|
|
1799
|
+
ctx;
|
|
1800
|
+
constructor(error, type, task) {
|
|
1801
|
+
super(error.message);
|
|
1802
|
+
this.error = error;
|
|
1803
|
+
this.type = type;
|
|
1804
|
+
this.task = task;
|
|
1805
|
+
this.name = "ListrError";
|
|
1806
|
+
this.path = task.path;
|
|
1807
|
+
if (task?.options.collectErrors === "full") {
|
|
1808
|
+
this.task = cloneObject(task);
|
|
1809
|
+
this.ctx = cloneObject(task.listr.ctx);
|
|
1810
|
+
}
|
|
1811
|
+
this.stack = error?.stack;
|
|
1812
|
+
}
|
|
1813
|
+
};
|
|
1814
|
+
/**
|
|
1815
|
+
* Internal error coming from renderer.
|
|
1816
|
+
*/
|
|
1817
|
+
var ListrRendererError = class extends Error {};
|
|
1818
|
+
/**
|
|
1819
|
+
* Internal error handling mechanism for Listr prompts to identify the failing cause is coming from a prompt.
|
|
1820
|
+
*
|
|
1821
|
+
* @see {@link https://listr2.kilic.dev/task/prompts.html}
|
|
1822
|
+
*/
|
|
1823
|
+
var PromptError = class extends Error {};
|
|
1824
|
+
/**
|
|
1825
|
+
* The original Task that is defined by the user is wrapped with the TaskWrapper to provide additional functionality.
|
|
1826
|
+
*
|
|
1827
|
+
* @see {@link https://listr2.kilic.dev/task/task.html}
|
|
1828
|
+
*/
|
|
1829
|
+
var TaskWrapper = class {
|
|
1830
|
+
constructor(task) {
|
|
1831
|
+
this.task = task;
|
|
1832
|
+
}
|
|
1833
|
+
/* istanbul ignore next */
|
|
1834
|
+
get title() {
|
|
1835
|
+
return this.task.title;
|
|
1836
|
+
}
|
|
1837
|
+
/**
|
|
1838
|
+
* Title of the current task.
|
|
1839
|
+
*
|
|
1840
|
+
* @see {@link https://listr2.kilic.dev/task/title.html}
|
|
1841
|
+
*/
|
|
1842
|
+
set title(title) {
|
|
1843
|
+
title = Array.isArray(title) ? title : [title];
|
|
1844
|
+
this.task.title$ = splat(title.shift(), ...title);
|
|
1845
|
+
}
|
|
1846
|
+
/* istanbul ignore next */
|
|
1847
|
+
get output() {
|
|
1848
|
+
return this.task.output;
|
|
1849
|
+
}
|
|
1850
|
+
/* istanbul ignore next */
|
|
1851
|
+
/**
|
|
1852
|
+
* Send output from the current task to the renderer.
|
|
1853
|
+
*
|
|
1854
|
+
* @see {@link https://listr2.kilic.dev/task/output.html}
|
|
1855
|
+
*/
|
|
1856
|
+
set output(output) {
|
|
1857
|
+
output = Array.isArray(output) ? output : [output];
|
|
1858
|
+
this.task.output$ = splat(output.shift(), ...output);
|
|
1859
|
+
}
|
|
1860
|
+
/* istanbul ignore next */
|
|
1861
|
+
/** Send an output to the output channel as prompt. */
|
|
1862
|
+
set promptOutput(output) {
|
|
1863
|
+
this.task.promptOutput$ = output;
|
|
1864
|
+
}
|
|
1865
|
+
/**
|
|
1866
|
+
* Creates a new set of Listr subtasks.
|
|
1867
|
+
*
|
|
1868
|
+
* @see {@link https://listr2.kilic.dev/task/subtasks.html}
|
|
1869
|
+
*/
|
|
1870
|
+
newListr(task, options) {
|
|
1871
|
+
let tasks;
|
|
1872
|
+
if (typeof task === "function") tasks = task(this);
|
|
1873
|
+
else tasks = task;
|
|
1874
|
+
return new Listr(tasks, options, this.task);
|
|
1875
|
+
}
|
|
1876
|
+
/**
|
|
1877
|
+
* Report an error that has to be collected and handled.
|
|
1878
|
+
*
|
|
1879
|
+
* @see {@link https://listr2.kilic.dev/task/error-handling.html}
|
|
1880
|
+
*/
|
|
1881
|
+
report(error, type) {
|
|
1882
|
+
if (this.task.options.collectErrors !== false) this.task.listr.errors.push(new ListrError(error, type, this.task));
|
|
1883
|
+
this.task.message$ = { error: error.message ?? this.task?.title };
|
|
1884
|
+
}
|
|
1885
|
+
/**
|
|
1886
|
+
* Skip the current task.
|
|
1887
|
+
*
|
|
1888
|
+
* @see {@link https://listr2.kilic.dev/task/skip.html}
|
|
1889
|
+
*/
|
|
1890
|
+
skip(message, ...metadata) {
|
|
1891
|
+
this.task.state$ = ListrTaskState.SKIPPED;
|
|
1892
|
+
if (message) this.task.message$ = { skip: message ? splat(message, ...metadata) : this.task?.title };
|
|
1893
|
+
}
|
|
1894
|
+
/**
|
|
1895
|
+
* Check whether this task is currently in a retry state.
|
|
1896
|
+
*
|
|
1897
|
+
* @see {@link https://listr2.kilic.dev/task/retry.html}
|
|
1898
|
+
*/
|
|
1899
|
+
isRetrying() {
|
|
1900
|
+
return this.task.isRetrying() ? this.task.retry : { count: 0 };
|
|
1901
|
+
}
|
|
1902
|
+
/* istanbul ignore next */
|
|
1903
|
+
/**
|
|
1904
|
+
* Create a new prompt for getting user input through the prompt adapter.
|
|
1905
|
+
* This will create a new prompt through the adapter if the task is not currently rendering a prompt or will return the active instance.
|
|
1906
|
+
*
|
|
1907
|
+
* This part of the application requires optional peer dependencies, please refer to documentation.
|
|
1908
|
+
*
|
|
1909
|
+
* @see {@link https://listr2.kilic.dev/task/prompt.html}
|
|
1910
|
+
*/
|
|
1911
|
+
prompt(adapter) {
|
|
1912
|
+
if (this.task.prompt) return this.task.prompt;
|
|
1913
|
+
return new adapter(this.task, this);
|
|
1914
|
+
}
|
|
1915
|
+
/* istanbul ignore next */
|
|
1916
|
+
/**
|
|
1917
|
+
* Generates a fake stdout for your use case, where it will be tunnelled through Listr to handle the rendering process.
|
|
1918
|
+
*
|
|
1919
|
+
* @see {@link https://listr2.kilic.dev/renderer/process-output.html}
|
|
1920
|
+
*/
|
|
1921
|
+
stdout(type) {
|
|
1922
|
+
return createWritable((chunk) => {
|
|
1923
|
+
switch (type) {
|
|
1924
|
+
case ListrTaskEventType.PROMPT:
|
|
1925
|
+
this.promptOutput = chunk;
|
|
1926
|
+
break;
|
|
1927
|
+
default: this.output = chunk;
|
|
1928
|
+
}
|
|
1929
|
+
});
|
|
1930
|
+
}
|
|
1931
|
+
/** Run this task. */
|
|
1932
|
+
run(ctx) {
|
|
1933
|
+
return this.task.run(ctx, this);
|
|
1934
|
+
}
|
|
1935
|
+
};
|
|
1936
|
+
var ListrTaskEventManager = class extends EventManager {};
|
|
1937
|
+
/**
|
|
1938
|
+
* Creates and handles a runnable instance of the Task.
|
|
1939
|
+
*/
|
|
1940
|
+
var Task = class extends ListrTaskEventManager {
|
|
1941
|
+
/** Unique id per task, can be used for identifying a Task. */
|
|
1942
|
+
id = randomUUID();
|
|
1943
|
+
/** The current state of the task. */
|
|
1944
|
+
state = ListrTaskState.WAITING;
|
|
1945
|
+
/** Subtasks of the current task. */
|
|
1946
|
+
subtasks;
|
|
1947
|
+
/** Title of the task. */
|
|
1948
|
+
title;
|
|
1949
|
+
/** Initial/Untouched version of the title for using whenever task has a reset. */
|
|
1950
|
+
initialTitle;
|
|
1951
|
+
/** Output channel for the task. */
|
|
1952
|
+
output;
|
|
1953
|
+
/** Current state of the retry process whenever the task is retrying. */
|
|
1954
|
+
retry;
|
|
1955
|
+
/**
|
|
1956
|
+
* A channel for messages.
|
|
1957
|
+
*
|
|
1958
|
+
* This requires a separate channel for messages like error, skip or runtime messages to further utilize in the renderers.
|
|
1959
|
+
*/
|
|
1960
|
+
message = {};
|
|
1961
|
+
/** Current prompt instance or prompt error whenever the task is prompting. */
|
|
1962
|
+
prompt;
|
|
1963
|
+
/** Parent task of the current task. */
|
|
1964
|
+
parent;
|
|
1965
|
+
/** Enable flag of this task. */
|
|
1966
|
+
enabled;
|
|
1967
|
+
/** User provided Task callback function to run. */
|
|
1968
|
+
taskFn;
|
|
1969
|
+
/** Marks the task as closed. This is different from finalized since this is not really related to task itself. */
|
|
1970
|
+
closed;
|
|
1971
|
+
constructor(listr, task, options, rendererOptions, rendererTaskOptions) {
|
|
1972
|
+
super();
|
|
1973
|
+
this.listr = listr;
|
|
1974
|
+
this.task = task;
|
|
1975
|
+
this.options = options;
|
|
1976
|
+
this.rendererOptions = rendererOptions;
|
|
1977
|
+
this.rendererTaskOptions = rendererTaskOptions;
|
|
1978
|
+
if (task.title) {
|
|
1979
|
+
const title = Array.isArray(task?.title) ? task.title : [task.title];
|
|
1980
|
+
this.title = splat(title.shift(), ...title);
|
|
1981
|
+
this.initialTitle = this.title;
|
|
1982
|
+
}
|
|
1983
|
+
this.taskFn = task.task;
|
|
1984
|
+
this.parent = listr.parentTask;
|
|
1985
|
+
}
|
|
1986
|
+
/**
|
|
1987
|
+
* Update the current state of the Task and emit the neccassary events.
|
|
1988
|
+
*/
|
|
1989
|
+
set state$(state) {
|
|
1990
|
+
this.state = state;
|
|
1991
|
+
this.emit(ListrTaskEventType.STATE, state);
|
|
1992
|
+
if (this.hasSubtasks() && this.hasFailed()) {
|
|
1993
|
+
for (const subtask of this.subtasks) if (subtask.state === ListrTaskState.STARTED) subtask.state$ = ListrTaskState.FAILED;
|
|
1994
|
+
}
|
|
1995
|
+
this.listr.events.emit(ListrEventType.SHOULD_REFRESH_RENDER);
|
|
1996
|
+
}
|
|
1997
|
+
/**
|
|
1998
|
+
* Update the current output of the Task and emit the neccassary events.
|
|
1999
|
+
*/
|
|
2000
|
+
set output$(data) {
|
|
2001
|
+
this.output = data;
|
|
2002
|
+
this.emit(ListrTaskEventType.OUTPUT, data);
|
|
2003
|
+
this.listr.events.emit(ListrEventType.SHOULD_REFRESH_RENDER);
|
|
2004
|
+
}
|
|
2005
|
+
/**
|
|
2006
|
+
* Update the current prompt output of the Task and emit the neccassary events.
|
|
2007
|
+
*/
|
|
2008
|
+
set promptOutput$(data) {
|
|
2009
|
+
this.emit(ListrTaskEventType.PROMPT, data);
|
|
2010
|
+
if (cleanseAnsi(data)) this.listr.events.emit(ListrEventType.SHOULD_REFRESH_RENDER);
|
|
2011
|
+
}
|
|
2012
|
+
/**
|
|
2013
|
+
* Update or extend the current message of the Task and emit the neccassary events.
|
|
2014
|
+
*/
|
|
2015
|
+
set message$(data) {
|
|
2016
|
+
this.message = {
|
|
2017
|
+
...this.message,
|
|
2018
|
+
...data
|
|
2019
|
+
};
|
|
2020
|
+
this.emit(ListrTaskEventType.MESSAGE, data);
|
|
2021
|
+
this.listr.events.emit(ListrEventType.SHOULD_REFRESH_RENDER);
|
|
2022
|
+
}
|
|
2023
|
+
/**
|
|
2024
|
+
* Update the current title of the Task and emit the neccassary events.
|
|
2025
|
+
*/
|
|
2026
|
+
set title$(title) {
|
|
2027
|
+
this.title = title;
|
|
2028
|
+
this.emit(ListrTaskEventType.TITLE, title);
|
|
2029
|
+
this.listr.events.emit(ListrEventType.SHOULD_REFRESH_RENDER);
|
|
2030
|
+
}
|
|
2031
|
+
/**
|
|
2032
|
+
* Current task path in the hierarchy.
|
|
2033
|
+
*/
|
|
2034
|
+
get path() {
|
|
2035
|
+
return [...this.listr.path, this.initialTitle];
|
|
2036
|
+
}
|
|
2037
|
+
/**
|
|
2038
|
+
* Checks whether the current task with the given context should be set as enabled.
|
|
2039
|
+
*/
|
|
2040
|
+
async check(ctx) {
|
|
2041
|
+
if (this.state === ListrTaskState.WAITING) {
|
|
2042
|
+
this.enabled = await assertFunctionOrSelf(this.task?.enabled ?? true, ctx);
|
|
2043
|
+
this.emit(ListrTaskEventType.ENABLED, this.enabled);
|
|
2044
|
+
this.listr.events.emit(ListrEventType.SHOULD_REFRESH_RENDER);
|
|
2045
|
+
}
|
|
2046
|
+
return this.enabled;
|
|
2047
|
+
}
|
|
2048
|
+
/** Returns whether this task has subtasks. */
|
|
2049
|
+
hasSubtasks() {
|
|
2050
|
+
return this.subtasks?.length > 0;
|
|
2051
|
+
}
|
|
2052
|
+
/** Returns whether this task is finalized in someform. */
|
|
2053
|
+
hasFinalized() {
|
|
2054
|
+
return this.isCompleted() || this.hasFailed() || this.isSkipped() || this.hasRolledBack();
|
|
2055
|
+
}
|
|
2056
|
+
/** Returns whether this task is in progress. */
|
|
2057
|
+
isPending() {
|
|
2058
|
+
return this.isStarted() || this.isPrompt() || this.hasReset();
|
|
2059
|
+
}
|
|
2060
|
+
/** Returns whether this task has started. */
|
|
2061
|
+
isStarted() {
|
|
2062
|
+
return this.state === ListrTaskState.STARTED;
|
|
2063
|
+
}
|
|
2064
|
+
/** Returns whether this task is skipped. */
|
|
2065
|
+
isSkipped() {
|
|
2066
|
+
return this.state === ListrTaskState.SKIPPED;
|
|
2067
|
+
}
|
|
2068
|
+
/** Returns whether this task has been completed. */
|
|
2069
|
+
isCompleted() {
|
|
2070
|
+
return this.state === ListrTaskState.COMPLETED;
|
|
2071
|
+
}
|
|
2072
|
+
/** Returns whether this task has been failed. */
|
|
2073
|
+
hasFailed() {
|
|
2074
|
+
return this.state === ListrTaskState.FAILED;
|
|
2075
|
+
}
|
|
2076
|
+
/** Returns whether this task has an active rollback task going on. */
|
|
2077
|
+
isRollingBack() {
|
|
2078
|
+
return this.state === ListrTaskState.ROLLING_BACK;
|
|
2079
|
+
}
|
|
2080
|
+
/** Returns whether the rollback action was successful. */
|
|
2081
|
+
hasRolledBack() {
|
|
2082
|
+
return this.state === ListrTaskState.ROLLED_BACK;
|
|
2083
|
+
}
|
|
2084
|
+
/** Returns whether this task has an actively retrying task going on. */
|
|
2085
|
+
isRetrying() {
|
|
2086
|
+
return this.state === ListrTaskState.RETRY;
|
|
2087
|
+
}
|
|
2088
|
+
/** Returns whether this task has some kind of reset like retry and rollback going on. */
|
|
2089
|
+
hasReset() {
|
|
2090
|
+
return this.state === ListrTaskState.RETRY || this.state === ListrTaskState.ROLLING_BACK;
|
|
2091
|
+
}
|
|
2092
|
+
/** Returns whether enabled function resolves to true. */
|
|
2093
|
+
isEnabled() {
|
|
2094
|
+
return this.enabled;
|
|
2095
|
+
}
|
|
2096
|
+
/** Returns whether this task actually has a title. */
|
|
2097
|
+
hasTitle() {
|
|
2098
|
+
return typeof this?.title === "string";
|
|
2099
|
+
}
|
|
2100
|
+
/** Returns whether this task has a prompt inside. */
|
|
2101
|
+
isPrompt() {
|
|
2102
|
+
return this.state === ListrTaskState.PROMPT || this.state === ListrTaskState.PROMPT_COMPLETED;
|
|
2103
|
+
}
|
|
2104
|
+
/** Returns whether this task is currently paused. */
|
|
2105
|
+
isPaused() {
|
|
2106
|
+
return this.state === ListrTaskState.PAUSED;
|
|
2107
|
+
}
|
|
2108
|
+
/** Returns whether this task is closed. */
|
|
2109
|
+
isClosed() {
|
|
2110
|
+
return this.closed;
|
|
2111
|
+
}
|
|
2112
|
+
/** Pause the given task for certain time. */
|
|
2113
|
+
async pause(time) {
|
|
2114
|
+
const state = this.state;
|
|
2115
|
+
this.state$ = ListrTaskState.PAUSED;
|
|
2116
|
+
this.message$ = { paused: Date.now() + time };
|
|
2117
|
+
await delay(time);
|
|
2118
|
+
this.state$ = state;
|
|
2119
|
+
this.message$ = { paused: null };
|
|
2120
|
+
}
|
|
2121
|
+
/** Run the current task. */
|
|
2122
|
+
async run(context, wrapper) {
|
|
2123
|
+
const handleResult = (result) => {
|
|
2124
|
+
if (result instanceof Listr) {
|
|
2125
|
+
result.options = {
|
|
2126
|
+
...this.options,
|
|
2127
|
+
...result.options
|
|
2128
|
+
};
|
|
2129
|
+
result.rendererClass = getRendererClass("silent");
|
|
2130
|
+
this.subtasks = result.tasks;
|
|
2131
|
+
result.errors = this.listr.errors;
|
|
2132
|
+
this.emit(ListrTaskEventType.SUBTASK, this.subtasks);
|
|
2133
|
+
result = result.run(context);
|
|
2134
|
+
} else if (result instanceof Promise) result = result.then(handleResult);
|
|
2135
|
+
else if (isReadable(result)) result = new Promise((resolve, reject) => {
|
|
2136
|
+
result.on("data", (data) => {
|
|
2137
|
+
this.output$ = data.toString();
|
|
2138
|
+
});
|
|
2139
|
+
result.on("error", (error) => reject(error));
|
|
2140
|
+
result.on("end", () => resolve(null));
|
|
2141
|
+
});
|
|
2142
|
+
else if (isObservable(result)) result = new Promise((resolve, reject) => {
|
|
2143
|
+
result.subscribe({
|
|
2144
|
+
next: (data) => {
|
|
2145
|
+
this.output$ = data;
|
|
2146
|
+
},
|
|
2147
|
+
error: reject,
|
|
2148
|
+
complete: resolve
|
|
2149
|
+
});
|
|
2150
|
+
});
|
|
2151
|
+
return result;
|
|
2152
|
+
};
|
|
2153
|
+
const startTime = Date.now();
|
|
2154
|
+
this.state$ = ListrTaskState.STARTED;
|
|
2155
|
+
const skipped = await assertFunctionOrSelf(this.task?.skip ?? false, context);
|
|
2156
|
+
if (skipped) {
|
|
2157
|
+
if (typeof skipped === "string") this.message$ = { skip: skipped };
|
|
2158
|
+
else if (this.hasTitle()) this.message$ = { skip: this.title };
|
|
2159
|
+
else this.message$ = { skip: "Skipped task without a title." };
|
|
2160
|
+
this.state$ = ListrTaskState.SKIPPED;
|
|
2161
|
+
return;
|
|
2162
|
+
}
|
|
2163
|
+
try {
|
|
2164
|
+
const retryCount = typeof this.task?.retry === "number" && this.task.retry > 0 ? this.task.retry + 1 : typeof this.task?.retry === "object" && this.task.retry.tries > 0 ? this.task.retry.tries + 1 : 1;
|
|
2165
|
+
const retryDelay = typeof this.task.retry === "object" && this.task.retry.delay;
|
|
2166
|
+
for (let retries = 1; retries <= retryCount; retries++) try {
|
|
2167
|
+
await handleResult(this.taskFn(context, wrapper));
|
|
2168
|
+
break;
|
|
2169
|
+
} catch (err) {
|
|
2170
|
+
if (retries !== retryCount) {
|
|
2171
|
+
this.retry = {
|
|
2172
|
+
count: retries,
|
|
2173
|
+
error: err
|
|
2174
|
+
};
|
|
2175
|
+
this.message$ = { retry: this.retry };
|
|
2176
|
+
this.title$ = this.initialTitle;
|
|
2177
|
+
this.output = void 0;
|
|
2178
|
+
wrapper.report(err, ListrErrorTypes.WILL_RETRY);
|
|
2179
|
+
this.state$ = ListrTaskState.RETRY;
|
|
2180
|
+
if (retryDelay) await this.pause(retryDelay);
|
|
2181
|
+
} else throw err;
|
|
2182
|
+
}
|
|
2183
|
+
if (this.isStarted() || this.isRetrying()) {
|
|
2184
|
+
this.message$ = { duration: Date.now() - startTime };
|
|
2185
|
+
this.state$ = ListrTaskState.COMPLETED;
|
|
2186
|
+
}
|
|
2187
|
+
} catch (error) {
|
|
2188
|
+
if (this.prompt instanceof PromptError) error = this.prompt;
|
|
2189
|
+
if (this.task?.rollback) {
|
|
2190
|
+
wrapper.report(error, ListrErrorTypes.WILL_ROLLBACK);
|
|
2191
|
+
try {
|
|
2192
|
+
this.state$ = ListrTaskState.ROLLING_BACK;
|
|
2193
|
+
await this.task.rollback(context, wrapper);
|
|
2194
|
+
this.message$ = { rollback: this.title };
|
|
2195
|
+
this.state$ = ListrTaskState.ROLLED_BACK;
|
|
2196
|
+
} catch (err) {
|
|
2197
|
+
this.state$ = ListrTaskState.FAILED;
|
|
2198
|
+
wrapper.report(err, ListrErrorTypes.HAS_FAILED_TO_ROLLBACK);
|
|
2199
|
+
this.close();
|
|
2200
|
+
throw err;
|
|
2201
|
+
}
|
|
2202
|
+
if (this.listr.options?.exitAfterRollback !== false) {
|
|
2203
|
+
this.close();
|
|
2204
|
+
throw error;
|
|
2205
|
+
}
|
|
2206
|
+
} else {
|
|
2207
|
+
this.state$ = ListrTaskState.FAILED;
|
|
2208
|
+
if (this.listr.options.exitOnError !== false && await assertFunctionOrSelf(this.task?.exitOnError, context) !== false) {
|
|
2209
|
+
wrapper.report(error, ListrErrorTypes.HAS_FAILED);
|
|
2210
|
+
this.close();
|
|
2211
|
+
throw error;
|
|
2212
|
+
} else if (!this.hasSubtasks()) wrapper.report(error, ListrErrorTypes.HAS_FAILED_WITHOUT_ERROR);
|
|
2213
|
+
}
|
|
2214
|
+
} finally {
|
|
2215
|
+
this.close();
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
close() {
|
|
2219
|
+
this.emit(ListrTaskEventType.CLOSED);
|
|
2220
|
+
this.listr.events.emit(ListrEventType.SHOULD_REFRESH_RENDER);
|
|
2221
|
+
this.complete();
|
|
2222
|
+
}
|
|
2223
|
+
};
|
|
2224
|
+
var ListrEventManager = class extends EventManager {};
|
|
2225
|
+
/**
|
|
2226
|
+
* Create a new task list with Listr.
|
|
2227
|
+
*
|
|
2228
|
+
* @see {@link https://listr2.kilic.dev/listr/listr.html}
|
|
2229
|
+
*/
|
|
2230
|
+
var Listr = class {
|
|
2231
|
+
tasks = [];
|
|
2232
|
+
errors = [];
|
|
2233
|
+
ctx;
|
|
2234
|
+
events;
|
|
2235
|
+
path = [];
|
|
2236
|
+
rendererClass;
|
|
2237
|
+
rendererClassOptions;
|
|
2238
|
+
rendererSelection;
|
|
2239
|
+
boundSignalHandler;
|
|
2240
|
+
concurrency;
|
|
2241
|
+
renderer;
|
|
2242
|
+
constructor(task, options, parentTask) {
|
|
2243
|
+
this.task = task;
|
|
2244
|
+
this.options = options;
|
|
2245
|
+
this.parentTask = parentTask;
|
|
2246
|
+
this.options = {
|
|
2247
|
+
concurrent: false,
|
|
2248
|
+
renderer: "default",
|
|
2249
|
+
fallbackRenderer: "simple",
|
|
2250
|
+
exitOnError: true,
|
|
2251
|
+
exitAfterRollback: true,
|
|
2252
|
+
collectErrors: false,
|
|
2253
|
+
registerSignalListeners: true,
|
|
2254
|
+
...this.parentTask?.options ?? {},
|
|
2255
|
+
...options
|
|
2256
|
+
};
|
|
2257
|
+
if (this.options.concurrent === true) this.options.concurrent = Infinity;
|
|
2258
|
+
else if (typeof this.options.concurrent !== "number") this.options.concurrent = 1;
|
|
2259
|
+
this.concurrency = new Concurrency({ concurrency: this.options.concurrent });
|
|
2260
|
+
if (parentTask) {
|
|
2261
|
+
this.path = [...parentTask.listr.path, parentTask.title];
|
|
2262
|
+
this.errors = parentTask.listr.errors;
|
|
2263
|
+
}
|
|
2264
|
+
if (this.parentTask?.listr.events instanceof ListrEventManager) this.events = this.parentTask.listr.events;
|
|
2265
|
+
else this.events = new ListrEventManager();
|
|
2266
|
+
/* istanbul ignore if */
|
|
2267
|
+
if (this.options?.forceTTY || process.env[ListrEnvironmentVariables.FORCE_TTY]) {
|
|
2268
|
+
process.stdout.isTTY = true;
|
|
2269
|
+
process.stderr.isTTY = true;
|
|
2270
|
+
}
|
|
2271
|
+
/* istanbul ignore if */
|
|
2272
|
+
if (this.options?.forceUnicode) process.env[ListrEnvironmentVariables.FORCE_UNICODE] = "1";
|
|
2273
|
+
const renderer = getRenderer({
|
|
2274
|
+
renderer: this.options.renderer,
|
|
2275
|
+
rendererOptions: this.options.rendererOptions,
|
|
2276
|
+
fallbackRenderer: this.options.fallbackRenderer,
|
|
2277
|
+
fallbackRendererOptions: this.options.fallbackRendererOptions,
|
|
2278
|
+
fallbackRendererCondition: this.options?.fallbackRendererCondition,
|
|
2279
|
+
silentRendererCondition: this.options?.silentRendererCondition
|
|
2280
|
+
});
|
|
2281
|
+
this.rendererClass = renderer.renderer;
|
|
2282
|
+
this.rendererClassOptions = renderer.options;
|
|
2283
|
+
this.rendererSelection = renderer.selection;
|
|
2284
|
+
/* istanbul ignore next */
|
|
2285
|
+
this.add(task ?? []);
|
|
2286
|
+
/* istanbul ignore if */
|
|
2287
|
+
if (this.options.registerSignalListeners) {
|
|
2288
|
+
this.boundSignalHandler = this.signalHandler.bind(this);
|
|
2289
|
+
process.once("SIGINT", this.boundSignalHandler).setMaxListeners(0);
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
/**
|
|
2293
|
+
* Whether this is the root task.
|
|
2294
|
+
*/
|
|
2295
|
+
isRoot() {
|
|
2296
|
+
return !this.parentTask;
|
|
2297
|
+
}
|
|
2298
|
+
/**
|
|
2299
|
+
* Whether this is a subtask of another task list.
|
|
2300
|
+
*/
|
|
2301
|
+
isSubtask() {
|
|
2302
|
+
return !!this.parentTask;
|
|
2303
|
+
}
|
|
2304
|
+
/**
|
|
2305
|
+
* Add tasks to current task list.
|
|
2306
|
+
*
|
|
2307
|
+
* @see {@link https://listr2.kilic.dev/task/task.html}
|
|
2308
|
+
*/
|
|
2309
|
+
add(tasks) {
|
|
2310
|
+
this.tasks.push(...this.generate(tasks));
|
|
2311
|
+
}
|
|
2312
|
+
/**
|
|
2313
|
+
* Run the task list.
|
|
2314
|
+
*
|
|
2315
|
+
* @see {@link https://listr2.kilic.dev/listr/listr.html#run-the-generated-task-list}
|
|
2316
|
+
*/
|
|
2317
|
+
async run(context) {
|
|
2318
|
+
if (!this.renderer) this.renderer = new this.rendererClass(this.tasks, this.rendererClassOptions, this.events);
|
|
2319
|
+
await this.renderer.render();
|
|
2320
|
+
this.ctx = this.options?.ctx ?? context ?? {};
|
|
2321
|
+
await Promise.all(this.tasks.map((task) => task.check(this.ctx)));
|
|
2322
|
+
try {
|
|
2323
|
+
await Promise.all(this.tasks.map((task) => this.concurrency.add(() => this.runTask(task))));
|
|
2324
|
+
this.renderer.end();
|
|
2325
|
+
this.removeSignalHandler();
|
|
2326
|
+
} catch (err) {
|
|
2327
|
+
if (this.options.exitOnError !== false) {
|
|
2328
|
+
this.renderer.end(err);
|
|
2329
|
+
this.removeSignalHandler();
|
|
2330
|
+
throw err;
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
return this.ctx;
|
|
2334
|
+
}
|
|
2335
|
+
generate(tasks) {
|
|
2336
|
+
tasks = Array.isArray(tasks) ? tasks : [tasks];
|
|
2337
|
+
return tasks.map((task) => {
|
|
2338
|
+
let rendererTaskOptions;
|
|
2339
|
+
if (this.rendererSelection === ListrRendererSelection.PRIMARY) rendererTaskOptions = task.rendererOptions;
|
|
2340
|
+
else if (this.rendererSelection === ListrRendererSelection.SECONDARY) rendererTaskOptions = task.fallbackRendererOptions;
|
|
2341
|
+
return new Task(this, task, this.options, this.rendererClassOptions, rendererTaskOptions);
|
|
2342
|
+
});
|
|
2343
|
+
}
|
|
2344
|
+
async runTask(task) {
|
|
2345
|
+
if (!await task.check(this.ctx)) return;
|
|
2346
|
+
return new TaskWrapper(task).run(this.ctx);
|
|
2347
|
+
}
|
|
2348
|
+
signalHandler() {
|
|
2349
|
+
this.tasks?.forEach(async (task) => {
|
|
2350
|
+
if (task.isPending()) task.state$ = ListrTaskState.FAILED;
|
|
2351
|
+
});
|
|
2352
|
+
if (this.isRoot()) {
|
|
2353
|
+
this.renderer?.end(/* @__PURE__ */ new Error("Interrupted."));
|
|
2354
|
+
process.exit(127);
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
removeSignalHandler() {
|
|
2358
|
+
if (this.boundSignalHandler) process.removeListener("SIGINT", this.boundSignalHandler);
|
|
2359
|
+
}
|
|
2360
|
+
};
|
|
2361
|
+
|
|
2362
|
+
//#endregion
|
|
2363
|
+
//#region src/manager.ts
|
|
2364
|
+
/**
|
|
2365
|
+
* Creates a new Listr2 task manager.
|
|
2366
|
+
*
|
|
2367
|
+
* Useful for creating a single instance of Listr2 with pre-set settings.
|
|
2368
|
+
*
|
|
2369
|
+
* @see {@link https://listr2.kilic.dev/listr/manager.html}
|
|
2370
|
+
*/
|
|
6
2371
|
var Manager = class {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
2372
|
+
errors = [];
|
|
2373
|
+
tasks = [];
|
|
2374
|
+
constructor(options) {
|
|
2375
|
+
this.options = options;
|
|
2376
|
+
}
|
|
2377
|
+
get ctx() {
|
|
2378
|
+
return this.options.ctx;
|
|
2379
|
+
}
|
|
2380
|
+
set ctx(ctx) {
|
|
2381
|
+
this.options.ctx = ctx;
|
|
2382
|
+
}
|
|
2383
|
+
add(tasks, options) {
|
|
2384
|
+
this.tasks = [...this.tasks, this.indent(tasks, options)];
|
|
2385
|
+
}
|
|
2386
|
+
async runAll(options) {
|
|
2387
|
+
options = {
|
|
2388
|
+
...this.options,
|
|
2389
|
+
...options
|
|
2390
|
+
};
|
|
2391
|
+
const tasks = [...this.tasks];
|
|
2392
|
+
this.tasks = [];
|
|
2393
|
+
const ctx = await this.run(tasks, options);
|
|
2394
|
+
return ctx;
|
|
2395
|
+
}
|
|
2396
|
+
newListr(tasks, options) {
|
|
2397
|
+
return new Listr(tasks, options);
|
|
2398
|
+
}
|
|
2399
|
+
indent(tasks, options, taskOptions) {
|
|
2400
|
+
options = {
|
|
2401
|
+
...this.options,
|
|
2402
|
+
...options
|
|
2403
|
+
};
|
|
2404
|
+
if (typeof tasks === "function") return {
|
|
2405
|
+
...taskOptions,
|
|
2406
|
+
task: (ctx) => this.newListr(tasks(ctx), options)
|
|
2407
|
+
};
|
|
2408
|
+
return {
|
|
2409
|
+
...taskOptions,
|
|
2410
|
+
task: () => this.newListr(tasks, options)
|
|
2411
|
+
};
|
|
2412
|
+
}
|
|
2413
|
+
async run(tasks, options) {
|
|
2414
|
+
options = {
|
|
2415
|
+
...this.options,
|
|
2416
|
+
...options
|
|
2417
|
+
};
|
|
2418
|
+
const task = this.newListr(tasks, options);
|
|
2419
|
+
const ctx = await task.run();
|
|
2420
|
+
this.errors.push(...task.errors);
|
|
2421
|
+
return ctx;
|
|
2422
|
+
}
|
|
57
2423
|
};
|
|
2424
|
+
|
|
2425
|
+
//#endregion
|
|
2426
|
+
export { Manager };
|