@canopycanopycanopy/b-ber-logger 3.0.8-nav.0 → 3.0.8-next.96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -55
- package/dist/index.d.ts +111 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +621 -132
- package/package.json +7 -18
- package/dist/Timer.js +0 -90
- package/dist/compose.js +0 -19
- package/dist/configure.js +0 -28
- package/dist/context.js +0 -32
- package/dist/debug.js +0 -10
- package/dist/error.js +0 -58
- package/dist/events.js +0 -12
- package/dist/format.js +0 -90
- package/dist/indenter.js +0 -29
- package/dist/info.js +0 -34
- package/dist/inspect.js +0 -14
- package/dist/listeners.js +0 -68
- package/dist/notice.js +0 -24
- package/dist/print-version.js +0 -16
- package/dist/printer.js +0 -23
- package/dist/register.js +0 -24
- package/dist/reset.js +0 -14
- package/dist/summary.js +0 -80
- package/dist/trace.js +0 -10
- package/dist/warn.js +0 -42
package/dist/index.js
CHANGED
|
@@ -1,132 +1,621 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
let util = require("util");
|
|
24
|
+
util = __toESM(util);
|
|
25
|
+
let events = require("events");
|
|
26
|
+
let chalk = require("chalk");
|
|
27
|
+
chalk = __toESM(chalk);
|
|
28
|
+
//#region src/compose.ts
|
|
29
|
+
function composeMessage(args) {
|
|
30
|
+
return util.default.format.call(util.default, ...args).split("\n").map((a) => a.trim()).join(`\n${" ".repeat(6)}`).replace(/\{(\d+)\}/g, (_, d) => this.decorate(String(this.floatFormat(d)), "blueBright")).replace(/\[([^\]]+)\]/g, (_, s) => this.decorate(s, "blueBright"));
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/configure.ts
|
|
34
|
+
function configure() {
|
|
35
|
+
let logLevel;
|
|
36
|
+
logLevel = this.settings["log-level"];
|
|
37
|
+
logLevel = this.settings.quiet ? 0 : logLevel;
|
|
38
|
+
logLevel = this.settings.verbose ? 4 : logLevel;
|
|
39
|
+
logLevel = this.settings.debug ? 5 : logLevel;
|
|
40
|
+
this.logLevel = logLevel;
|
|
41
|
+
this.boringOutput = this.settings["no-color"] || this.boringOutput;
|
|
42
|
+
this.summary = this.settings.summary || this.summary;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/Timer.ts
|
|
46
|
+
var Timer = class Timer extends events.EventEmitter {
|
|
47
|
+
static dateFormattingOptions = {
|
|
48
|
+
day: "numeric",
|
|
49
|
+
month: "short",
|
|
50
|
+
year: "numeric",
|
|
51
|
+
hour: "numeric",
|
|
52
|
+
minute: "numeric",
|
|
53
|
+
second: "numeric"
|
|
54
|
+
};
|
|
55
|
+
static timeFormat(t) {
|
|
56
|
+
const s = t[0] * 1e3 + t[1] / 1e6;
|
|
57
|
+
return `${String(s).slice(0, -3)}ms`;
|
|
58
|
+
}
|
|
59
|
+
static dateFormat() {
|
|
60
|
+
return new Date(Date.now()).toLocaleString();
|
|
61
|
+
}
|
|
62
|
+
taskBegin = null;
|
|
63
|
+
taskEnd = null;
|
|
64
|
+
sequenceBegin;
|
|
65
|
+
formattedStartDate;
|
|
66
|
+
taskTimes;
|
|
67
|
+
constructor() {
|
|
68
|
+
super();
|
|
69
|
+
this.prepare();
|
|
70
|
+
}
|
|
71
|
+
prepare() {
|
|
72
|
+
this.sequenceBegin = process.hrtime();
|
|
73
|
+
this.formattedStartDate = (/* @__PURE__ */ new Date()).toLocaleDateString("en-CA", Timer.dateFormattingOptions);
|
|
74
|
+
this.taskTimes = [];
|
|
75
|
+
}
|
|
76
|
+
start(task) {
|
|
77
|
+
this.taskBegin = process.hrtime(this.sequenceBegin);
|
|
78
|
+
this.emit("begin", {
|
|
79
|
+
task,
|
|
80
|
+
begin: this.taskBegin
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
stop(task) {
|
|
84
|
+
this.taskEnd = process.hrtime(this.sequenceBegin);
|
|
85
|
+
const beginMs = Timer.timeFormat(this.taskBegin);
|
|
86
|
+
const endMs = Timer.timeFormat(this.taskEnd);
|
|
87
|
+
const totalMs = `${(parseFloat(endMs) - parseFloat(beginMs)).toFixed(3)}ms`;
|
|
88
|
+
const taskTime = {
|
|
89
|
+
taskName: task,
|
|
90
|
+
beginHrtime: this.taskBegin,
|
|
91
|
+
endHrtime: this.taskEnd,
|
|
92
|
+
beginMs,
|
|
93
|
+
endMs,
|
|
94
|
+
totalMs
|
|
95
|
+
};
|
|
96
|
+
this.taskTimes.push(taskTime);
|
|
97
|
+
this.emit("end", {
|
|
98
|
+
task,
|
|
99
|
+
taskTime
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
done({ state }) {
|
|
103
|
+
const { taskTimes, formattedStartDate } = this;
|
|
104
|
+
const formattedEndDate = (/* @__PURE__ */ new Date()).toLocaleDateString("en-CA", Timer.dateFormattingOptions);
|
|
105
|
+
const sequenceEnd = Timer.timeFormat(process.hrtime(this.sequenceBegin));
|
|
106
|
+
this.emit("done", {
|
|
107
|
+
state,
|
|
108
|
+
taskTimes,
|
|
109
|
+
formattedStartDate,
|
|
110
|
+
formattedEndDate,
|
|
111
|
+
sequenceEnd
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/context.ts
|
|
117
|
+
function ctx(fileName) {
|
|
118
|
+
return fileName;
|
|
119
|
+
}
|
|
120
|
+
function counter() {
|
|
121
|
+
this.incrementCounter();
|
|
122
|
+
return this.decorate(`[${Timer.dateFormat()}]`);
|
|
123
|
+
}
|
|
124
|
+
function getContext() {
|
|
125
|
+
const { stack } = /* @__PURE__ */ new Error();
|
|
126
|
+
const context = stack.split("\n")[3].replace(/^\s+at[^/]+(\/[^:]+):.+$/, (_, m) => ctx(m));
|
|
127
|
+
if (context !== this.context) this.context = context;
|
|
128
|
+
else return "";
|
|
129
|
+
return context;
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/debug.ts
|
|
133
|
+
function debug() {}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/error.ts
|
|
136
|
+
function error(_args) {
|
|
137
|
+
const args = Array.isArray(_args) ? _args : [_args];
|
|
138
|
+
if (this.logLevel < 1) return;
|
|
139
|
+
const errCode = 1;
|
|
140
|
+
let message;
|
|
141
|
+
let stack;
|
|
142
|
+
let err;
|
|
143
|
+
let formatted;
|
|
144
|
+
while (err = args.shift()) {
|
|
145
|
+
if (err instanceof Error) {
|
|
146
|
+
message = this.composeMessage([err.message]);
|
|
147
|
+
stack = err.stack;
|
|
148
|
+
} else {
|
|
149
|
+
message = this.composeMessage([err]);
|
|
150
|
+
stack = (/* @__PURE__ */ new Error()).stack;
|
|
151
|
+
}
|
|
152
|
+
let prefix = "";
|
|
153
|
+
prefix += this.decorate("b-ber", "whiteBright", "bgBlack");
|
|
154
|
+
prefix += " ";
|
|
155
|
+
prefix += this.decorate("ERR!", "whiteBright", "bgRed");
|
|
156
|
+
formatted = util.default.format.apply(util.default, [
|
|
157
|
+
"%s %s",
|
|
158
|
+
prefix,
|
|
159
|
+
message
|
|
160
|
+
]);
|
|
161
|
+
this.taskErrors += 1;
|
|
162
|
+
this.errors.push({
|
|
163
|
+
stack,
|
|
164
|
+
message,
|
|
165
|
+
formatted
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
this.errors.forEach((processedErr) => {
|
|
169
|
+
process.stdout.write(processedErr.formatted);
|
|
170
|
+
this.newLine();
|
|
171
|
+
if (this.logLevel > 3) {
|
|
172
|
+
process.stdout.write(util.default.format.call(util.default, processedErr.stack));
|
|
173
|
+
this.newLine();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
process.stdout.write(this.decorate(`b-ber exited with code ${errCode}`, "whiteBright", "bgRed"));
|
|
177
|
+
this.newLine();
|
|
178
|
+
process.exit(errCode);
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/events.ts
|
|
182
|
+
function notify(event, data) {
|
|
183
|
+
this[event].call(this, data);
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/format.ts
|
|
187
|
+
function wrap(arr, space) {
|
|
188
|
+
return arr.reduce((acc, curr) => {
|
|
189
|
+
const a = acc.split("\n");
|
|
190
|
+
const l = a[a.length - 1].length;
|
|
191
|
+
return acc.concat(l > this.consoleWidth ? `\n${space}${curr}, ` : `${curr}, `);
|
|
192
|
+
}, "").slice(0, -2);
|
|
193
|
+
}
|
|
194
|
+
function floatFormat(_n) {
|
|
195
|
+
const n = Number(_n);
|
|
196
|
+
const pows = {
|
|
197
|
+
1: {
|
|
198
|
+
text: "B",
|
|
199
|
+
pow: 0
|
|
200
|
+
},
|
|
201
|
+
2: {
|
|
202
|
+
text: "B",
|
|
203
|
+
pow: 0
|
|
204
|
+
},
|
|
205
|
+
3: {
|
|
206
|
+
text: "B",
|
|
207
|
+
pow: 0
|
|
208
|
+
},
|
|
209
|
+
4: {
|
|
210
|
+
text: "Kb",
|
|
211
|
+
pow: 3
|
|
212
|
+
},
|
|
213
|
+
5: {
|
|
214
|
+
text: "Kb",
|
|
215
|
+
pow: 3
|
|
216
|
+
},
|
|
217
|
+
6: {
|
|
218
|
+
text: "Kb",
|
|
219
|
+
pow: 3
|
|
220
|
+
},
|
|
221
|
+
7: {
|
|
222
|
+
text: "Mb",
|
|
223
|
+
pow: 6
|
|
224
|
+
},
|
|
225
|
+
8: {
|
|
226
|
+
text: "Mb",
|
|
227
|
+
pow: 6
|
|
228
|
+
},
|
|
229
|
+
9: {
|
|
230
|
+
text: "Mb",
|
|
231
|
+
pow: 6
|
|
232
|
+
},
|
|
233
|
+
10: {
|
|
234
|
+
text: "Gb",
|
|
235
|
+
pow: 9
|
|
236
|
+
},
|
|
237
|
+
11: {
|
|
238
|
+
text: "Gb",
|
|
239
|
+
pow: 9
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
const len = String(n).length;
|
|
243
|
+
return `${(n / Number(`1e${pows[len].pow}`)).toFixed(2)} ${pows[len].text}`;
|
|
244
|
+
}
|
|
245
|
+
function decorate(_args, ...props) {
|
|
246
|
+
const args = _args && Array.isArray(_args) ? _args : [_args];
|
|
247
|
+
let message = util.default.format.call(util.default, ...args);
|
|
248
|
+
if (this.boringOutput === false) for (let i = props.length - 1; i >= 0; i--) {
|
|
249
|
+
const chalkFn = chalk.default[props[i]];
|
|
250
|
+
if (chalkFn) message = chalkFn(message);
|
|
251
|
+
else message = chalk.default`${message}`;
|
|
252
|
+
}
|
|
253
|
+
return message;
|
|
254
|
+
}
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/indenter.ts
|
|
257
|
+
function indent() {
|
|
258
|
+
return this.whitespace.repeat(this.indentLevel);
|
|
259
|
+
}
|
|
260
|
+
function incrementIndent() {
|
|
261
|
+
this.indentLevel += this.increment;
|
|
262
|
+
}
|
|
263
|
+
function decrementIndent() {
|
|
264
|
+
this.indentLevel -= this.increment;
|
|
265
|
+
}
|
|
266
|
+
function incrementCounter() {
|
|
267
|
+
this.taskCounter += 1;
|
|
268
|
+
}
|
|
269
|
+
function decrementCounter() {
|
|
270
|
+
this.taskCounter -= 1;
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/info.ts
|
|
274
|
+
function info(...args) {
|
|
275
|
+
if (this.logLevel < 4) return;
|
|
276
|
+
const message = this.decorate(this.composeMessage(args));
|
|
277
|
+
let prefix = "";
|
|
278
|
+
if (this.logLevel > 2) {
|
|
279
|
+
prefix += this.decorate(`[${(/* @__PURE__ */ new Date()).toISOString()}]`, "gray");
|
|
280
|
+
prefix += " ";
|
|
281
|
+
}
|
|
282
|
+
prefix += this.decorate("b-ber", "whiteBright", "bgBlack");
|
|
283
|
+
prefix += " ";
|
|
284
|
+
prefix += this.decorate("info", "green");
|
|
285
|
+
prefix += " ";
|
|
286
|
+
process.stdout.write(`${prefix}${message}`);
|
|
287
|
+
this.newLine();
|
|
288
|
+
if (this.logLevel > 4) {
|
|
289
|
+
const { stack } = /* @__PURE__ */ new Error();
|
|
290
|
+
process.stdout.write(util.default.format.call(util.default, stack.replace(/^Error\s+/, "Info ")));
|
|
291
|
+
this.newLine();
|
|
292
|
+
this.newLine();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/inspect.ts
|
|
297
|
+
function inspect(_args) {
|
|
298
|
+
console.log(util.default.inspect(_args, true, null, true));
|
|
299
|
+
}
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/listeners.ts
|
|
302
|
+
function bind() {
|
|
303
|
+
this.on("begin", ({ task }) => {
|
|
304
|
+
this.task = task;
|
|
305
|
+
this.taskWarnings = 0;
|
|
306
|
+
this.taskErrors = 0;
|
|
307
|
+
if (this.logLevel < 3) {
|
|
308
|
+
this.incrementIndent();
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
this.incrementIndent();
|
|
312
|
+
});
|
|
313
|
+
this.on("end", ({ task, taskTime }) => {
|
|
314
|
+
this.decrementIndent();
|
|
315
|
+
if (this.logLevel < 3) return;
|
|
316
|
+
const { totalMs } = taskTime;
|
|
317
|
+
process.stdout.clearLine(0);
|
|
318
|
+
process.stdout.cursorTo(0);
|
|
319
|
+
const message = util.default.format.call(util.default, "%s%s %s %s %s done (%s)", this.indent(), this.decorate(`[${(/* @__PURE__ */ new Date()).toISOString()}]`, "gray"), this.decorate("b-ber", "whiteBright", "bgBlack"), this.decorate("info", "green"), this.decorate(task), totalMs);
|
|
320
|
+
process.stdout.write(message);
|
|
321
|
+
this.newLine();
|
|
322
|
+
if (this.logLevel > 4) {
|
|
323
|
+
const { stack } = /* @__PURE__ */ new Error();
|
|
324
|
+
process.stdout.write(util.default.format.call(util.default, stack.replace(/^Error\s+/, "Info ")));
|
|
325
|
+
this.newLine();
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
this.on("done", (data) => {
|
|
329
|
+
if (this.logLevel < 1) return;
|
|
330
|
+
const message = util.default.format.call(util.default, "%s%s %s %s", this.indent(), this.decorate("b-ber", "whiteBright", "bgBlack"), this.decorate("info", "green"), this.decorate("Build succeeded", "green"));
|
|
331
|
+
process.stdout.write(message);
|
|
332
|
+
this.newLine();
|
|
333
|
+
if (this.summary) this.printSummary(data);
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region src/notice.ts
|
|
338
|
+
function notice(...args) {
|
|
339
|
+
const message = this.decorate(this.composeMessage(args));
|
|
340
|
+
let prefix = "";
|
|
341
|
+
if (this.logLevel > 2) {
|
|
342
|
+
prefix += this.decorate(`[${(/* @__PURE__ */ new Date()).toISOString()}]`, "gray");
|
|
343
|
+
prefix += " ";
|
|
344
|
+
}
|
|
345
|
+
prefix += this.decorate("b-ber", "whiteBright", "bgBlack");
|
|
346
|
+
prefix += " ";
|
|
347
|
+
prefix += this.decorate("info", "green");
|
|
348
|
+
prefix += " ";
|
|
349
|
+
process.stdout.write(`${prefix}${message}`);
|
|
350
|
+
this.newLine();
|
|
351
|
+
}
|
|
352
|
+
//#endregion
|
|
353
|
+
//#region src/print-version.ts
|
|
354
|
+
function printVersion(version) {
|
|
355
|
+
const message = util.default.format.call(util.default, "%s%s %s %s", this.indent(), this.decorate("b-ber", "whiteBright", "bgBlack"), this.decorate("version"), this.decorate(version, "blueBright"));
|
|
356
|
+
process.stdout.write(message);
|
|
357
|
+
this.newLine();
|
|
358
|
+
}
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/printer.ts
|
|
361
|
+
function printNotices(type, task = "b-ber") {
|
|
362
|
+
const notices = this[type];
|
|
363
|
+
const leader = type === "warnings" ? "WARN" : "ERR!";
|
|
364
|
+
const color = type === "warnings" ? "bgYellowBright" : "bgRed";
|
|
365
|
+
const message = util.default.format.call(util.default, "%s%s %s task %s - %s %s", this.indent(), this.decorate("b-ber", "whiteBright", "bgBlack"), this.decorate(leader, color), this.decorate(task), this.decorate(notices.length), this.decorate(type));
|
|
366
|
+
if (this.logLevel > 2) process.stdout.write(message);
|
|
367
|
+
}
|
|
368
|
+
function printWarnings(task) {
|
|
369
|
+
printNotices.call(this, "warnings", task);
|
|
370
|
+
}
|
|
371
|
+
function printErrors(task) {
|
|
372
|
+
printNotices.call(this, "errors", task);
|
|
373
|
+
}
|
|
374
|
+
//#endregion
|
|
375
|
+
//#region src/register.ts
|
|
376
|
+
function registerSequence(_state, _command, sequence) {
|
|
377
|
+
if (this.logLevel < 1) return;
|
|
378
|
+
const message = this.decorate(this.composeMessage([
|
|
379
|
+
"Preparing to run",
|
|
380
|
+
sequence.length,
|
|
381
|
+
`task${sequence.length > 1 ? "s" : ""}`
|
|
382
|
+
]));
|
|
383
|
+
let prefix = "";
|
|
384
|
+
if (this.logLevel > 2) {
|
|
385
|
+
prefix += this.decorate(`[${(/* @__PURE__ */ new Date()).toISOString()}]`, "gray");
|
|
386
|
+
prefix += " ";
|
|
387
|
+
}
|
|
388
|
+
prefix += this.decorate("b-ber", "whiteBright", "bgBlack");
|
|
389
|
+
prefix += " ";
|
|
390
|
+
prefix += this.decorate("info", "green");
|
|
391
|
+
prefix += " ";
|
|
392
|
+
process.stdout.write(`${prefix}${message}`);
|
|
393
|
+
this.newLine();
|
|
394
|
+
}
|
|
395
|
+
//#endregion
|
|
396
|
+
//#region src/reset.ts
|
|
397
|
+
function reset() {
|
|
398
|
+
this.errors = [];
|
|
399
|
+
this.warnings = [];
|
|
400
|
+
}
|
|
401
|
+
//#endregion
|
|
402
|
+
//#region src/summary.ts
|
|
403
|
+
const INDENTATION = " ";
|
|
404
|
+
function isPlainObject(v) {
|
|
405
|
+
return typeof v === "object" && v !== null && Object.getPrototypeOf(v) === Object.prototype;
|
|
406
|
+
}
|
|
407
|
+
function write(msgs, context) {
|
|
408
|
+
const len = msgs.length - 1;
|
|
409
|
+
const esses = " %s".repeat(len);
|
|
410
|
+
const msgs_ = msgs.map(([text, color]) => color ? context.decorate(text, color) : context.decorate(text));
|
|
411
|
+
const message = util.default.format.call(util.default, `%s%s %s${esses}`, context.indent(), context.decorate("b-ber", "whiteBright", "bgBlack"), ...msgs_);
|
|
412
|
+
process.stdout.write(message);
|
|
413
|
+
context.newLine();
|
|
414
|
+
}
|
|
415
|
+
function printNavigation(data, context, indent = 0) {
|
|
416
|
+
const indent_ = INDENTATION.repeat(indent);
|
|
417
|
+
function render(_data, _context) {
|
|
418
|
+
_data.forEach((item) => {
|
|
419
|
+
write.call(_context, [[`${indent_}${item.title || "[no title]"}: ${item.name}`]], _context);
|
|
420
|
+
if (item.nodes && item.nodes.length) render(item.nodes, _context);
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
render(data, context);
|
|
424
|
+
}
|
|
425
|
+
function writeMetadata(data, context) {
|
|
426
|
+
Object.entries(data).forEach(([, v]) => {
|
|
427
|
+
if (isPlainObject(v)) write.call(context, [[`${v.term}: ${v.value}`]], context);
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
function writeConfig(data, context, indent = 0) {
|
|
431
|
+
const indent_ = INDENTATION.repeat(indent);
|
|
432
|
+
Object.entries(data).forEach(([k, v]) => {
|
|
433
|
+
if (typeof v === "string") write.call(context, [[`${indent_}${k}: ${v}`]], context);
|
|
434
|
+
if (isPlainObject(v)) {
|
|
435
|
+
write.call(context, [[`${indent_}${k}`]], context);
|
|
436
|
+
writeConfig(v, context, indent + 1);
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
function printSummary({ state, formattedStartDate, formattedEndDate, sequenceEnd }) {
|
|
441
|
+
this.newLine();
|
|
442
|
+
write.call(this, [["Stats", "blueBright"]], this);
|
|
443
|
+
write.call(this, [["Build Start:"], [formattedStartDate]], this);
|
|
444
|
+
write.call(this, [["Build End:"], [formattedEndDate]], this);
|
|
445
|
+
write.call(this, [["Elapsed:"], [sequenceEnd]], this);
|
|
446
|
+
this.newLine();
|
|
447
|
+
write.call(this, [["Configuration", "blueBright"]], this);
|
|
448
|
+
writeConfig(state.config, this);
|
|
449
|
+
this.newLine();
|
|
450
|
+
write.call(this, [["Metadata", "blueBright"]], this);
|
|
451
|
+
writeMetadata(state.metadata.json(), this);
|
|
452
|
+
this.newLine();
|
|
453
|
+
write.call(this, [["Navigation", "blueBright"]], this);
|
|
454
|
+
printNavigation(state.toc, this);
|
|
455
|
+
}
|
|
456
|
+
//#endregion
|
|
457
|
+
//#region src/trace.ts
|
|
458
|
+
function trace() {}
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/warn.ts
|
|
461
|
+
function warn(...args) {
|
|
462
|
+
if (this.logLevel < 2) return;
|
|
463
|
+
let message;
|
|
464
|
+
message = this.composeMessage(args);
|
|
465
|
+
message = args[0] instanceof Error ? this.composeMessage([args[0].message]) : this.composeMessage(args);
|
|
466
|
+
const { stack } = /* @__PURE__ */ new Error();
|
|
467
|
+
let prefix = "";
|
|
468
|
+
if (this.logLevel > 2) {
|
|
469
|
+
prefix += this.decorate(`[${(/* @__PURE__ */ new Date()).toISOString()}]`, "gray");
|
|
470
|
+
prefix += " ";
|
|
471
|
+
}
|
|
472
|
+
prefix += this.decorate("b-ber", "whiteBright", "bgBlack");
|
|
473
|
+
prefix += " ";
|
|
474
|
+
prefix += this.decorate("WARN", "black", "bgYellowBright");
|
|
475
|
+
const formatted = util.default.format.apply(util.default, [
|
|
476
|
+
"%s %s",
|
|
477
|
+
prefix,
|
|
478
|
+
message
|
|
479
|
+
]);
|
|
480
|
+
this.taskWarnings += 1;
|
|
481
|
+
this.warnings.push({
|
|
482
|
+
stack,
|
|
483
|
+
message,
|
|
484
|
+
formatted
|
|
485
|
+
});
|
|
486
|
+
process.stdout.write(formatted);
|
|
487
|
+
this.newLine();
|
|
488
|
+
if (this.logLevel > 3) {
|
|
489
|
+
process.stdout.write(util.default.format.call(util.default, stack.replace(/^Error\s+/, "Warning ")));
|
|
490
|
+
this.newLine();
|
|
491
|
+
if (this.logLevel > 4) this.newLine();
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
const log = new class Logger extends Timer {
|
|
495
|
+
static defaults = {
|
|
496
|
+
logLevel: 2,
|
|
497
|
+
boringOutput: false,
|
|
498
|
+
summary: false,
|
|
499
|
+
command: null,
|
|
500
|
+
consoleWidth: 70,
|
|
501
|
+
errors: [],
|
|
502
|
+
warnings: [],
|
|
503
|
+
taskWarnings: 0,
|
|
504
|
+
taskErrors: 0,
|
|
505
|
+
whitespace: " ",
|
|
506
|
+
increment: 0,
|
|
507
|
+
indentLevel: 0,
|
|
508
|
+
taskCounter: -1,
|
|
509
|
+
context: null
|
|
510
|
+
};
|
|
511
|
+
logLevel;
|
|
512
|
+
boringOutput;
|
|
513
|
+
command;
|
|
514
|
+
consoleWidth;
|
|
515
|
+
errors;
|
|
516
|
+
warnings;
|
|
517
|
+
taskWarnings;
|
|
518
|
+
taskErrors;
|
|
519
|
+
whitespace;
|
|
520
|
+
increment;
|
|
521
|
+
indentLevel;
|
|
522
|
+
taskCounter;
|
|
523
|
+
context;
|
|
524
|
+
summary;
|
|
525
|
+
task;
|
|
526
|
+
settings;
|
|
527
|
+
printWarnings;
|
|
528
|
+
printErrors;
|
|
529
|
+
indent;
|
|
530
|
+
incrementIndent;
|
|
531
|
+
decrementIndent;
|
|
532
|
+
incrementCounter;
|
|
533
|
+
decrementCounter;
|
|
534
|
+
bind;
|
|
535
|
+
notify;
|
|
536
|
+
warn;
|
|
537
|
+
info;
|
|
538
|
+
error;
|
|
539
|
+
debug;
|
|
540
|
+
trace;
|
|
541
|
+
notice;
|
|
542
|
+
inspect;
|
|
543
|
+
printSummary;
|
|
544
|
+
configure;
|
|
545
|
+
printVersion;
|
|
546
|
+
registerSequence;
|
|
547
|
+
wrap;
|
|
548
|
+
decorate;
|
|
549
|
+
floatFormat;
|
|
550
|
+
counter;
|
|
551
|
+
getContext;
|
|
552
|
+
composeMessage;
|
|
553
|
+
reset;
|
|
554
|
+
constructor() {
|
|
555
|
+
super();
|
|
556
|
+
this.logLevel = Logger.defaults.logLevel;
|
|
557
|
+
this.boringOutput = Logger.defaults.boringOutput;
|
|
558
|
+
this.command = Logger.defaults.command;
|
|
559
|
+
this.consoleWidth = Logger.defaults.consoleWidth;
|
|
560
|
+
this.errors = [];
|
|
561
|
+
this.warnings = [];
|
|
562
|
+
this.taskWarnings = Logger.defaults.taskWarnings;
|
|
563
|
+
this.taskErrors = Logger.defaults.taskErrors;
|
|
564
|
+
this.whitespace = Logger.defaults.whitespace;
|
|
565
|
+
this.increment = Logger.defaults.increment;
|
|
566
|
+
this.indentLevel = Logger.defaults.indentLevel;
|
|
567
|
+
this.taskCounter = Logger.defaults.taskCounter;
|
|
568
|
+
this.context = Logger.defaults.context;
|
|
569
|
+
this.settings = {
|
|
570
|
+
quiet: false,
|
|
571
|
+
verbose: false,
|
|
572
|
+
debug: false,
|
|
573
|
+
summary: Logger.defaults.summary,
|
|
574
|
+
"no-color": Logger.defaults.boringOutput,
|
|
575
|
+
"log-level": Logger.defaults.logLevel
|
|
576
|
+
};
|
|
577
|
+
this.printWarnings = printWarnings.bind(this);
|
|
578
|
+
this.printErrors = printErrors.bind(this);
|
|
579
|
+
this.indent = indent.bind(this);
|
|
580
|
+
this.incrementIndent = incrementIndent.bind(this);
|
|
581
|
+
this.decrementIndent = decrementIndent.bind(this);
|
|
582
|
+
this.incrementCounter = incrementCounter.bind(this);
|
|
583
|
+
this.decrementCounter = decrementCounter.bind(this);
|
|
584
|
+
this.bind = bind.bind(this);
|
|
585
|
+
this.notify = notify.bind(this);
|
|
586
|
+
this.warn = warn.bind(this);
|
|
587
|
+
this.info = info.bind(this);
|
|
588
|
+
this.error = error.bind(this);
|
|
589
|
+
this.debug = debug.bind(this);
|
|
590
|
+
this.trace = trace.bind(this);
|
|
591
|
+
this.notice = notice.bind(this);
|
|
592
|
+
this.inspect = inspect.bind(this);
|
|
593
|
+
this.printSummary = printSummary.bind(this);
|
|
594
|
+
this.configure = configure.bind(this);
|
|
595
|
+
this.printVersion = printVersion.bind(this);
|
|
596
|
+
this.registerSequence = registerSequence.bind(this);
|
|
597
|
+
this.wrap = wrap.bind(this);
|
|
598
|
+
this.decorate = decorate.bind(this);
|
|
599
|
+
this.floatFormat = floatFormat.bind(this);
|
|
600
|
+
this.counter = counter.bind(this);
|
|
601
|
+
this.getContext = getContext.bind(this);
|
|
602
|
+
this.composeMessage = composeMessage.bind(this);
|
|
603
|
+
this.reset = reset.bind(this);
|
|
604
|
+
const argv = process.argv.reduce((acc, curr) => {
|
|
605
|
+
const [k, v] = curr.split("=");
|
|
606
|
+
acc[k] = v === void 0 ? true : !Number.isNaN(Number(v)) ? Number(v) : v;
|
|
607
|
+
return acc;
|
|
608
|
+
}, {});
|
|
609
|
+
Object.keys(this.settings).forEach((a) => {
|
|
610
|
+
const opt = `--${a}`;
|
|
611
|
+
if (Object.hasOwn(argv, opt)) this.settings[a] = argv[opt];
|
|
612
|
+
});
|
|
613
|
+
this.configure();
|
|
614
|
+
this.bind();
|
|
615
|
+
}
|
|
616
|
+
newLine() {
|
|
617
|
+
process.stdout.write("\n");
|
|
618
|
+
}
|
|
619
|
+
}();
|
|
620
|
+
//#endregion
|
|
621
|
+
module.exports = log;
|