@innei/pretty-logger-core 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1105 @@
1
+ "use strict";
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 __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // index.ts
31
+ var core_exports = {};
32
+ __export(core_exports, {
33
+ BasicReporter: () => BasicReporter,
34
+ BrowserReporter: () => BrowserReporter,
35
+ Consola: () => Consola,
36
+ FancyReporter: () => FancyReporter,
37
+ FileReporter: () => FileReporter,
38
+ LEVEL_COLOR_MAP: () => LEVEL_COLOR_MAP,
39
+ LogLevels: () => LogLevels,
40
+ LogTypes: () => LogTypes,
41
+ LoggerReporter: () => LoggerReporter,
42
+ SubscriberReporter: () => SubscriberReporter,
43
+ TYPE_COLOR_MAP: () => TYPE_COLOR_MAP,
44
+ consola: () => consola,
45
+ createConsola: () => createConsola2,
46
+ createLoggerConsola: () => createLoggerConsola,
47
+ wrapperSubscribers: () => wrapperSubscribers
48
+ });
49
+ module.exports = __toCommonJS(core_exports);
50
+
51
+ // consola.instance.ts
52
+ var import_std_env3 = require("std-env");
53
+
54
+ // consola/index.ts
55
+ var import_std_env = require("std-env");
56
+
57
+ // consola/consola.ts
58
+ var import_defu = require("defu");
59
+
60
+ // consola/constants.ts
61
+ var LogLevels = {
62
+ silent: Number.NEGATIVE_INFINITY,
63
+ fatal: 0,
64
+ error: 0,
65
+ warn: 1,
66
+ log: 2,
67
+ info: 3,
68
+ success: 3,
69
+ fail: 3,
70
+ ready: 3,
71
+ start: 3,
72
+ box: 3,
73
+ debug: 4,
74
+ trace: 5,
75
+ verbose: Number.POSITIVE_INFINITY
76
+ };
77
+ var LogTypes = {
78
+ // Silent
79
+ silent: {
80
+ level: -1
81
+ },
82
+ // Level 0
83
+ fatal: {
84
+ level: LogLevels.fatal
85
+ },
86
+ error: {
87
+ level: LogLevels.error
88
+ },
89
+ // Level 1
90
+ warn: {
91
+ level: LogLevels.warn
92
+ },
93
+ // Level 2
94
+ log: {
95
+ level: LogLevels.log
96
+ },
97
+ // Level 3
98
+ info: {
99
+ level: LogLevels.info
100
+ },
101
+ success: {
102
+ level: LogLevels.success
103
+ },
104
+ fail: {
105
+ level: LogLevels.fail
106
+ },
107
+ ready: {
108
+ level: LogLevels.info
109
+ },
110
+ start: {
111
+ level: LogLevels.info
112
+ },
113
+ box: {
114
+ level: LogLevels.info
115
+ },
116
+ // Level 4
117
+ debug: {
118
+ level: LogLevels.debug
119
+ },
120
+ // Level 5
121
+ trace: {
122
+ level: LogLevels.trace
123
+ },
124
+ // Verbose
125
+ verbose: {
126
+ level: LogLevels.verbose
127
+ }
128
+ };
129
+
130
+ // consola/utils/log.ts
131
+ function isPlainObject(obj) {
132
+ return Object.prototype.toString.call(obj) === "[object Object]";
133
+ }
134
+ function isLogObj(arg) {
135
+ if (!isPlainObject(arg)) {
136
+ return false;
137
+ }
138
+ if (!arg.message && !arg.args) {
139
+ return false;
140
+ }
141
+ if (arg.stack) {
142
+ return false;
143
+ }
144
+ return true;
145
+ }
146
+
147
+ // consola/consola.ts
148
+ var paused = false;
149
+ var queue = [];
150
+ var Consola = class _Consola {
151
+ constructor(options = {}) {
152
+ const types = options.types || LogTypes;
153
+ this.options = (0, import_defu.defu)(
154
+ {
155
+ ...options,
156
+ defaults: { ...options.defaults },
157
+ level: _normalizeLogLevel(options.level, types),
158
+ reporters: [...options.reporters || []]
159
+ },
160
+ {
161
+ types: LogTypes,
162
+ throttle: 1e3,
163
+ throttleMin: 5,
164
+ formatOptions: {
165
+ date: true,
166
+ colors: false,
167
+ compact: true
168
+ }
169
+ }
170
+ );
171
+ for (const type in types) {
172
+ const defaults = {
173
+ type,
174
+ ...this.options.defaults,
175
+ ...types[type]
176
+ };
177
+ this[type] = this._wrapLogFn(defaults);
178
+ this[type].raw = this._wrapLogFn(
179
+ defaults,
180
+ true
181
+ );
182
+ }
183
+ if (this.options.mockFn) {
184
+ this.mockTypes();
185
+ }
186
+ this._lastLog = {};
187
+ }
188
+ get level() {
189
+ return this.options.level;
190
+ }
191
+ set level(level) {
192
+ this.options.level = _normalizeLogLevel(
193
+ level,
194
+ this.options.types,
195
+ this.options.level
196
+ );
197
+ }
198
+ create(options) {
199
+ const instance = new _Consola({
200
+ ...this.options,
201
+ ...options
202
+ });
203
+ if (this._mockFn) {
204
+ instance.mockTypes(this._mockFn);
205
+ }
206
+ return instance;
207
+ }
208
+ withDefaults(defaults) {
209
+ return this.create({
210
+ ...this.options,
211
+ defaults: {
212
+ ...this.options.defaults,
213
+ ...defaults
214
+ }
215
+ });
216
+ }
217
+ withTag(tag) {
218
+ return this.withDefaults({
219
+ tag: this.options.defaults.tag ? `${this.options.defaults.tag}:${tag}` : tag
220
+ });
221
+ }
222
+ addReporter(reporter) {
223
+ this.options.reporters.push(reporter);
224
+ return this;
225
+ }
226
+ removeReporter(reporter) {
227
+ if (reporter) {
228
+ const i = this.options.reporters.indexOf(reporter);
229
+ if (i >= 0) {
230
+ return this.options.reporters.splice(i, 1);
231
+ }
232
+ } else {
233
+ this.options.reporters.splice(0);
234
+ }
235
+ return this;
236
+ }
237
+ setReporters(reporters) {
238
+ this.options.reporters = Array.isArray(reporters) ? reporters : [reporters];
239
+ return this;
240
+ }
241
+ wrapAll() {
242
+ this.wrapConsole();
243
+ this.wrapStd();
244
+ }
245
+ restoreAll() {
246
+ this.restoreConsole();
247
+ this.restoreStd();
248
+ }
249
+ wrapConsole() {
250
+ for (const type in this.options.types) {
251
+ if (!console[`__${type}`]) {
252
+ ;
253
+ console[`__${type}`] = console[type];
254
+ }
255
+ ;
256
+ console[type] = this[type].raw;
257
+ }
258
+ }
259
+ restoreConsole() {
260
+ for (const type in this.options.types) {
261
+ if (console[`__${type}`]) {
262
+ ;
263
+ console[type] = console[`__${type}`];
264
+ delete console[`__${type}`];
265
+ }
266
+ }
267
+ }
268
+ wrapStd() {
269
+ this._wrapStream(this.options.stdout, "log");
270
+ this._wrapStream(this.options.stderr, "log");
271
+ }
272
+ _wrapStream(stream, type) {
273
+ if (!stream) {
274
+ return;
275
+ }
276
+ if (!stream.__write) {
277
+ ;
278
+ stream.__write = stream.write;
279
+ }
280
+ ;
281
+ stream.write = (data) => {
282
+ ;
283
+ this[type].raw(String(data).trim());
284
+ };
285
+ }
286
+ restoreStd() {
287
+ this._restoreStream(this.options.stdout);
288
+ this._restoreStream(this.options.stderr);
289
+ }
290
+ _restoreStream(stream) {
291
+ if (!stream) {
292
+ return;
293
+ }
294
+ if (stream.__write) {
295
+ stream.write = stream.__write;
296
+ delete stream.__write;
297
+ }
298
+ }
299
+ pauseLogs() {
300
+ paused = true;
301
+ }
302
+ resumeLogs() {
303
+ paused = false;
304
+ const _queue = queue.splice(0);
305
+ for (const item of _queue) {
306
+ item[0]._logFn(item[1], item[2]);
307
+ }
308
+ }
309
+ mockTypes(mockFn) {
310
+ const _mockFn = mockFn || this.options.mockFn;
311
+ this._mockFn = _mockFn;
312
+ if (typeof _mockFn !== "function") {
313
+ return;
314
+ }
315
+ for (const type in this.options.types) {
316
+ ;
317
+ this[type] = _mockFn(type, this.options.types[type]) || this[type];
318
+ this[type].raw = this[type];
319
+ }
320
+ }
321
+ _wrapLogFn(defaults, isRaw) {
322
+ return (...args) => {
323
+ if (paused) {
324
+ queue.push([this, defaults, args, isRaw]);
325
+ return;
326
+ }
327
+ return this._logFn(defaults, args, isRaw);
328
+ };
329
+ }
330
+ _logFn(defaults, args, isRaw) {
331
+ if ((defaults.level || 0) > this.level) {
332
+ return false;
333
+ }
334
+ const logObj = {
335
+ date: /* @__PURE__ */ new Date(),
336
+ args: [],
337
+ ...defaults,
338
+ level: _normalizeLogLevel(defaults.level, this.options.types)
339
+ };
340
+ if (!isRaw && args.length === 1 && isLogObj(args[0])) {
341
+ Object.assign(logObj, args[0]);
342
+ } else {
343
+ logObj.args = [...args];
344
+ }
345
+ if (logObj.message) {
346
+ logObj.args.unshift(logObj.message);
347
+ delete logObj.message;
348
+ }
349
+ if (logObj.additional) {
350
+ if (!Array.isArray(logObj.additional)) {
351
+ logObj.additional = logObj.additional.split("\n");
352
+ }
353
+ logObj.args.push(`
354
+ ${logObj.additional.join("\n")}`);
355
+ delete logObj.additional;
356
+ }
357
+ logObj.type = typeof logObj.type === "string" ? logObj.type.toLowerCase() : "log";
358
+ logObj.tag = typeof logObj.tag === "string" ? logObj.tag : "";
359
+ const resolveLog = (newLog = false) => {
360
+ const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
361
+ if (this._lastLog.object && repeated > 0) {
362
+ const args2 = [...this._lastLog.object.args];
363
+ if (repeated > 1) {
364
+ args2.push(`(repeated ${repeated} times)`);
365
+ }
366
+ this._log({ ...this._lastLog.object, args: args2 });
367
+ this._lastLog.count = 1;
368
+ }
369
+ if (newLog) {
370
+ this._lastLog.object = logObj;
371
+ this._log(logObj);
372
+ }
373
+ };
374
+ clearTimeout(this._lastLog.timeout);
375
+ const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
376
+ this._lastLog.time = logObj.date;
377
+ if (diffTime < this.options.throttle) {
378
+ try {
379
+ const serializedLog = JSON.stringify([
380
+ logObj.type,
381
+ logObj.tag,
382
+ logObj.args
383
+ ]);
384
+ const isSameLog = this._lastLog.serialized === serializedLog;
385
+ this._lastLog.serialized = serializedLog;
386
+ if (isSameLog) {
387
+ this._lastLog.count = (this._lastLog.count || 0) + 1;
388
+ if (this._lastLog.count > this.options.throttleMin) {
389
+ this._lastLog.timeout = setTimeout(
390
+ resolveLog,
391
+ this.options.throttle
392
+ );
393
+ return;
394
+ }
395
+ }
396
+ } catch {
397
+ }
398
+ }
399
+ resolveLog(true);
400
+ }
401
+ _log(logObj) {
402
+ for (const reporter of this.options.reporters) {
403
+ reporter.log(logObj, {
404
+ options: this.options
405
+ });
406
+ }
407
+ }
408
+ };
409
+ function _normalizeLogLevel(input, types = {}, defaultLevel = 3) {
410
+ if (input === void 0) {
411
+ return defaultLevel;
412
+ }
413
+ if (typeof input === "number") {
414
+ return input;
415
+ }
416
+ if (types[input] && types[input].level !== void 0) {
417
+ return types[input].level;
418
+ }
419
+ return defaultLevel;
420
+ }
421
+ Consola.prototype.add = Consola.prototype.addReporter;
422
+ Consola.prototype.remove = Consola.prototype.removeReporter;
423
+ Consola.prototype.clear = Consola.prototype.removeReporter;
424
+ Consola.prototype.withScope = Consola.prototype.withTag;
425
+ Consola.prototype.mock = Consola.prototype.mockTypes;
426
+ Consola.prototype.pause = Consola.prototype.pauseLogs;
427
+ Consola.prototype.resume = Consola.prototype.resumeLogs;
428
+ function createConsola(options = {}) {
429
+ return new Consola(options);
430
+ }
431
+
432
+ // consola/reporters/basic.ts
433
+ var import_node_util = require("util");
434
+
435
+ // consola/utils/error.ts
436
+ var import_node_path = require("path");
437
+ function parseStack(stack) {
438
+ const cwd = process.cwd() + import_node_path.sep;
439
+ const lines = stack.split("\n").splice(1).map((l) => l.trim().replace("file://", "").replace(cwd, ""));
440
+ return lines;
441
+ }
442
+
443
+ // consola/utils/stream.ts
444
+ function writeStream(data, stream) {
445
+ const write = stream.__write || stream.write;
446
+ return write.call(stream, data);
447
+ }
448
+
449
+ // consola/reporters/basic.ts
450
+ var bracket = (x) => x ? `[${x}]` : "";
451
+ var BasicReporter = class {
452
+ formatStack(stack, opts) {
453
+ return ` ${parseStack(stack).join("\n ")}`;
454
+ }
455
+ formatArgs(args, opts) {
456
+ const _args = args.map((arg) => {
457
+ if (arg && typeof arg.stack === "string") {
458
+ return `${arg.message}
459
+ ${this.formatStack(arg.stack, opts)}`;
460
+ }
461
+ return arg;
462
+ });
463
+ return (0, import_node_util.formatWithOptions)(opts, ..._args);
464
+ }
465
+ formatDate(date, opts) {
466
+ return opts.date ? date.toLocaleTimeString() : "";
467
+ }
468
+ filterAndJoin(arr) {
469
+ return arr.filter(Boolean).join(" ");
470
+ }
471
+ formatLogObj(logObj, opts) {
472
+ const message = this.formatArgs(logObj.args, opts);
473
+ if (logObj.type === "box") {
474
+ return `
475
+ ${[
476
+ bracket(logObj.tag),
477
+ logObj.title && logObj.title,
478
+ ...message.split("\n")
479
+ ].filter(Boolean).map((l) => ` > ${l}`).join("\n")}
480
+ `;
481
+ }
482
+ return this.filterAndJoin([
483
+ bracket(logObj.type),
484
+ bracket(logObj.tag),
485
+ message
486
+ ]);
487
+ }
488
+ log(logObj, ctx) {
489
+ const line = this.formatLogObj(logObj, {
490
+ columns: ctx.options.stdout.columns || 0,
491
+ ...ctx.options.formatOptions
492
+ });
493
+ return writeStream(
494
+ `${line}
495
+ `,
496
+ logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout
497
+ );
498
+ }
499
+ };
500
+
501
+ // consola/reporters/fancy.ts
502
+ var import_string_width = __toESM(require("string-width"));
503
+
504
+ // consola/utils/color.ts
505
+ var tty = __toESM(require("tty"));
506
+ var {
507
+ env = {},
508
+ argv = [],
509
+ platform = ""
510
+ } = typeof process === "undefined" ? {} : process;
511
+ var isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
512
+ var isForced = "FORCE_COLOR" in env || argv.includes("--color");
513
+ var isWindows = platform === "win32";
514
+ var isDumbTerminal = env.TERM === "dumb";
515
+ var isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
516
+ var isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
517
+ var isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
518
+ function replaceClose(index, string, close, replace, head = string.slice(0, Math.max(0, index)) + replace, tail = string.slice(Math.max(0, index + close.length)), next = tail.indexOf(close)) {
519
+ return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
520
+ }
521
+ function clearBleed(index, string, open, close, replace) {
522
+ return index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
523
+ }
524
+ function filterEmpty(open, close, replace = open, at = open.length + 1) {
525
+ return (string) => string || !(string === "" || string === void 0) ? clearBleed(`${string}`.indexOf(close, at), string, open, close, replace) : "";
526
+ }
527
+ function init(open, close, replace) {
528
+ return filterEmpty(`\x1B[${open}m`, `\x1B[${close}m`, replace);
529
+ }
530
+ var colorDefs = {
531
+ reset: init(0, 0),
532
+ bold: init(1, 22, "\x1B[22m\x1B[1m"),
533
+ dim: init(2, 22, "\x1B[22m\x1B[2m"),
534
+ italic: init(3, 23),
535
+ underline: init(4, 24),
536
+ inverse: init(7, 27),
537
+ hidden: init(8, 28),
538
+ strikethrough: init(9, 29),
539
+ black: init(30, 39),
540
+ red: init(31, 39),
541
+ green: init(32, 39),
542
+ yellow: init(33, 39),
543
+ blue: init(34, 39),
544
+ magenta: init(35, 39),
545
+ cyan: init(36, 39),
546
+ white: init(37, 39),
547
+ gray: init(90, 39),
548
+ bgBlack: init(40, 49),
549
+ bgRed: init(41, 49),
550
+ bgGreen: init(42, 49),
551
+ bgYellow: init(43, 49),
552
+ bgBlue: init(44, 49),
553
+ bgMagenta: init(45, 49),
554
+ bgCyan: init(46, 49),
555
+ bgWhite: init(47, 49),
556
+ blackBright: init(90, 39),
557
+ redBright: init(91, 39),
558
+ greenBright: init(92, 39),
559
+ yellowBright: init(93, 39),
560
+ blueBright: init(94, 39),
561
+ magentaBright: init(95, 39),
562
+ cyanBright: init(96, 39),
563
+ whiteBright: init(97, 39),
564
+ bgBlackBright: init(100, 49),
565
+ bgRedBright: init(101, 49),
566
+ bgGreenBright: init(102, 49),
567
+ bgYellowBright: init(103, 49),
568
+ bgBlueBright: init(104, 49),
569
+ bgMagentaBright: init(105, 49),
570
+ bgCyanBright: init(106, 49),
571
+ bgWhiteBright: init(107, 49)
572
+ };
573
+ function createColors(useColor = isColorSupported) {
574
+ return useColor ? colorDefs : Object.fromEntries(Object.keys(colorDefs).map((key) => [key, String]));
575
+ }
576
+ var colors = createColors();
577
+ function getColor(color, fallback = "reset") {
578
+ return colors[color] || colors[fallback];
579
+ }
580
+
581
+ // consola/utils/string.ts
582
+ var ansiRegex = [
583
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
584
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"
585
+ ].join("|");
586
+ function stripAnsi(text) {
587
+ return text.replace(new RegExp(ansiRegex, "g"), "");
588
+ }
589
+
590
+ // consola/utils/box.ts
591
+ var boxStylePresets = {
592
+ solid: {
593
+ tl: "\u250C",
594
+ tr: "\u2510",
595
+ bl: "\u2514",
596
+ br: "\u2518",
597
+ h: "\u2500",
598
+ v: "\u2502"
599
+ },
600
+ double: {
601
+ tl: "\u2554",
602
+ tr: "\u2557",
603
+ bl: "\u255A",
604
+ br: "\u255D",
605
+ h: "\u2550",
606
+ v: "\u2551"
607
+ },
608
+ doubleSingle: {
609
+ tl: "\u2553",
610
+ tr: "\u2556",
611
+ bl: "\u2559",
612
+ br: "\u255C",
613
+ h: "\u2500",
614
+ v: "\u2551"
615
+ },
616
+ doubleSingleRounded: {
617
+ tl: "\u256D",
618
+ tr: "\u256E",
619
+ bl: "\u2570",
620
+ br: "\u256F",
621
+ h: "\u2500",
622
+ v: "\u2551"
623
+ },
624
+ singleThick: {
625
+ tl: "\u250F",
626
+ tr: "\u2513",
627
+ bl: "\u2517",
628
+ br: "\u251B",
629
+ h: "\u2501",
630
+ v: "\u2503"
631
+ },
632
+ singleDouble: {
633
+ tl: "\u2552",
634
+ tr: "\u2555",
635
+ bl: "\u2558",
636
+ br: "\u255B",
637
+ h: "\u2550",
638
+ v: "\u2502"
639
+ },
640
+ singleDoubleRounded: {
641
+ tl: "\u256D",
642
+ tr: "\u256E",
643
+ bl: "\u2570",
644
+ br: "\u256F",
645
+ h: "\u2550",
646
+ v: "\u2502"
647
+ },
648
+ rounded: {
649
+ tl: "\u256D",
650
+ tr: "\u256E",
651
+ bl: "\u2570",
652
+ br: "\u256F",
653
+ h: "\u2500",
654
+ v: "\u2502"
655
+ }
656
+ };
657
+ var defaultStyle = {
658
+ borderColor: "white",
659
+ borderStyle: "rounded",
660
+ valign: "center",
661
+ padding: 2,
662
+ marginLeft: 1,
663
+ marginTop: 1,
664
+ marginBottom: 1
665
+ };
666
+ function box(text, _opts = {}) {
667
+ const opts = {
668
+ ..._opts,
669
+ style: {
670
+ ...defaultStyle,
671
+ ..._opts.style
672
+ }
673
+ };
674
+ const textLines = text.split("\n");
675
+ const boxLines = [];
676
+ const _color = getColor(opts.style.borderColor);
677
+ const borderStyle = {
678
+ ...typeof opts.style.borderStyle === "string" ? boxStylePresets[opts.style.borderStyle] || boxStylePresets.solid : opts.style.borderStyle
679
+ };
680
+ if (_color) {
681
+ for (const key in borderStyle) {
682
+ borderStyle[key] = _color(
683
+ borderStyle[key]
684
+ );
685
+ }
686
+ }
687
+ const paddingOffset = opts.style.padding % 2 === 0 ? opts.style.padding : opts.style.padding + 1;
688
+ const height = textLines.length + paddingOffset;
689
+ const width = Math.max(...textLines.map((line) => line.length)) + paddingOffset;
690
+ const widthOffset = width + paddingOffset;
691
+ const leftSpace = opts.style.marginLeft > 0 ? " ".repeat(opts.style.marginLeft) : "";
692
+ if (opts.style.marginTop > 0) {
693
+ boxLines.push("".repeat(opts.style.marginTop));
694
+ }
695
+ if (opts.title) {
696
+ const left = borderStyle.h.repeat(
697
+ Math.floor((width - stripAnsi(opts.title).length) / 2)
698
+ );
699
+ const right = borderStyle.h.repeat(
700
+ width - stripAnsi(opts.title).length - stripAnsi(left).length + paddingOffset
701
+ );
702
+ boxLines.push(
703
+ `${leftSpace}${borderStyle.tl}${left}${opts.title}${right}${borderStyle.tr}`
704
+ );
705
+ } else {
706
+ boxLines.push(
707
+ `${leftSpace}${borderStyle.tl}${borderStyle.h.repeat(widthOffset)}${borderStyle.tr}`
708
+ );
709
+ }
710
+ const valignOffset = opts.style.valign === "center" ? Math.floor((height - textLines.length) / 2) : opts.style.valign === "top" ? height - textLines.length - paddingOffset : height - textLines.length;
711
+ for (let i = 0; i < height; i++) {
712
+ if (i < valignOffset || i >= valignOffset + textLines.length) {
713
+ boxLines.push(
714
+ `${leftSpace}${borderStyle.v}${" ".repeat(widthOffset)}${borderStyle.v}`
715
+ );
716
+ } else {
717
+ const line = textLines[i - valignOffset];
718
+ const left = " ".repeat(paddingOffset);
719
+ const right = " ".repeat(width - stripAnsi(line).length);
720
+ boxLines.push(
721
+ `${leftSpace}${borderStyle.v}${left}${line}${right}${borderStyle.v}`
722
+ );
723
+ }
724
+ }
725
+ boxLines.push(
726
+ `${leftSpace}${borderStyle.bl}${borderStyle.h.repeat(widthOffset)}${borderStyle.br}`
727
+ );
728
+ if (opts.style.marginBottom > 0) {
729
+ boxLines.push("".repeat(opts.style.marginBottom));
730
+ }
731
+ return boxLines.join("\n");
732
+ }
733
+
734
+ // consola/utils/tester.ts
735
+ function isUnicodeSupported() {
736
+ if (process.platform !== "win32") {
737
+ return process.env.TERM !== "linux";
738
+ }
739
+ return Boolean(process.env.WT_SESSION) || // Windows Terminal
740
+ Boolean(process.env.TERMINUS_SUBLIME) || // Terminus (<0.2.27)
741
+ process.env.ConEmuTask === "{cmd::Cmder}" || // ConEmu and cmder
742
+ process.env.TERM_PROGRAM === "Terminus-Sublime" || process.env.TERM_PROGRAM === "vscode" || process.env.TERM === "xterm-256color" || process.env.TERM === "alacritty" || process.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
743
+ }
744
+
745
+ // consola/reporters/fancy.ts
746
+ var TYPE_COLOR_MAP = {
747
+ info: "cyan",
748
+ fail: "red",
749
+ success: "green",
750
+ ready: "green",
751
+ start: "magenta"
752
+ };
753
+ var LEVEL_COLOR_MAP = {
754
+ 0: "red",
755
+ 1: "yellow"
756
+ };
757
+ var unicode = isUnicodeSupported();
758
+ var s = (c, fallback) => unicode ? c : fallback;
759
+ var TYPE_ICONS = {
760
+ error: s("\u2716", "\xD7"),
761
+ fatal: s("\u2716", "\xD7"),
762
+ ready: s("\u2714", "\u221A"),
763
+ warn: s("\u26A0", "\u203C"),
764
+ info: s("\u2139", "i"),
765
+ success: s("\u2714", "\u221A"),
766
+ debug: s("\u2699", "D"),
767
+ trace: s("\u2192", "\u2192"),
768
+ fail: s("\u2716", "\xD7"),
769
+ start: s("\u25D0", "o"),
770
+ log: ""
771
+ };
772
+ function stringWidth(str) {
773
+ if (!Intl.Segmenter) {
774
+ return stripAnsi(str).length;
775
+ }
776
+ return (0, import_string_width.default)(str);
777
+ }
778
+ var FancyReporter = class extends BasicReporter {
779
+ formatStack(stack) {
780
+ return `
781
+ ${parseStack(stack).map(
782
+ (line) => ` ${line.replace(/^at +/, (m) => colors.gray(m)).replace(/\((.+)\)/, (_, m) => `(${colors.cyan(m)})`)}`
783
+ ).join("\n")}`;
784
+ }
785
+ formatType(logObj, isBadge, opts) {
786
+ const typeColor = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level] || "gray";
787
+ if (isBadge) {
788
+ return getBgColor(typeColor)(
789
+ colors.black(` ${logObj.type.toUpperCase()} `)
790
+ );
791
+ }
792
+ const _type = typeof TYPE_ICONS[logObj.type] === "string" ? TYPE_ICONS[logObj.type] : logObj.icon || logObj.type;
793
+ return _type ? getColor2(typeColor)(_type) : "";
794
+ }
795
+ formatLogObj(logObj, opts) {
796
+ const [message, ...additional] = this.formatArgs(logObj.args, opts).split(
797
+ "\n"
798
+ );
799
+ if (logObj.type === "box") {
800
+ return box(
801
+ characterFormat(
802
+ message + (additional.length > 0 ? `
803
+ ${additional.join("\n")}` : "")
804
+ ),
805
+ {
806
+ title: logObj.title ? characterFormat(logObj.title) : void 0,
807
+ style: logObj.style
808
+ }
809
+ );
810
+ }
811
+ const date = this.formatDate(logObj.date, opts);
812
+ const coloredDate = date && colors.gray(date);
813
+ const isBadge = logObj.badge ?? logObj.level < 2;
814
+ const type = this.formatType(logObj, isBadge, opts);
815
+ const tag = logObj.tag ? colors.gray(logObj.tag) : "";
816
+ let line;
817
+ const left = this.filterAndJoin([type, characterFormat(message)]);
818
+ const right = this.filterAndJoin(opts.columns ? [tag, coloredDate] : [tag]);
819
+ const space = (opts.columns || 0) - stringWidth(left) - stringWidth(right) - 2;
820
+ line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : "") + left;
821
+ line += characterFormat(
822
+ additional.length > 0 ? `
823
+ ${additional.join("\n")}` : ""
824
+ );
825
+ if (logObj.type === "trace") {
826
+ const _err = new Error(`Trace: ${logObj.message}`);
827
+ line += this.formatStack(_err.stack || "");
828
+ }
829
+ return isBadge ? `
830
+ ${line}
831
+ ` : line;
832
+ }
833
+ };
834
+ function characterFormat(str) {
835
+ return str.replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)).replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${colors.underline(m)} `);
836
+ }
837
+ function getColor2(color = "white") {
838
+ return colors[color] || colors.white;
839
+ }
840
+ function getBgColor(color = "bgWhite") {
841
+ return colors[`bg${color[0].toUpperCase()}${color.slice(1)}`] || colors.bgWhite;
842
+ }
843
+
844
+ // consola/index.ts
845
+ function createConsola2(options = {}) {
846
+ let level = _getDefaultLogLevel();
847
+ if (process.env.CONSOLA_LEVEL) {
848
+ level = Number.parseInt(process.env.CONSOLA_LEVEL) ?? level;
849
+ }
850
+ const consola2 = createConsola({
851
+ level,
852
+ defaults: { level },
853
+ stdout: process.stdout,
854
+ stderr: process.stderr,
855
+ reporters: options.reporters || [
856
+ options.fancy ?? !(import_std_env.isCI || import_std_env.isTest) ? new FancyReporter() : new BasicReporter()
857
+ ],
858
+ ...options
859
+ });
860
+ return consola2;
861
+ }
862
+ function _getDefaultLogLevel() {
863
+ if (import_std_env.isDebug) {
864
+ return LogLevels.debug;
865
+ }
866
+ if (import_std_env.isTest) {
867
+ return LogLevels.warn;
868
+ }
869
+ return LogLevels.info;
870
+ }
871
+ var consola = createConsola2();
872
+
873
+ // consola/reporters/file.ts
874
+ var import_fs = require("fs");
875
+ var fs = __toESM(require("fs"));
876
+ var import_path2 = require("path");
877
+ var import_cron = require("cron");
878
+
879
+ // tool.util.ts
880
+ var import_path = __toESM(require("path"));
881
+ var getShortTime = (date) => {
882
+ return Intl.DateTimeFormat("en-US", {
883
+ timeStyle: "medium",
884
+ hour12: false
885
+ }).format(date);
886
+ };
887
+ var getShortDate = (date) => {
888
+ return Intl.DateTimeFormat("en-US", {
889
+ dateStyle: "short"
890
+ }).format(date).replace(/\//g, "-");
891
+ };
892
+ var getLogFilePath = (logDir, formatString) => import_path.default.resolve(logDir, formatString.replace(/%d/g, getShortDate(/* @__PURE__ */ new Date())));
893
+
894
+ // consola/reporters/logger.ts
895
+ var import_picocolors = __toESM(require("picocolors"));
896
+ var import_std_env2 = require("std-env");
897
+ var LoggerReporter = class extends FancyReporter {
898
+ constructor() {
899
+ super(...arguments);
900
+ this.latestLogTime = Date.now();
901
+ }
902
+ formatDate(date, opts) {
903
+ const isInVirtualTerminal = typeof opts.columns === "undefined";
904
+ if (import_std_env2.isDevelopment) {
905
+ const now = Date.now();
906
+ const delta = now - this.latestLogTime;
907
+ this.latestLogTime = now;
908
+ return `+${delta | 0}ms ${super.formatDate(date, opts)}`;
909
+ }
910
+ return isInVirtualTerminal ? "" : super.formatDate(date, opts);
911
+ }
912
+ formatLogObj(logObj, opts) {
913
+ const isInVirtualTerminal = typeof opts.columns === "undefined";
914
+ return isInVirtualTerminal ? `${import_picocolors.default.gray(getShortTime(/* @__PURE__ */ new Date()))} ${super.formatLogObj(logObj, opts).replace(/^\n/, "")}`.trimEnd() : super.formatLogObj(logObj, opts);
915
+ }
916
+ };
917
+
918
+ // consola/reporters/file.ts
919
+ var FileReporter = class extends LoggerReporter {
920
+ constructor(configs) {
921
+ super();
922
+ this.configs = configs;
923
+ this.refreshWriteStream();
924
+ this.scheduleRefreshWriteStream();
925
+ }
926
+ scheduleRefreshWriteStream() {
927
+ const { cron = "0 0 * * *" } = this.configs;
928
+ const job = new import_cron.CronJob(cron, this.refreshWriteStream.bind(this));
929
+ job.start();
930
+ this.__job = job;
931
+ }
932
+ teardown() {
933
+ this.__job?.stop();
934
+ this.stdoutStream?.end();
935
+ this.stderrStream?.end();
936
+ }
937
+ refreshWriteStream() {
938
+ const {
939
+ loggerDir,
940
+ stderrFileFormat = "error.log",
941
+ stdoutFileFormat = "stdout_%d.log"
942
+ } = this.configs;
943
+ const stdoutPath = getLogFilePath(loggerDir, stdoutFileFormat);
944
+ const stderrPath = getLogFilePath(loggerDir, stderrFileFormat);
945
+ createLoggerFileIfNotExist(stdoutPath);
946
+ createLoggerFileIfNotExist(stderrPath);
947
+ const options = {
948
+ encoding: "utf-8",
949
+ flags: "a+"
950
+ };
951
+ [this.stderrStream, this.stdoutStream].forEach((stream) => {
952
+ stream?.end();
953
+ });
954
+ this.stdoutStream = (0, import_fs.createWriteStream)(stdoutPath, options);
955
+ this.stderrStream = (0, import_fs.createWriteStream)(stderrPath, options);
956
+ [this.stderrStream, this.stdoutStream].forEach((stream) => {
957
+ writeStream(
958
+ "\n========================================================\n",
959
+ stream
960
+ );
961
+ });
962
+ }
963
+ log(logObj, ctx) {
964
+ if (!this.stdoutStream || !this.stderrStream) {
965
+ return;
966
+ }
967
+ const finalStdout = this.stdoutStream;
968
+ const finalStderr = this.stderrStream || this.stdoutStream;
969
+ const line = super.formatLogObj(logObj, {
970
+ ...ctx.options.formatOptions,
971
+ columns: void 0
972
+ });
973
+ if (this.configs.errWriteToStdout && logObj.level < 2) {
974
+ writeStream(`${line}
975
+ `, finalStdout);
976
+ }
977
+ return writeStream(
978
+ `${line}
979
+ `,
980
+ logObj.level < 2 ? finalStderr : finalStdout
981
+ );
982
+ }
983
+ };
984
+ var createLoggerFileIfNotExist = (path2) => {
985
+ const dirPath = (0, import_path2.dirname)(path2);
986
+ if (!fs.existsSync(dirPath)) {
987
+ fs.mkdirSync(dirPath, { recursive: true });
988
+ }
989
+ if (!fs.existsSync(path2)) {
990
+ fs.writeFileSync(path2, "", { flag: "wx" });
991
+ }
992
+ };
993
+
994
+ // consola/reporters/subscriber.ts
995
+ var import_events = __toESM(require("events"));
996
+ var wrapperSubscribers = (consola2) => {
997
+ Object.assign(consola2, {
998
+ onData: (handler) => SubscriberReporter.subscriber.on("log", handler),
999
+ onStdOut: (handler) => SubscriberReporter.subscriber.on("stdout", handler),
1000
+ onStdErr: (handler) => SubscriberReporter.subscriber.on("stderr", handler)
1001
+ });
1002
+ return consola2;
1003
+ };
1004
+ var _SubscriberReporter = class _SubscriberReporter extends LoggerReporter {
1005
+ log(logObj, ctx) {
1006
+ const line = super.formatLogObj(logObj, ctx);
1007
+ const event = logObj.level < 2 ? "stderr" : "stdout";
1008
+ _SubscriberReporter.subscriber.emit(event, line);
1009
+ _SubscriberReporter.subscriber.emit("log", line);
1010
+ }
1011
+ };
1012
+ _SubscriberReporter.subscriber = new import_events.default();
1013
+ var SubscriberReporter = _SubscriberReporter;
1014
+
1015
+ // consola.instance.ts
1016
+ var createLoggerConsola = (options) => {
1017
+ const reporters = [
1018
+ new FancyReporter(),
1019
+ new SubscriberReporter()
1020
+ ];
1021
+ if (options?.writeToFile) {
1022
+ reporters.push(new FileReporter(options.writeToFile));
1023
+ }
1024
+ const consola2 = createConsola2({
1025
+ formatOptions: {
1026
+ date: true
1027
+ },
1028
+ reporters,
1029
+ level: import_std_env3.isDevelopment ? LogLevels.trace : LogLevels.info,
1030
+ ...options
1031
+ });
1032
+ return wrapperSubscribers(consola2);
1033
+ };
1034
+
1035
+ // consola/reporters/browser.ts
1036
+ var BrowserReporter = class {
1037
+ constructor(options) {
1038
+ this.options = { ...options };
1039
+ this.defaultColor = "#7f8c8d";
1040
+ this.levelColorMap = {
1041
+ 0: "#c0392b",
1042
+ // Red
1043
+ 1: "#f39c12",
1044
+ // Yellow
1045
+ 3: "#00BCD4"
1046
+ // Cyan
1047
+ };
1048
+ this.typeColorMap = {
1049
+ success: "#2ecc71"
1050
+ // Green
1051
+ };
1052
+ }
1053
+ _getLogFn(level) {
1054
+ if (level < 1) {
1055
+ return console.__error || console.error;
1056
+ }
1057
+ if (level === 1) {
1058
+ return console.__warn || console.warn;
1059
+ }
1060
+ return console.__log || console.log;
1061
+ }
1062
+ log(logObj) {
1063
+ const consoleLogFn = this._getLogFn(logObj.level);
1064
+ const type = logObj.type === "log" ? "" : logObj.type;
1065
+ const tag = logObj.tag || "";
1066
+ const color = this.typeColorMap[logObj.type] || this.levelColorMap[logObj.level] || this.defaultColor;
1067
+ const style = `
1068
+ background: ${color};
1069
+ border-radius: 0.5em;
1070
+ color: white;
1071
+ font-weight: bold;
1072
+ padding: 2px 0.5em;
1073
+ `;
1074
+ const badge = `%c${[tag, type].filter(Boolean).join(":")}`;
1075
+ if (typeof logObj.args[0] === "string") {
1076
+ consoleLogFn(
1077
+ `${badge}%c ${logObj.args[0]}`,
1078
+ style,
1079
+ // Empty string as style resets to default console style
1080
+ "",
1081
+ ...logObj.args.slice(1)
1082
+ );
1083
+ } else {
1084
+ consoleLogFn(badge, style, ...logObj.args);
1085
+ }
1086
+ }
1087
+ };
1088
+ // Annotate the CommonJS export names for ESM import in node:
1089
+ 0 && (module.exports = {
1090
+ BasicReporter,
1091
+ BrowserReporter,
1092
+ Consola,
1093
+ FancyReporter,
1094
+ FileReporter,
1095
+ LEVEL_COLOR_MAP,
1096
+ LogLevels,
1097
+ LogTypes,
1098
+ LoggerReporter,
1099
+ SubscriberReporter,
1100
+ TYPE_COLOR_MAP,
1101
+ consola,
1102
+ createConsola,
1103
+ createLoggerConsola,
1104
+ wrapperSubscribers
1105
+ });