feat: init
This commit is contained in:
32
node_modules/consola/dist/basic.cjs
generated
vendored
Normal file
32
node_modules/consola/dist/basic.cjs
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
const core = require('./core.cjs');
|
||||
const basic = require('./shared/consola.DCGIlDNP.cjs');
|
||||
require('node:util');
|
||||
require('node:path');
|
||||
|
||||
function createConsola(options = {}) {
|
||||
let level = core.LogLevels.info;
|
||||
if (process.env.CONSOLA_LEVEL) {
|
||||
level = Number.parseInt(process.env.CONSOLA_LEVEL) ?? level;
|
||||
}
|
||||
const consola2 = core.createConsola({
|
||||
level,
|
||||
defaults: { level },
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
reporters: options.reporters || [new basic.BasicReporter()],
|
||||
...options
|
||||
});
|
||||
return consola2;
|
||||
}
|
||||
const consola = createConsola();
|
||||
|
||||
exports.Consola = core.Consola;
|
||||
exports.LogLevels = core.LogLevels;
|
||||
exports.LogTypes = core.LogTypes;
|
||||
exports.consola = consola;
|
||||
exports.createConsola = createConsola;
|
||||
exports.default = consola;
|
||||
23
node_modules/consola/dist/basic.d.cts
generated
vendored
Normal file
23
node_modules/consola/dist/basic.d.cts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { ConsolaInstance, ConsolaOptions } from './core.cjs';
|
||||
export { ConfirmPromptOptions, Consola, ConsolaReporter, FormatOptions, InputLogObject, LogLevel, LogLevels, LogObject, LogType, LogTypes, MultiSelectOptions, PromptOptions, SelectPromptOptions, TextPromptOptions } from './core.cjs';
|
||||
|
||||
/**
|
||||
* Factory function to create a new Consola instance
|
||||
*
|
||||
* @param {Partial<ConsolaOptions & { fancy: boolean }>} [options={}] - Optional configuration options. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new Consola instance configured with the given options.
|
||||
*/
|
||||
declare function createConsola(options?: Partial<ConsolaOptions & {
|
||||
fancy: boolean;
|
||||
}>): ConsolaInstance;
|
||||
/**
|
||||
* Creates and exports a standard instance of Consola with the default configuration.
|
||||
* This instance can be used directly for logging throughout the application.
|
||||
*
|
||||
* @type {ConsolaInstance} consola - The default instance of Consola.
|
||||
*/
|
||||
declare const consola: ConsolaInstance;
|
||||
|
||||
// @ts-ignore
|
||||
export = consola;
|
||||
export { ConsolaInstance, ConsolaOptions, consola, createConsola };
|
||||
21
node_modules/consola/dist/basic.d.mts
generated
vendored
Normal file
21
node_modules/consola/dist/basic.d.mts
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { ConsolaInstance, ConsolaOptions } from './core.mjs';
|
||||
export { ConfirmPromptOptions, Consola, ConsolaReporter, FormatOptions, InputLogObject, LogLevel, LogLevels, LogObject, LogType, LogTypes, MultiSelectOptions, PromptOptions, SelectPromptOptions, TextPromptOptions } from './core.mjs';
|
||||
|
||||
/**
|
||||
* Factory function to create a new Consola instance
|
||||
*
|
||||
* @param {Partial<ConsolaOptions & { fancy: boolean }>} [options={}] - Optional configuration options. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new Consola instance configured with the given options.
|
||||
*/
|
||||
declare function createConsola(options?: Partial<ConsolaOptions & {
|
||||
fancy: boolean;
|
||||
}>): ConsolaInstance;
|
||||
/**
|
||||
* Creates and exports a standard instance of Consola with the default configuration.
|
||||
* This instance can be used directly for logging throughout the application.
|
||||
*
|
||||
* @type {ConsolaInstance} consola - The default instance of Consola.
|
||||
*/
|
||||
declare const consola: ConsolaInstance;
|
||||
|
||||
export { ConsolaInstance, ConsolaOptions, consola, createConsola, consola as default };
|
||||
23
node_modules/consola/dist/basic.d.ts
generated
vendored
Normal file
23
node_modules/consola/dist/basic.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { ConsolaInstance, ConsolaOptions } from './core.js';
|
||||
export { ConfirmPromptOptions, Consola, ConsolaReporter, FormatOptions, InputLogObject, LogLevel, LogLevels, LogObject, LogType, LogTypes, MultiSelectOptions, PromptOptions, SelectPromptOptions, TextPromptOptions } from './core.js';
|
||||
|
||||
/**
|
||||
* Factory function to create a new Consola instance
|
||||
*
|
||||
* @param {Partial<ConsolaOptions & { fancy: boolean }>} [options={}] - Optional configuration options. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new Consola instance configured with the given options.
|
||||
*/
|
||||
declare function createConsola(options?: Partial<ConsolaOptions & {
|
||||
fancy: boolean;
|
||||
}>): ConsolaInstance;
|
||||
/**
|
||||
* Creates and exports a standard instance of Consola with the default configuration.
|
||||
* This instance can be used directly for logging throughout the application.
|
||||
*
|
||||
* @type {ConsolaInstance} consola - The default instance of Consola.
|
||||
*/
|
||||
declare const consola: ConsolaInstance;
|
||||
|
||||
// @ts-ignore
|
||||
export = consola;
|
||||
export { ConsolaInstance, ConsolaOptions, consola, createConsola };
|
||||
24
node_modules/consola/dist/basic.mjs
generated
vendored
Normal file
24
node_modules/consola/dist/basic.mjs
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { LogLevels, createConsola as createConsola$1 } from './core.mjs';
|
||||
export { Consola, LogTypes } from './core.mjs';
|
||||
import { B as BasicReporter } from './shared/consola.DRwqZj3T.mjs';
|
||||
import 'node:util';
|
||||
import 'node:path';
|
||||
|
||||
function createConsola(options = {}) {
|
||||
let level = LogLevels.info;
|
||||
if (process.env.CONSOLA_LEVEL) {
|
||||
level = Number.parseInt(process.env.CONSOLA_LEVEL) ?? level;
|
||||
}
|
||||
const consola2 = createConsola$1({
|
||||
level,
|
||||
defaults: { level },
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
reporters: options.reporters || [new BasicReporter()],
|
||||
...options
|
||||
});
|
||||
return consola2;
|
||||
}
|
||||
const consola = createConsola();
|
||||
|
||||
export { LogLevels, consola, createConsola, consola as default };
|
||||
84
node_modules/consola/dist/browser.cjs
generated
vendored
Normal file
84
node_modules/consola/dist/browser.cjs
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
const core = require('./core.cjs');
|
||||
|
||||
class BrowserReporter {
|
||||
options;
|
||||
defaultColor;
|
||||
levelColorMap;
|
||||
typeColorMap;
|
||||
constructor(options) {
|
||||
this.options = { ...options };
|
||||
this.defaultColor = "#7f8c8d";
|
||||
this.levelColorMap = {
|
||||
0: "#c0392b",
|
||||
// Red
|
||||
1: "#f39c12",
|
||||
// Yellow
|
||||
3: "#00BCD4"
|
||||
// Cyan
|
||||
};
|
||||
this.typeColorMap = {
|
||||
success: "#2ecc71"
|
||||
// Green
|
||||
};
|
||||
}
|
||||
_getLogFn(level) {
|
||||
if (level < 1) {
|
||||
return console.__error || console.error;
|
||||
}
|
||||
if (level === 1) {
|
||||
return console.__warn || console.warn;
|
||||
}
|
||||
return console.__log || console.log;
|
||||
}
|
||||
log(logObj) {
|
||||
const consoleLogFn = this._getLogFn(logObj.level);
|
||||
const type = logObj.type === "log" ? "" : logObj.type;
|
||||
const tag = logObj.tag || "";
|
||||
const color = this.typeColorMap[logObj.type] || this.levelColorMap[logObj.level] || this.defaultColor;
|
||||
const style = `
|
||||
background: ${color};
|
||||
border-radius: 0.5em;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
padding: 2px 0.5em;
|
||||
`;
|
||||
const badge = `%c${[tag, type].filter(Boolean).join(":")}`;
|
||||
if (typeof logObj.args[0] === "string") {
|
||||
consoleLogFn(
|
||||
`${badge}%c ${logObj.args[0]}`,
|
||||
style,
|
||||
// Empty string as style resets to default console style
|
||||
"",
|
||||
...logObj.args.slice(1)
|
||||
);
|
||||
} else {
|
||||
consoleLogFn(badge, style, ...logObj.args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createConsola(options = {}) {
|
||||
const consola2 = core.createConsola({
|
||||
reporters: options.reporters || [new BrowserReporter({})],
|
||||
prompt(message, options2 = {}) {
|
||||
if (options2.type === "confirm") {
|
||||
return Promise.resolve(confirm(message));
|
||||
}
|
||||
return Promise.resolve(prompt(message));
|
||||
},
|
||||
...options
|
||||
});
|
||||
return consola2;
|
||||
}
|
||||
const consola = createConsola();
|
||||
|
||||
exports.Consola = core.Consola;
|
||||
exports.LogLevels = core.LogLevels;
|
||||
exports.LogTypes = core.LogTypes;
|
||||
exports.consola = consola;
|
||||
exports.createConsola = createConsola;
|
||||
exports.default = consola;
|
||||
23
node_modules/consola/dist/browser.d.cts
generated
vendored
Normal file
23
node_modules/consola/dist/browser.d.cts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { ConsolaInstance, ConsolaOptions } from './core.cjs';
|
||||
export { ConfirmPromptOptions, Consola, ConsolaReporter, FormatOptions, InputLogObject, LogLevel, LogLevels, LogObject, LogType, LogTypes, MultiSelectOptions, PromptOptions, SelectPromptOptions, TextPromptOptions } from './core.cjs';
|
||||
|
||||
/**
|
||||
* Creates a new Consola instance configured specifically for browser environments.
|
||||
* This function sets up default reporters and a prompt method tailored to the browser's dialogue APIs.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} [options={}] - Optional configuration options.
|
||||
* The options can override the default reporter and prompt behaviour. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new Consola instance optimised for use in browser environments.
|
||||
*/
|
||||
declare function createConsola(options?: Partial<ConsolaOptions>): ConsolaInstance;
|
||||
/**
|
||||
* A standard Consola instance created with browser-specific configurations.
|
||||
* This instance can be used throughout a browser-based project.
|
||||
*
|
||||
* @type {ConsolaInstance} consola - The default browser-configured Consola instance.
|
||||
*/
|
||||
declare const consola: ConsolaInstance;
|
||||
|
||||
// @ts-ignore
|
||||
export = consola;
|
||||
export { ConsolaInstance, ConsolaOptions, consola, createConsola };
|
||||
21
node_modules/consola/dist/browser.d.mts
generated
vendored
Normal file
21
node_modules/consola/dist/browser.d.mts
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { ConsolaInstance, ConsolaOptions } from './core.mjs';
|
||||
export { ConfirmPromptOptions, Consola, ConsolaReporter, FormatOptions, InputLogObject, LogLevel, LogLevels, LogObject, LogType, LogTypes, MultiSelectOptions, PromptOptions, SelectPromptOptions, TextPromptOptions } from './core.mjs';
|
||||
|
||||
/**
|
||||
* Creates a new Consola instance configured specifically for browser environments.
|
||||
* This function sets up default reporters and a prompt method tailored to the browser's dialogue APIs.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} [options={}] - Optional configuration options.
|
||||
* The options can override the default reporter and prompt behaviour. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new Consola instance optimised for use in browser environments.
|
||||
*/
|
||||
declare function createConsola(options?: Partial<ConsolaOptions>): ConsolaInstance;
|
||||
/**
|
||||
* A standard Consola instance created with browser-specific configurations.
|
||||
* This instance can be used throughout a browser-based project.
|
||||
*
|
||||
* @type {ConsolaInstance} consola - The default browser-configured Consola instance.
|
||||
*/
|
||||
declare const consola: ConsolaInstance;
|
||||
|
||||
export { ConsolaInstance, ConsolaOptions, consola, createConsola, consola as default };
|
||||
23
node_modules/consola/dist/browser.d.ts
generated
vendored
Normal file
23
node_modules/consola/dist/browser.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { ConsolaInstance, ConsolaOptions } from './core.js';
|
||||
export { ConfirmPromptOptions, Consola, ConsolaReporter, FormatOptions, InputLogObject, LogLevel, LogLevels, LogObject, LogType, LogTypes, MultiSelectOptions, PromptOptions, SelectPromptOptions, TextPromptOptions } from './core.js';
|
||||
|
||||
/**
|
||||
* Creates a new Consola instance configured specifically for browser environments.
|
||||
* This function sets up default reporters and a prompt method tailored to the browser's dialogue APIs.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} [options={}] - Optional configuration options.
|
||||
* The options can override the default reporter and prompt behaviour. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new Consola instance optimised for use in browser environments.
|
||||
*/
|
||||
declare function createConsola(options?: Partial<ConsolaOptions>): ConsolaInstance;
|
||||
/**
|
||||
* A standard Consola instance created with browser-specific configurations.
|
||||
* This instance can be used throughout a browser-based project.
|
||||
*
|
||||
* @type {ConsolaInstance} consola - The default browser-configured Consola instance.
|
||||
*/
|
||||
declare const consola: ConsolaInstance;
|
||||
|
||||
// @ts-ignore
|
||||
export = consola;
|
||||
export { ConsolaInstance, ConsolaOptions, consola, createConsola };
|
||||
76
node_modules/consola/dist/browser.mjs
generated
vendored
Normal file
76
node_modules/consola/dist/browser.mjs
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
import { createConsola as createConsola$1 } from './core.mjs';
|
||||
export { Consola, LogLevels, LogTypes } from './core.mjs';
|
||||
|
||||
class BrowserReporter {
|
||||
options;
|
||||
defaultColor;
|
||||
levelColorMap;
|
||||
typeColorMap;
|
||||
constructor(options) {
|
||||
this.options = { ...options };
|
||||
this.defaultColor = "#7f8c8d";
|
||||
this.levelColorMap = {
|
||||
0: "#c0392b",
|
||||
// Red
|
||||
1: "#f39c12",
|
||||
// Yellow
|
||||
3: "#00BCD4"
|
||||
// Cyan
|
||||
};
|
||||
this.typeColorMap = {
|
||||
success: "#2ecc71"
|
||||
// Green
|
||||
};
|
||||
}
|
||||
_getLogFn(level) {
|
||||
if (level < 1) {
|
||||
return console.__error || console.error;
|
||||
}
|
||||
if (level === 1) {
|
||||
return console.__warn || console.warn;
|
||||
}
|
||||
return console.__log || console.log;
|
||||
}
|
||||
log(logObj) {
|
||||
const consoleLogFn = this._getLogFn(logObj.level);
|
||||
const type = logObj.type === "log" ? "" : logObj.type;
|
||||
const tag = logObj.tag || "";
|
||||
const color = this.typeColorMap[logObj.type] || this.levelColorMap[logObj.level] || this.defaultColor;
|
||||
const style = `
|
||||
background: ${color};
|
||||
border-radius: 0.5em;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
padding: 2px 0.5em;
|
||||
`;
|
||||
const badge = `%c${[tag, type].filter(Boolean).join(":")}`;
|
||||
if (typeof logObj.args[0] === "string") {
|
||||
consoleLogFn(
|
||||
`${badge}%c ${logObj.args[0]}`,
|
||||
style,
|
||||
// Empty string as style resets to default console style
|
||||
"",
|
||||
...logObj.args.slice(1)
|
||||
);
|
||||
} else {
|
||||
consoleLogFn(badge, style, ...logObj.args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createConsola(options = {}) {
|
||||
const consola2 = createConsola$1({
|
||||
reporters: options.reporters || [new BrowserReporter({})],
|
||||
prompt(message, options2 = {}) {
|
||||
if (options2.type === "confirm") {
|
||||
return Promise.resolve(confirm(message));
|
||||
}
|
||||
return Promise.resolve(prompt(message));
|
||||
},
|
||||
...options
|
||||
});
|
||||
return consola2;
|
||||
}
|
||||
const consola = createConsola();
|
||||
|
||||
export { consola, createConsola, consola as default };
|
||||
288
node_modules/consola/dist/chunks/prompt.cjs
generated
vendored
Normal file
288
node_modules/consola/dist/chunks/prompt.cjs
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
280
node_modules/consola/dist/chunks/prompt.mjs
generated
vendored
Normal file
280
node_modules/consola/dist/chunks/prompt.mjs
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
517
node_modules/consola/dist/core.cjs
generated
vendored
Normal file
517
node_modules/consola/dist/core.cjs
generated
vendored
Normal file
@@ -0,0 +1,517 @@
|
||||
'use strict';
|
||||
|
||||
const LogLevels = {
|
||||
silent: Number.NEGATIVE_INFINITY,
|
||||
fatal: 0,
|
||||
error: 0,
|
||||
warn: 1,
|
||||
log: 2,
|
||||
info: 3,
|
||||
success: 3,
|
||||
fail: 3,
|
||||
ready: 3,
|
||||
start: 3,
|
||||
box: 3,
|
||||
debug: 4,
|
||||
trace: 5,
|
||||
verbose: Number.POSITIVE_INFINITY
|
||||
};
|
||||
const LogTypes = {
|
||||
// Silent
|
||||
silent: {
|
||||
level: -1
|
||||
},
|
||||
// Level 0
|
||||
fatal: {
|
||||
level: LogLevels.fatal
|
||||
},
|
||||
error: {
|
||||
level: LogLevels.error
|
||||
},
|
||||
// Level 1
|
||||
warn: {
|
||||
level: LogLevels.warn
|
||||
},
|
||||
// Level 2
|
||||
log: {
|
||||
level: LogLevels.log
|
||||
},
|
||||
// Level 3
|
||||
info: {
|
||||
level: LogLevels.info
|
||||
},
|
||||
success: {
|
||||
level: LogLevels.success
|
||||
},
|
||||
fail: {
|
||||
level: LogLevels.fail
|
||||
},
|
||||
ready: {
|
||||
level: LogLevels.info
|
||||
},
|
||||
start: {
|
||||
level: LogLevels.info
|
||||
},
|
||||
box: {
|
||||
level: LogLevels.info
|
||||
},
|
||||
// Level 4
|
||||
debug: {
|
||||
level: LogLevels.debug
|
||||
},
|
||||
// Level 5
|
||||
trace: {
|
||||
level: LogLevels.trace
|
||||
},
|
||||
// Verbose
|
||||
verbose: {
|
||||
level: LogLevels.verbose
|
||||
}
|
||||
};
|
||||
|
||||
function isPlainObject$1(value) {
|
||||
if (value === null || typeof value !== "object") {
|
||||
return false;
|
||||
}
|
||||
const prototype = Object.getPrototypeOf(value);
|
||||
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
||||
return false;
|
||||
}
|
||||
if (Symbol.iterator in value) {
|
||||
return false;
|
||||
}
|
||||
if (Symbol.toStringTag in value) {
|
||||
return Object.prototype.toString.call(value) === "[object Module]";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function _defu(baseObject, defaults, namespace = ".", merger) {
|
||||
if (!isPlainObject$1(defaults)) {
|
||||
return _defu(baseObject, {}, namespace, merger);
|
||||
}
|
||||
const object = Object.assign({}, defaults);
|
||||
for (const key in baseObject) {
|
||||
if (key === "__proto__" || key === "constructor") {
|
||||
continue;
|
||||
}
|
||||
const value = baseObject[key];
|
||||
if (value === null || value === void 0) {
|
||||
continue;
|
||||
}
|
||||
if (merger && merger(object, key, value, namespace)) {
|
||||
continue;
|
||||
}
|
||||
if (Array.isArray(value) && Array.isArray(object[key])) {
|
||||
object[key] = [...value, ...object[key]];
|
||||
} else if (isPlainObject$1(value) && isPlainObject$1(object[key])) {
|
||||
object[key] = _defu(
|
||||
value,
|
||||
object[key],
|
||||
(namespace ? `${namespace}.` : "") + key.toString(),
|
||||
merger
|
||||
);
|
||||
} else {
|
||||
object[key] = value;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
function createDefu(merger) {
|
||||
return (...arguments_) => (
|
||||
// eslint-disable-next-line unicorn/no-array-reduce
|
||||
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
||||
);
|
||||
}
|
||||
const defu = createDefu();
|
||||
|
||||
function isPlainObject(obj) {
|
||||
return Object.prototype.toString.call(obj) === "[object Object]";
|
||||
}
|
||||
function isLogObj(arg) {
|
||||
if (!isPlainObject(arg)) {
|
||||
return false;
|
||||
}
|
||||
if (!arg.message && !arg.args) {
|
||||
return false;
|
||||
}
|
||||
if (arg.stack) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
let paused = false;
|
||||
const queue = [];
|
||||
class Consola {
|
||||
options;
|
||||
_lastLog;
|
||||
_mockFn;
|
||||
/**
|
||||
* Creates an instance of Consola with specified options or defaults.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} [options={}] - Configuration options for the Consola instance.
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
const types = options.types || LogTypes;
|
||||
this.options = defu(
|
||||
{
|
||||
...options,
|
||||
defaults: { ...options.defaults },
|
||||
level: _normalizeLogLevel(options.level, types),
|
||||
reporters: [...options.reporters || []]
|
||||
},
|
||||
{
|
||||
types: LogTypes,
|
||||
throttle: 1e3,
|
||||
throttleMin: 5,
|
||||
formatOptions: {
|
||||
date: true,
|
||||
colors: false,
|
||||
compact: true
|
||||
}
|
||||
}
|
||||
);
|
||||
for (const type in types) {
|
||||
const defaults = {
|
||||
type,
|
||||
...this.options.defaults,
|
||||
...types[type]
|
||||
};
|
||||
this[type] = this._wrapLogFn(defaults);
|
||||
this[type].raw = this._wrapLogFn(
|
||||
defaults,
|
||||
true
|
||||
);
|
||||
}
|
||||
if (this.options.mockFn) {
|
||||
this.mockTypes();
|
||||
}
|
||||
this._lastLog = {};
|
||||
}
|
||||
/**
|
||||
* Gets the current log level of the Consola instance.
|
||||
*
|
||||
* @returns {number} The current log level.
|
||||
*/
|
||||
get level() {
|
||||
return this.options.level;
|
||||
}
|
||||
/**
|
||||
* Sets the minimum log level that will be output by the instance.
|
||||
*
|
||||
* @param {number} level - The new log level to set.
|
||||
*/
|
||||
set level(level) {
|
||||
this.options.level = _normalizeLogLevel(
|
||||
level,
|
||||
this.options.types,
|
||||
this.options.level
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Displays a prompt to the user and returns the response.
|
||||
* Throw an error if `prompt` is not supported by the current configuration.
|
||||
*
|
||||
* @template T
|
||||
* @param {string} message - The message to display in the prompt.
|
||||
* @param {T} [opts] - Optional options for the prompt. See {@link PromptOptions}.
|
||||
* @returns {promise<T>} A promise that infer with the prompt options. See {@link PromptOptions}.
|
||||
*/
|
||||
prompt(message, opts) {
|
||||
if (!this.options.prompt) {
|
||||
throw new Error("prompt is not supported!");
|
||||
}
|
||||
return this.options.prompt(message, opts);
|
||||
}
|
||||
/**
|
||||
* Creates a new instance of Consola, inheriting options from the current instance, with possible overrides.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} options - Optional overrides for the new instance. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
create(options) {
|
||||
const instance = new Consola({
|
||||
...this.options,
|
||||
...options
|
||||
});
|
||||
if (this._mockFn) {
|
||||
instance.mockTypes(this._mockFn);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
/**
|
||||
* Creates a new Consola instance with the specified default log object properties.
|
||||
*
|
||||
* @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
withDefaults(defaults) {
|
||||
return this.create({
|
||||
...this.options,
|
||||
defaults: {
|
||||
...this.options.defaults,
|
||||
...defaults
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Creates a new Consola instance with a specified tag, which will be included in every log.
|
||||
*
|
||||
* @param {string} tag - The tag to include in each log of the new instance.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
withTag(tag) {
|
||||
return this.withDefaults({
|
||||
tag: this.options.defaults.tag ? this.options.defaults.tag + ":" + tag : tag
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds a custom reporter to the Consola instance.
|
||||
* Reporters will be called for each log message, depending on their implementation and log level.
|
||||
*
|
||||
* @param {ConsolaReporter} reporter - The reporter to add. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
addReporter(reporter) {
|
||||
this.options.reporters.push(reporter);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Removes a custom reporter from the Consola instance.
|
||||
* If no reporter is specified, all reporters will be removed.
|
||||
*
|
||||
* @param {ConsolaReporter} reporter - The reporter to remove. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
removeReporter(reporter) {
|
||||
if (reporter) {
|
||||
const i = this.options.reporters.indexOf(reporter);
|
||||
if (i !== -1) {
|
||||
return this.options.reporters.splice(i, 1);
|
||||
}
|
||||
} else {
|
||||
this.options.reporters.splice(0);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Replaces all reporters of the Consola instance with the specified array of reporters.
|
||||
*
|
||||
* @param {ConsolaReporter[]} reporters - The new reporters to set. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
setReporters(reporters) {
|
||||
this.options.reporters = Array.isArray(reporters) ? reporters : [reporters];
|
||||
return this;
|
||||
}
|
||||
wrapAll() {
|
||||
this.wrapConsole();
|
||||
this.wrapStd();
|
||||
}
|
||||
restoreAll() {
|
||||
this.restoreConsole();
|
||||
this.restoreStd();
|
||||
}
|
||||
/**
|
||||
* Overrides console methods with Consola logging methods for consistent logging.
|
||||
*/
|
||||
wrapConsole() {
|
||||
for (const type in this.options.types) {
|
||||
if (!console["__" + type]) {
|
||||
console["__" + type] = console[type];
|
||||
}
|
||||
console[type] = this[type].raw;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Restores the original console methods, removing Consola overrides.
|
||||
*/
|
||||
restoreConsole() {
|
||||
for (const type in this.options.types) {
|
||||
if (console["__" + type]) {
|
||||
console[type] = console["__" + type];
|
||||
delete console["__" + type];
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Overrides standard output and error streams to redirect them through Consola.
|
||||
*/
|
||||
wrapStd() {
|
||||
this._wrapStream(this.options.stdout, "log");
|
||||
this._wrapStream(this.options.stderr, "log");
|
||||
}
|
||||
_wrapStream(stream, type) {
|
||||
if (!stream) {
|
||||
return;
|
||||
}
|
||||
if (!stream.__write) {
|
||||
stream.__write = stream.write;
|
||||
}
|
||||
stream.write = (data) => {
|
||||
this[type].raw(String(data).trim());
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Restores the original standard output and error streams, removing the Consola redirection.
|
||||
*/
|
||||
restoreStd() {
|
||||
this._restoreStream(this.options.stdout);
|
||||
this._restoreStream(this.options.stderr);
|
||||
}
|
||||
_restoreStream(stream) {
|
||||
if (!stream) {
|
||||
return;
|
||||
}
|
||||
if (stream.__write) {
|
||||
stream.write = stream.__write;
|
||||
delete stream.__write;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Pauses logging, queues incoming logs until resumed.
|
||||
*/
|
||||
pauseLogs() {
|
||||
paused = true;
|
||||
}
|
||||
/**
|
||||
* Resumes logging, processing any queued logs.
|
||||
*/
|
||||
resumeLogs() {
|
||||
paused = false;
|
||||
const _queue = queue.splice(0);
|
||||
for (const item of _queue) {
|
||||
item[0]._logFn(item[1], item[2]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Replaces logging methods with mocks if a mock function is provided.
|
||||
*
|
||||
* @param {ConsolaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link ConsolaOptions["mockFn"]}.
|
||||
*/
|
||||
mockTypes(mockFn) {
|
||||
const _mockFn = mockFn || this.options.mockFn;
|
||||
this._mockFn = _mockFn;
|
||||
if (typeof _mockFn !== "function") {
|
||||
return;
|
||||
}
|
||||
for (const type in this.options.types) {
|
||||
this[type] = _mockFn(type, this.options.types[type]) || this[type];
|
||||
this[type].raw = this[type];
|
||||
}
|
||||
}
|
||||
_wrapLogFn(defaults, isRaw) {
|
||||
return (...args) => {
|
||||
if (paused) {
|
||||
queue.push([this, defaults, args, isRaw]);
|
||||
return;
|
||||
}
|
||||
return this._logFn(defaults, args, isRaw);
|
||||
};
|
||||
}
|
||||
_logFn(defaults, args, isRaw) {
|
||||
if ((defaults.level || 0) > this.level) {
|
||||
return false;
|
||||
}
|
||||
const logObj = {
|
||||
date: /* @__PURE__ */ new Date(),
|
||||
args: [],
|
||||
...defaults,
|
||||
level: _normalizeLogLevel(defaults.level, this.options.types)
|
||||
};
|
||||
if (!isRaw && args.length === 1 && isLogObj(args[0])) {
|
||||
Object.assign(logObj, args[0]);
|
||||
} else {
|
||||
logObj.args = [...args];
|
||||
}
|
||||
if (logObj.message) {
|
||||
logObj.args.unshift(logObj.message);
|
||||
delete logObj.message;
|
||||
}
|
||||
if (logObj.additional) {
|
||||
if (!Array.isArray(logObj.additional)) {
|
||||
logObj.additional = logObj.additional.split("\n");
|
||||
}
|
||||
logObj.args.push("\n" + logObj.additional.join("\n"));
|
||||
delete logObj.additional;
|
||||
}
|
||||
logObj.type = typeof logObj.type === "string" ? logObj.type.toLowerCase() : "log";
|
||||
logObj.tag = typeof logObj.tag === "string" ? logObj.tag : "";
|
||||
const resolveLog = (newLog = false) => {
|
||||
const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
|
||||
if (this._lastLog.object && repeated > 0) {
|
||||
const args2 = [...this._lastLog.object.args];
|
||||
if (repeated > 1) {
|
||||
args2.push(`(repeated ${repeated} times)`);
|
||||
}
|
||||
this._log({ ...this._lastLog.object, args: args2 });
|
||||
this._lastLog.count = 1;
|
||||
}
|
||||
if (newLog) {
|
||||
this._lastLog.object = logObj;
|
||||
this._log(logObj);
|
||||
}
|
||||
};
|
||||
clearTimeout(this._lastLog.timeout);
|
||||
const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
|
||||
this._lastLog.time = logObj.date;
|
||||
if (diffTime < this.options.throttle) {
|
||||
try {
|
||||
const serializedLog = JSON.stringify([
|
||||
logObj.type,
|
||||
logObj.tag,
|
||||
logObj.args
|
||||
]);
|
||||
const isSameLog = this._lastLog.serialized === serializedLog;
|
||||
this._lastLog.serialized = serializedLog;
|
||||
if (isSameLog) {
|
||||
this._lastLog.count = (this._lastLog.count || 0) + 1;
|
||||
if (this._lastLog.count > this.options.throttleMin) {
|
||||
this._lastLog.timeout = setTimeout(
|
||||
resolveLog,
|
||||
this.options.throttle
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
resolveLog(true);
|
||||
}
|
||||
_log(logObj) {
|
||||
for (const reporter of this.options.reporters) {
|
||||
reporter.log(logObj, {
|
||||
options: this.options
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
function _normalizeLogLevel(input, types = {}, defaultLevel = 3) {
|
||||
if (input === void 0) {
|
||||
return defaultLevel;
|
||||
}
|
||||
if (typeof input === "number") {
|
||||
return input;
|
||||
}
|
||||
if (types[input] && types[input].level !== void 0) {
|
||||
return types[input].level;
|
||||
}
|
||||
return defaultLevel;
|
||||
}
|
||||
Consola.prototype.add = Consola.prototype.addReporter;
|
||||
Consola.prototype.remove = Consola.prototype.removeReporter;
|
||||
Consola.prototype.clear = Consola.prototype.removeReporter;
|
||||
Consola.prototype.withScope = Consola.prototype.withTag;
|
||||
Consola.prototype.mock = Consola.prototype.mockTypes;
|
||||
Consola.prototype.pause = Consola.prototype.pauseLogs;
|
||||
Consola.prototype.resume = Consola.prototype.resumeLogs;
|
||||
function createConsola(options = {}) {
|
||||
return new Consola(options);
|
||||
}
|
||||
|
||||
exports.Consola = Consola;
|
||||
exports.LogLevels = LogLevels;
|
||||
exports.LogTypes = LogTypes;
|
||||
exports.createConsola = createConsola;
|
||||
459
node_modules/consola/dist/core.d.cts
generated
vendored
Normal file
459
node_modules/consola/dist/core.d.cts
generated
vendored
Normal file
@@ -0,0 +1,459 @@
|
||||
type SelectOption = {
|
||||
label: string;
|
||||
value: string;
|
||||
hint?: string;
|
||||
};
|
||||
declare const kCancel: unique symbol;
|
||||
type PromptCommonOptions = {
|
||||
/**
|
||||
* Specify how to handle a cancelled prompt (e.g. by pressing Ctrl+C).
|
||||
*
|
||||
* Default strategy is `"default"`.
|
||||
*
|
||||
* - `"default"` - Resolve the promise with the `default` value or `initial` value.
|
||||
* - `"undefined`" - Resolve the promise with `undefined`.
|
||||
* - `"null"` - Resolve the promise with `null`.
|
||||
* - `"symbol"` - Resolve the promise with a symbol `Symbol.for("cancel")`.
|
||||
* - `"reject"` - Reject the promise with an error.
|
||||
*/
|
||||
cancel?: "reject" | "default" | "undefined" | "null" | "symbol";
|
||||
};
|
||||
type TextPromptOptions = PromptCommonOptions & {
|
||||
/**
|
||||
* Specifies the prompt type as text.
|
||||
* @optional
|
||||
* @default "text"
|
||||
*/
|
||||
type?: "text";
|
||||
/**
|
||||
* The default text value.
|
||||
* @optional
|
||||
*/
|
||||
default?: string;
|
||||
/**
|
||||
* A placeholder text displayed in the prompt.
|
||||
* @optional
|
||||
*/
|
||||
placeholder?: string;
|
||||
/**
|
||||
* The initial text value.
|
||||
* @optional
|
||||
*/
|
||||
initial?: string;
|
||||
};
|
||||
type ConfirmPromptOptions = PromptCommonOptions & {
|
||||
/**
|
||||
* Specifies the prompt type as confirm.
|
||||
*/
|
||||
type: "confirm";
|
||||
/**
|
||||
* The initial value for the confirm prompt.
|
||||
* @optional
|
||||
*/
|
||||
initial?: boolean;
|
||||
};
|
||||
type SelectPromptOptions = PromptCommonOptions & {
|
||||
/**
|
||||
* Specifies the prompt type as select.
|
||||
*/
|
||||
type: "select";
|
||||
/**
|
||||
* The initial value for the select prompt.
|
||||
* @optional
|
||||
*/
|
||||
initial?: string;
|
||||
/**
|
||||
* The options to select from. See {@link SelectOption}.
|
||||
*/
|
||||
options: (string | SelectOption)[];
|
||||
};
|
||||
type MultiSelectOptions = PromptCommonOptions & {
|
||||
/**
|
||||
* Specifies the prompt type as multiselect.
|
||||
*/
|
||||
type: "multiselect";
|
||||
/**
|
||||
* The options to select from. See {@link SelectOption}.
|
||||
*/
|
||||
initial?: string[];
|
||||
/**
|
||||
* The options to select from. See {@link SelectOption}.
|
||||
*/
|
||||
options: (string | SelectOption)[];
|
||||
/**
|
||||
* Whether the prompt requires at least one selection.
|
||||
*/
|
||||
required?: boolean;
|
||||
};
|
||||
/**
|
||||
* Defines a combined type for all prompt options.
|
||||
*/
|
||||
type PromptOptions = TextPromptOptions | ConfirmPromptOptions | SelectPromptOptions | MultiSelectOptions;
|
||||
type inferPromptReturnType<T extends PromptOptions> = T extends TextPromptOptions ? string : T extends ConfirmPromptOptions ? boolean : T extends SelectPromptOptions ? T["options"][number] extends SelectOption ? T["options"][number]["value"] : T["options"][number] : T extends MultiSelectOptions ? T["options"] : unknown;
|
||||
type inferPromptCancalReturnType<T extends PromptOptions> = T extends {
|
||||
cancel: "reject";
|
||||
} ? never : T extends {
|
||||
cancel: "default";
|
||||
} ? inferPromptReturnType<T> : T extends {
|
||||
cancel: "undefined";
|
||||
} ? undefined : T extends {
|
||||
cancel: "null";
|
||||
} ? null : T extends {
|
||||
cancel: "symbol";
|
||||
} ? typeof kCancel : inferPromptReturnType<T>;
|
||||
/**
|
||||
* Asynchronously prompts the user for input based on specified options.
|
||||
* Supports text, confirm, select and multi-select prompts.
|
||||
*
|
||||
* @param {string} message - The message to display in the prompt.
|
||||
* @param {PromptOptions} [opts={}] - The prompt options. See {@link PromptOptions}.
|
||||
* @returns {Promise<inferPromptReturnType<T>>} - A promise that resolves with the user's response, the type of which is inferred from the options. See {@link inferPromptReturnType}.
|
||||
*/
|
||||
declare function prompt<_ = any, __ = any, T extends PromptOptions = TextPromptOptions>(message: string, opts?: PromptOptions): Promise<inferPromptReturnType<T> | inferPromptCancalReturnType<T>>;
|
||||
|
||||
/**
|
||||
* Defines the level of logs as specific numbers or special number types.
|
||||
*
|
||||
* @type {0 | 1 | 2 | 3 | 4 | 5 | (number & {})} LogLevel - Represents the log level.
|
||||
* @default 0 - Represents the default log level.
|
||||
*/
|
||||
type LogLevel = 0 | 1 | 2 | 3 | 4 | 5 | (number & {});
|
||||
/**
|
||||
* A mapping of `LogType` to its corresponding numeric log level.
|
||||
*
|
||||
* @type {Record<LogType, number>} LogLevels - key-value pairs of log types to their numeric levels. See {@link LogType}.
|
||||
*/
|
||||
declare const LogLevels: Record<LogType, number>;
|
||||
/**
|
||||
* Lists the types of log messages supported by the system.
|
||||
*
|
||||
* @type {"silent" | "fatal" | "error" | "warn" | "log" | "info" | "success" | "fail" | "ready" | "start" | "box" | "debug" | "trace" | "verbose"} LogType - Represents the specific type of log message.
|
||||
*/
|
||||
type LogType = "silent" | "fatal" | "error" | "warn" | "log" | "info" | "success" | "fail" | "ready" | "start" | "box" | "debug" | "trace" | "verbose";
|
||||
/**
|
||||
* Maps `LogType` to a `Partial<LogObject>`, primarily defining the log level.
|
||||
*
|
||||
* @type {Record<LogType, Partial<LogObject>>} LogTypes - key-value pairs of log types to partial log objects, specifying log levels. See {@link LogType} and {@link LogObject}.
|
||||
*/
|
||||
declare const LogTypes: Record<LogType, Partial<LogObject>>;
|
||||
|
||||
interface ConsolaOptions {
|
||||
/**
|
||||
* An array of ConsolaReporter instances used to handle and output log messages.
|
||||
*/
|
||||
reporters: ConsolaReporter[];
|
||||
/**
|
||||
* A record mapping LogType to InputLogObject, defining the log configuration for each log type.
|
||||
* See {@link LogType} and {@link InputLogObject}.
|
||||
*/
|
||||
types: Record<LogType, InputLogObject>;
|
||||
/**
|
||||
* The minimum log level to output. See {@link LogLevel}.
|
||||
*/
|
||||
level: LogLevel;
|
||||
/**
|
||||
* Default properties applied to all log messages unless overridden. See {@link InputLogObject}.
|
||||
*/
|
||||
defaults: InputLogObject;
|
||||
/**
|
||||
* The maximum number of times a log message can be repeated within a given timeframe.
|
||||
*/
|
||||
throttle: number;
|
||||
/**
|
||||
* The minimum time in milliseconds that must elapse before a throttled log message can be logged again.
|
||||
*/
|
||||
throttleMin: number;
|
||||
/**
|
||||
* The Node.js writable stream for standard output. See {@link NodeJS.WriteStream}.
|
||||
* @optional
|
||||
*/
|
||||
stdout?: NodeJS.WriteStream;
|
||||
/**
|
||||
* The Node.js writeable stream for standard error output. See {@link NodeJS.WriteStream}.
|
||||
* @optional
|
||||
*/
|
||||
stderr?: NodeJS.WriteStream;
|
||||
/**
|
||||
* A function that allows you to mock log messages for testing purposes.
|
||||
* @optional
|
||||
*/
|
||||
mockFn?: (type: LogType, defaults: InputLogObject) => (...args: any) => void;
|
||||
/**
|
||||
* Custom prompt function to use. It can be undefined.
|
||||
* @optional
|
||||
*/
|
||||
prompt?: typeof prompt | undefined;
|
||||
/**
|
||||
* Configuration options for formatting log messages. See {@link FormatOptions}.
|
||||
*/
|
||||
formatOptions: FormatOptions;
|
||||
}
|
||||
/**
|
||||
* @see https://nodejs.org/api/util.html#util_util_inspect_object_showhidden_depth_colors
|
||||
*/
|
||||
interface FormatOptions {
|
||||
/**
|
||||
* The maximum number of columns to output, affects formatting.
|
||||
* @optional
|
||||
*/
|
||||
columns?: number;
|
||||
/**
|
||||
* Whether to include timestamp information in log messages.
|
||||
* @optional
|
||||
*/
|
||||
date?: boolean;
|
||||
/**
|
||||
* Whether to use colors in the output.
|
||||
* @optional
|
||||
*/
|
||||
colors?: boolean;
|
||||
/**
|
||||
* Specifies whether or not the output should be compact. Accepts a boolean or numeric level of compactness.
|
||||
* @optional
|
||||
*/
|
||||
compact?: boolean | number;
|
||||
/**
|
||||
* Error cause level.
|
||||
*/
|
||||
errorLevel?: number;
|
||||
/**
|
||||
* Allows additional custom formatting options.
|
||||
*/
|
||||
[key: string]: unknown;
|
||||
}
|
||||
interface InputLogObject {
|
||||
/**
|
||||
* The logging level of the message. See {@link LogLevel}.
|
||||
* @optional
|
||||
*/
|
||||
level?: LogLevel;
|
||||
/**
|
||||
* A string tag to categorise or identify the log message.
|
||||
* @optional
|
||||
*/
|
||||
tag?: string;
|
||||
/**
|
||||
* The type of log message, which affects how it's processed and displayed. See {@link LogType}.
|
||||
* @optional
|
||||
*/
|
||||
type?: LogType;
|
||||
/**
|
||||
* The main log message text.
|
||||
* @optional
|
||||
*/
|
||||
message?: string;
|
||||
/**
|
||||
* Additional text or texts to be logged with the message.
|
||||
* @optional
|
||||
*/
|
||||
additional?: string | string[];
|
||||
/**
|
||||
* Additional arguments to be logged with the message.
|
||||
* @optional
|
||||
*/
|
||||
args?: any[];
|
||||
/**
|
||||
* The date and time when the log message was created.
|
||||
* @optional
|
||||
*/
|
||||
date?: Date;
|
||||
}
|
||||
interface LogObject extends InputLogObject {
|
||||
/**
|
||||
* The logging level of the message, overridden if required. See {@link LogLevel}.
|
||||
*/
|
||||
level: LogLevel;
|
||||
/**
|
||||
* The type of log message, overridden if required. See {@link LogType}.
|
||||
*/
|
||||
type: LogType;
|
||||
/**
|
||||
* A string tag to categorise or identify the log message, overridden if necessary.
|
||||
*/
|
||||
tag: string;
|
||||
/**
|
||||
* Additional arguments to be logged with the message, overridden if necessary.
|
||||
*/
|
||||
args: any[];
|
||||
/**
|
||||
* The date and time the log message was created, overridden if necessary.
|
||||
*/
|
||||
date: Date;
|
||||
/**
|
||||
* Allows additional custom properties to be set on the log object.
|
||||
*/
|
||||
[key: string]: unknown;
|
||||
}
|
||||
interface ConsolaReporter {
|
||||
/**
|
||||
* Defines how a log message is processed and displayed by this reporter.
|
||||
* @param logObj The LogObject containing the log information to process. See {@link LogObject}.
|
||||
* @param ctx An object containing context information such as options. See {@link ConsolaOptions}.
|
||||
*/
|
||||
log: (logObj: LogObject, ctx: {
|
||||
options: ConsolaOptions;
|
||||
}) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consola class for logging management with support for pause/resume, mocking and customisable reporting.
|
||||
* Provides flexible logging capabilities including level-based logging, custom reporters and integration options.
|
||||
*
|
||||
* @class Consola
|
||||
*/
|
||||
declare class Consola {
|
||||
options: ConsolaOptions;
|
||||
_lastLog: {
|
||||
serialized?: string;
|
||||
object?: LogObject;
|
||||
count?: number;
|
||||
time?: Date;
|
||||
timeout?: ReturnType<typeof setTimeout>;
|
||||
};
|
||||
_mockFn?: ConsolaOptions["mockFn"];
|
||||
/**
|
||||
* Creates an instance of Consola with specified options or defaults.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} [options={}] - Configuration options for the Consola instance.
|
||||
*/
|
||||
constructor(options?: Partial<ConsolaOptions>);
|
||||
/**
|
||||
* Gets the current log level of the Consola instance.
|
||||
*
|
||||
* @returns {number} The current log level.
|
||||
*/
|
||||
get level(): LogLevel;
|
||||
/**
|
||||
* Sets the minimum log level that will be output by the instance.
|
||||
*
|
||||
* @param {number} level - The new log level to set.
|
||||
*/
|
||||
set level(level: LogLevel);
|
||||
/**
|
||||
* Displays a prompt to the user and returns the response.
|
||||
* Throw an error if `prompt` is not supported by the current configuration.
|
||||
*
|
||||
* @template T
|
||||
* @param {string} message - The message to display in the prompt.
|
||||
* @param {T} [opts] - Optional options for the prompt. See {@link PromptOptions}.
|
||||
* @returns {promise<T>} A promise that infer with the prompt options. See {@link PromptOptions}.
|
||||
*/
|
||||
prompt<T extends PromptOptions>(message: string, opts?: T): Promise<(T extends TextPromptOptions ? string : T extends ConfirmPromptOptions ? boolean : T extends SelectPromptOptions ? T["options"][number] extends {
|
||||
label: string;
|
||||
value: string;
|
||||
hint?: string;
|
||||
} ? T["options"][number]["value"] : T["options"][number] : T extends MultiSelectOptions ? T["options"] : unknown) | (T extends {
|
||||
cancel: "reject";
|
||||
} ? never : T extends {
|
||||
cancel: "default";
|
||||
} ? T extends infer T_1 ? T_1 extends T ? T_1 extends TextPromptOptions ? string : T_1 extends ConfirmPromptOptions ? boolean : T_1 extends SelectPromptOptions ? T_1["options"][number] extends {
|
||||
label: string;
|
||||
value: string;
|
||||
hint?: string;
|
||||
} ? T_1["options"][number]["value"] : T_1["options"][number] : T_1 extends MultiSelectOptions ? T_1["options"] : unknown : never : never : T extends {
|
||||
cancel: "undefined";
|
||||
} ? undefined : T extends {
|
||||
cancel: "null";
|
||||
} ? null : T extends {
|
||||
cancel: "symbol";
|
||||
} ? typeof kCancel : T extends TextPromptOptions ? string : T extends ConfirmPromptOptions ? boolean : T extends SelectPromptOptions ? T["options"][number] extends {
|
||||
label: string;
|
||||
value: string;
|
||||
hint?: string;
|
||||
} ? T["options"][number]["value"] : T["options"][number] : T extends MultiSelectOptions ? T["options"] : unknown)>;
|
||||
/**
|
||||
* Creates a new instance of Consola, inheriting options from the current instance, with possible overrides.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} options - Optional overrides for the new instance. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
create(options: Partial<ConsolaOptions>): ConsolaInstance;
|
||||
/**
|
||||
* Creates a new Consola instance with the specified default log object properties.
|
||||
*
|
||||
* @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
withDefaults(defaults: InputLogObject): ConsolaInstance;
|
||||
/**
|
||||
* Creates a new Consola instance with a specified tag, which will be included in every log.
|
||||
*
|
||||
* @param {string} tag - The tag to include in each log of the new instance.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
withTag(tag: string): ConsolaInstance;
|
||||
/**
|
||||
* Adds a custom reporter to the Consola instance.
|
||||
* Reporters will be called for each log message, depending on their implementation and log level.
|
||||
*
|
||||
* @param {ConsolaReporter} reporter - The reporter to add. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
addReporter(reporter: ConsolaReporter): this;
|
||||
/**
|
||||
* Removes a custom reporter from the Consola instance.
|
||||
* If no reporter is specified, all reporters will be removed.
|
||||
*
|
||||
* @param {ConsolaReporter} reporter - The reporter to remove. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
removeReporter(reporter: ConsolaReporter): ConsolaReporter[] | this;
|
||||
/**
|
||||
* Replaces all reporters of the Consola instance with the specified array of reporters.
|
||||
*
|
||||
* @param {ConsolaReporter[]} reporters - The new reporters to set. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
setReporters(reporters: ConsolaReporter[]): this;
|
||||
wrapAll(): void;
|
||||
restoreAll(): void;
|
||||
/**
|
||||
* Overrides console methods with Consola logging methods for consistent logging.
|
||||
*/
|
||||
wrapConsole(): void;
|
||||
/**
|
||||
* Restores the original console methods, removing Consola overrides.
|
||||
*/
|
||||
restoreConsole(): void;
|
||||
/**
|
||||
* Overrides standard output and error streams to redirect them through Consola.
|
||||
*/
|
||||
wrapStd(): void;
|
||||
_wrapStream(stream: NodeJS.WriteStream | undefined, type: LogType): void;
|
||||
/**
|
||||
* Restores the original standard output and error streams, removing the Consola redirection.
|
||||
*/
|
||||
restoreStd(): void;
|
||||
_restoreStream(stream?: NodeJS.WriteStream): void;
|
||||
/**
|
||||
* Pauses logging, queues incoming logs until resumed.
|
||||
*/
|
||||
pauseLogs(): void;
|
||||
/**
|
||||
* Resumes logging, processing any queued logs.
|
||||
*/
|
||||
resumeLogs(): void;
|
||||
/**
|
||||
* Replaces logging methods with mocks if a mock function is provided.
|
||||
*
|
||||
* @param {ConsolaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link ConsolaOptions["mockFn"]}.
|
||||
*/
|
||||
mockTypes(mockFn?: ConsolaOptions["mockFn"]): void;
|
||||
_wrapLogFn(defaults: InputLogObject, isRaw?: boolean): (...args: any[]) => false | undefined;
|
||||
_logFn(defaults: InputLogObject, args: any[], isRaw?: boolean): false | undefined;
|
||||
_log(logObj: LogObject): void;
|
||||
}
|
||||
interface LogFn {
|
||||
(message: InputLogObject | any, ...args: any[]): void;
|
||||
raw: (...args: any[]) => void;
|
||||
}
|
||||
type ConsolaInstance = Consola & Record<LogType, LogFn>;
|
||||
/**
|
||||
* Utility for creating a new Consola instance with optional configuration.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} [options={}] - Optional configuration options for the new Consola instance. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new instance of Consola. See {@link ConsolaInstance}.
|
||||
*/
|
||||
declare function createConsola(options?: Partial<ConsolaOptions>): ConsolaInstance;
|
||||
|
||||
export { type ConfirmPromptOptions, Consola, type ConsolaInstance, type ConsolaOptions, type ConsolaReporter, type FormatOptions, type InputLogObject, type LogLevel, LogLevels, type LogObject, type LogType, LogTypes, type MultiSelectOptions, type PromptOptions, type SelectPromptOptions, type TextPromptOptions, createConsola };
|
||||
459
node_modules/consola/dist/core.d.mts
generated
vendored
Normal file
459
node_modules/consola/dist/core.d.mts
generated
vendored
Normal file
@@ -0,0 +1,459 @@
|
||||
type SelectOption = {
|
||||
label: string;
|
||||
value: string;
|
||||
hint?: string;
|
||||
};
|
||||
declare const kCancel: unique symbol;
|
||||
type PromptCommonOptions = {
|
||||
/**
|
||||
* Specify how to handle a cancelled prompt (e.g. by pressing Ctrl+C).
|
||||
*
|
||||
* Default strategy is `"default"`.
|
||||
*
|
||||
* - `"default"` - Resolve the promise with the `default` value or `initial` value.
|
||||
* - `"undefined`" - Resolve the promise with `undefined`.
|
||||
* - `"null"` - Resolve the promise with `null`.
|
||||
* - `"symbol"` - Resolve the promise with a symbol `Symbol.for("cancel")`.
|
||||
* - `"reject"` - Reject the promise with an error.
|
||||
*/
|
||||
cancel?: "reject" | "default" | "undefined" | "null" | "symbol";
|
||||
};
|
||||
type TextPromptOptions = PromptCommonOptions & {
|
||||
/**
|
||||
* Specifies the prompt type as text.
|
||||
* @optional
|
||||
* @default "text"
|
||||
*/
|
||||
type?: "text";
|
||||
/**
|
||||
* The default text value.
|
||||
* @optional
|
||||
*/
|
||||
default?: string;
|
||||
/**
|
||||
* A placeholder text displayed in the prompt.
|
||||
* @optional
|
||||
*/
|
||||
placeholder?: string;
|
||||
/**
|
||||
* The initial text value.
|
||||
* @optional
|
||||
*/
|
||||
initial?: string;
|
||||
};
|
||||
type ConfirmPromptOptions = PromptCommonOptions & {
|
||||
/**
|
||||
* Specifies the prompt type as confirm.
|
||||
*/
|
||||
type: "confirm";
|
||||
/**
|
||||
* The initial value for the confirm prompt.
|
||||
* @optional
|
||||
*/
|
||||
initial?: boolean;
|
||||
};
|
||||
type SelectPromptOptions = PromptCommonOptions & {
|
||||
/**
|
||||
* Specifies the prompt type as select.
|
||||
*/
|
||||
type: "select";
|
||||
/**
|
||||
* The initial value for the select prompt.
|
||||
* @optional
|
||||
*/
|
||||
initial?: string;
|
||||
/**
|
||||
* The options to select from. See {@link SelectOption}.
|
||||
*/
|
||||
options: (string | SelectOption)[];
|
||||
};
|
||||
type MultiSelectOptions = PromptCommonOptions & {
|
||||
/**
|
||||
* Specifies the prompt type as multiselect.
|
||||
*/
|
||||
type: "multiselect";
|
||||
/**
|
||||
* The options to select from. See {@link SelectOption}.
|
||||
*/
|
||||
initial?: string[];
|
||||
/**
|
||||
* The options to select from. See {@link SelectOption}.
|
||||
*/
|
||||
options: (string | SelectOption)[];
|
||||
/**
|
||||
* Whether the prompt requires at least one selection.
|
||||
*/
|
||||
required?: boolean;
|
||||
};
|
||||
/**
|
||||
* Defines a combined type for all prompt options.
|
||||
*/
|
||||
type PromptOptions = TextPromptOptions | ConfirmPromptOptions | SelectPromptOptions | MultiSelectOptions;
|
||||
type inferPromptReturnType<T extends PromptOptions> = T extends TextPromptOptions ? string : T extends ConfirmPromptOptions ? boolean : T extends SelectPromptOptions ? T["options"][number] extends SelectOption ? T["options"][number]["value"] : T["options"][number] : T extends MultiSelectOptions ? T["options"] : unknown;
|
||||
type inferPromptCancalReturnType<T extends PromptOptions> = T extends {
|
||||
cancel: "reject";
|
||||
} ? never : T extends {
|
||||
cancel: "default";
|
||||
} ? inferPromptReturnType<T> : T extends {
|
||||
cancel: "undefined";
|
||||
} ? undefined : T extends {
|
||||
cancel: "null";
|
||||
} ? null : T extends {
|
||||
cancel: "symbol";
|
||||
} ? typeof kCancel : inferPromptReturnType<T>;
|
||||
/**
|
||||
* Asynchronously prompts the user for input based on specified options.
|
||||
* Supports text, confirm, select and multi-select prompts.
|
||||
*
|
||||
* @param {string} message - The message to display in the prompt.
|
||||
* @param {PromptOptions} [opts={}] - The prompt options. See {@link PromptOptions}.
|
||||
* @returns {Promise<inferPromptReturnType<T>>} - A promise that resolves with the user's response, the type of which is inferred from the options. See {@link inferPromptReturnType}.
|
||||
*/
|
||||
declare function prompt<_ = any, __ = any, T extends PromptOptions = TextPromptOptions>(message: string, opts?: PromptOptions): Promise<inferPromptReturnType<T> | inferPromptCancalReturnType<T>>;
|
||||
|
||||
/**
|
||||
* Defines the level of logs as specific numbers or special number types.
|
||||
*
|
||||
* @type {0 | 1 | 2 | 3 | 4 | 5 | (number & {})} LogLevel - Represents the log level.
|
||||
* @default 0 - Represents the default log level.
|
||||
*/
|
||||
type LogLevel = 0 | 1 | 2 | 3 | 4 | 5 | (number & {});
|
||||
/**
|
||||
* A mapping of `LogType` to its corresponding numeric log level.
|
||||
*
|
||||
* @type {Record<LogType, number>} LogLevels - key-value pairs of log types to their numeric levels. See {@link LogType}.
|
||||
*/
|
||||
declare const LogLevels: Record<LogType, number>;
|
||||
/**
|
||||
* Lists the types of log messages supported by the system.
|
||||
*
|
||||
* @type {"silent" | "fatal" | "error" | "warn" | "log" | "info" | "success" | "fail" | "ready" | "start" | "box" | "debug" | "trace" | "verbose"} LogType - Represents the specific type of log message.
|
||||
*/
|
||||
type LogType = "silent" | "fatal" | "error" | "warn" | "log" | "info" | "success" | "fail" | "ready" | "start" | "box" | "debug" | "trace" | "verbose";
|
||||
/**
|
||||
* Maps `LogType` to a `Partial<LogObject>`, primarily defining the log level.
|
||||
*
|
||||
* @type {Record<LogType, Partial<LogObject>>} LogTypes - key-value pairs of log types to partial log objects, specifying log levels. See {@link LogType} and {@link LogObject}.
|
||||
*/
|
||||
declare const LogTypes: Record<LogType, Partial<LogObject>>;
|
||||
|
||||
interface ConsolaOptions {
|
||||
/**
|
||||
* An array of ConsolaReporter instances used to handle and output log messages.
|
||||
*/
|
||||
reporters: ConsolaReporter[];
|
||||
/**
|
||||
* A record mapping LogType to InputLogObject, defining the log configuration for each log type.
|
||||
* See {@link LogType} and {@link InputLogObject}.
|
||||
*/
|
||||
types: Record<LogType, InputLogObject>;
|
||||
/**
|
||||
* The minimum log level to output. See {@link LogLevel}.
|
||||
*/
|
||||
level: LogLevel;
|
||||
/**
|
||||
* Default properties applied to all log messages unless overridden. See {@link InputLogObject}.
|
||||
*/
|
||||
defaults: InputLogObject;
|
||||
/**
|
||||
* The maximum number of times a log message can be repeated within a given timeframe.
|
||||
*/
|
||||
throttle: number;
|
||||
/**
|
||||
* The minimum time in milliseconds that must elapse before a throttled log message can be logged again.
|
||||
*/
|
||||
throttleMin: number;
|
||||
/**
|
||||
* The Node.js writable stream for standard output. See {@link NodeJS.WriteStream}.
|
||||
* @optional
|
||||
*/
|
||||
stdout?: NodeJS.WriteStream;
|
||||
/**
|
||||
* The Node.js writeable stream for standard error output. See {@link NodeJS.WriteStream}.
|
||||
* @optional
|
||||
*/
|
||||
stderr?: NodeJS.WriteStream;
|
||||
/**
|
||||
* A function that allows you to mock log messages for testing purposes.
|
||||
* @optional
|
||||
*/
|
||||
mockFn?: (type: LogType, defaults: InputLogObject) => (...args: any) => void;
|
||||
/**
|
||||
* Custom prompt function to use. It can be undefined.
|
||||
* @optional
|
||||
*/
|
||||
prompt?: typeof prompt | undefined;
|
||||
/**
|
||||
* Configuration options for formatting log messages. See {@link FormatOptions}.
|
||||
*/
|
||||
formatOptions: FormatOptions;
|
||||
}
|
||||
/**
|
||||
* @see https://nodejs.org/api/util.html#util_util_inspect_object_showhidden_depth_colors
|
||||
*/
|
||||
interface FormatOptions {
|
||||
/**
|
||||
* The maximum number of columns to output, affects formatting.
|
||||
* @optional
|
||||
*/
|
||||
columns?: number;
|
||||
/**
|
||||
* Whether to include timestamp information in log messages.
|
||||
* @optional
|
||||
*/
|
||||
date?: boolean;
|
||||
/**
|
||||
* Whether to use colors in the output.
|
||||
* @optional
|
||||
*/
|
||||
colors?: boolean;
|
||||
/**
|
||||
* Specifies whether or not the output should be compact. Accepts a boolean or numeric level of compactness.
|
||||
* @optional
|
||||
*/
|
||||
compact?: boolean | number;
|
||||
/**
|
||||
* Error cause level.
|
||||
*/
|
||||
errorLevel?: number;
|
||||
/**
|
||||
* Allows additional custom formatting options.
|
||||
*/
|
||||
[key: string]: unknown;
|
||||
}
|
||||
interface InputLogObject {
|
||||
/**
|
||||
* The logging level of the message. See {@link LogLevel}.
|
||||
* @optional
|
||||
*/
|
||||
level?: LogLevel;
|
||||
/**
|
||||
* A string tag to categorise or identify the log message.
|
||||
* @optional
|
||||
*/
|
||||
tag?: string;
|
||||
/**
|
||||
* The type of log message, which affects how it's processed and displayed. See {@link LogType}.
|
||||
* @optional
|
||||
*/
|
||||
type?: LogType;
|
||||
/**
|
||||
* The main log message text.
|
||||
* @optional
|
||||
*/
|
||||
message?: string;
|
||||
/**
|
||||
* Additional text or texts to be logged with the message.
|
||||
* @optional
|
||||
*/
|
||||
additional?: string | string[];
|
||||
/**
|
||||
* Additional arguments to be logged with the message.
|
||||
* @optional
|
||||
*/
|
||||
args?: any[];
|
||||
/**
|
||||
* The date and time when the log message was created.
|
||||
* @optional
|
||||
*/
|
||||
date?: Date;
|
||||
}
|
||||
interface LogObject extends InputLogObject {
|
||||
/**
|
||||
* The logging level of the message, overridden if required. See {@link LogLevel}.
|
||||
*/
|
||||
level: LogLevel;
|
||||
/**
|
||||
* The type of log message, overridden if required. See {@link LogType}.
|
||||
*/
|
||||
type: LogType;
|
||||
/**
|
||||
* A string tag to categorise or identify the log message, overridden if necessary.
|
||||
*/
|
||||
tag: string;
|
||||
/**
|
||||
* Additional arguments to be logged with the message, overridden if necessary.
|
||||
*/
|
||||
args: any[];
|
||||
/**
|
||||
* The date and time the log message was created, overridden if necessary.
|
||||
*/
|
||||
date: Date;
|
||||
/**
|
||||
* Allows additional custom properties to be set on the log object.
|
||||
*/
|
||||
[key: string]: unknown;
|
||||
}
|
||||
interface ConsolaReporter {
|
||||
/**
|
||||
* Defines how a log message is processed and displayed by this reporter.
|
||||
* @param logObj The LogObject containing the log information to process. See {@link LogObject}.
|
||||
* @param ctx An object containing context information such as options. See {@link ConsolaOptions}.
|
||||
*/
|
||||
log: (logObj: LogObject, ctx: {
|
||||
options: ConsolaOptions;
|
||||
}) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consola class for logging management with support for pause/resume, mocking and customisable reporting.
|
||||
* Provides flexible logging capabilities including level-based logging, custom reporters and integration options.
|
||||
*
|
||||
* @class Consola
|
||||
*/
|
||||
declare class Consola {
|
||||
options: ConsolaOptions;
|
||||
_lastLog: {
|
||||
serialized?: string;
|
||||
object?: LogObject;
|
||||
count?: number;
|
||||
time?: Date;
|
||||
timeout?: ReturnType<typeof setTimeout>;
|
||||
};
|
||||
_mockFn?: ConsolaOptions["mockFn"];
|
||||
/**
|
||||
* Creates an instance of Consola with specified options or defaults.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} [options={}] - Configuration options for the Consola instance.
|
||||
*/
|
||||
constructor(options?: Partial<ConsolaOptions>);
|
||||
/**
|
||||
* Gets the current log level of the Consola instance.
|
||||
*
|
||||
* @returns {number} The current log level.
|
||||
*/
|
||||
get level(): LogLevel;
|
||||
/**
|
||||
* Sets the minimum log level that will be output by the instance.
|
||||
*
|
||||
* @param {number} level - The new log level to set.
|
||||
*/
|
||||
set level(level: LogLevel);
|
||||
/**
|
||||
* Displays a prompt to the user and returns the response.
|
||||
* Throw an error if `prompt` is not supported by the current configuration.
|
||||
*
|
||||
* @template T
|
||||
* @param {string} message - The message to display in the prompt.
|
||||
* @param {T} [opts] - Optional options for the prompt. See {@link PromptOptions}.
|
||||
* @returns {promise<T>} A promise that infer with the prompt options. See {@link PromptOptions}.
|
||||
*/
|
||||
prompt<T extends PromptOptions>(message: string, opts?: T): Promise<(T extends TextPromptOptions ? string : T extends ConfirmPromptOptions ? boolean : T extends SelectPromptOptions ? T["options"][number] extends {
|
||||
label: string;
|
||||
value: string;
|
||||
hint?: string;
|
||||
} ? T["options"][number]["value"] : T["options"][number] : T extends MultiSelectOptions ? T["options"] : unknown) | (T extends {
|
||||
cancel: "reject";
|
||||
} ? never : T extends {
|
||||
cancel: "default";
|
||||
} ? T extends infer T_1 ? T_1 extends T ? T_1 extends TextPromptOptions ? string : T_1 extends ConfirmPromptOptions ? boolean : T_1 extends SelectPromptOptions ? T_1["options"][number] extends {
|
||||
label: string;
|
||||
value: string;
|
||||
hint?: string;
|
||||
} ? T_1["options"][number]["value"] : T_1["options"][number] : T_1 extends MultiSelectOptions ? T_1["options"] : unknown : never : never : T extends {
|
||||
cancel: "undefined";
|
||||
} ? undefined : T extends {
|
||||
cancel: "null";
|
||||
} ? null : T extends {
|
||||
cancel: "symbol";
|
||||
} ? typeof kCancel : T extends TextPromptOptions ? string : T extends ConfirmPromptOptions ? boolean : T extends SelectPromptOptions ? T["options"][number] extends {
|
||||
label: string;
|
||||
value: string;
|
||||
hint?: string;
|
||||
} ? T["options"][number]["value"] : T["options"][number] : T extends MultiSelectOptions ? T["options"] : unknown)>;
|
||||
/**
|
||||
* Creates a new instance of Consola, inheriting options from the current instance, with possible overrides.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} options - Optional overrides for the new instance. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
create(options: Partial<ConsolaOptions>): ConsolaInstance;
|
||||
/**
|
||||
* Creates a new Consola instance with the specified default log object properties.
|
||||
*
|
||||
* @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
withDefaults(defaults: InputLogObject): ConsolaInstance;
|
||||
/**
|
||||
* Creates a new Consola instance with a specified tag, which will be included in every log.
|
||||
*
|
||||
* @param {string} tag - The tag to include in each log of the new instance.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
withTag(tag: string): ConsolaInstance;
|
||||
/**
|
||||
* Adds a custom reporter to the Consola instance.
|
||||
* Reporters will be called for each log message, depending on their implementation and log level.
|
||||
*
|
||||
* @param {ConsolaReporter} reporter - The reporter to add. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
addReporter(reporter: ConsolaReporter): this;
|
||||
/**
|
||||
* Removes a custom reporter from the Consola instance.
|
||||
* If no reporter is specified, all reporters will be removed.
|
||||
*
|
||||
* @param {ConsolaReporter} reporter - The reporter to remove. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
removeReporter(reporter: ConsolaReporter): ConsolaReporter[] | this;
|
||||
/**
|
||||
* Replaces all reporters of the Consola instance with the specified array of reporters.
|
||||
*
|
||||
* @param {ConsolaReporter[]} reporters - The new reporters to set. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
setReporters(reporters: ConsolaReporter[]): this;
|
||||
wrapAll(): void;
|
||||
restoreAll(): void;
|
||||
/**
|
||||
* Overrides console methods with Consola logging methods for consistent logging.
|
||||
*/
|
||||
wrapConsole(): void;
|
||||
/**
|
||||
* Restores the original console methods, removing Consola overrides.
|
||||
*/
|
||||
restoreConsole(): void;
|
||||
/**
|
||||
* Overrides standard output and error streams to redirect them through Consola.
|
||||
*/
|
||||
wrapStd(): void;
|
||||
_wrapStream(stream: NodeJS.WriteStream | undefined, type: LogType): void;
|
||||
/**
|
||||
* Restores the original standard output and error streams, removing the Consola redirection.
|
||||
*/
|
||||
restoreStd(): void;
|
||||
_restoreStream(stream?: NodeJS.WriteStream): void;
|
||||
/**
|
||||
* Pauses logging, queues incoming logs until resumed.
|
||||
*/
|
||||
pauseLogs(): void;
|
||||
/**
|
||||
* Resumes logging, processing any queued logs.
|
||||
*/
|
||||
resumeLogs(): void;
|
||||
/**
|
||||
* Replaces logging methods with mocks if a mock function is provided.
|
||||
*
|
||||
* @param {ConsolaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link ConsolaOptions["mockFn"]}.
|
||||
*/
|
||||
mockTypes(mockFn?: ConsolaOptions["mockFn"]): void;
|
||||
_wrapLogFn(defaults: InputLogObject, isRaw?: boolean): (...args: any[]) => false | undefined;
|
||||
_logFn(defaults: InputLogObject, args: any[], isRaw?: boolean): false | undefined;
|
||||
_log(logObj: LogObject): void;
|
||||
}
|
||||
interface LogFn {
|
||||
(message: InputLogObject | any, ...args: any[]): void;
|
||||
raw: (...args: any[]) => void;
|
||||
}
|
||||
type ConsolaInstance = Consola & Record<LogType, LogFn>;
|
||||
/**
|
||||
* Utility for creating a new Consola instance with optional configuration.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} [options={}] - Optional configuration options for the new Consola instance. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new instance of Consola. See {@link ConsolaInstance}.
|
||||
*/
|
||||
declare function createConsola(options?: Partial<ConsolaOptions>): ConsolaInstance;
|
||||
|
||||
export { type ConfirmPromptOptions, Consola, type ConsolaInstance, type ConsolaOptions, type ConsolaReporter, type FormatOptions, type InputLogObject, type LogLevel, LogLevels, type LogObject, type LogType, LogTypes, type MultiSelectOptions, type PromptOptions, type SelectPromptOptions, type TextPromptOptions, createConsola };
|
||||
459
node_modules/consola/dist/core.d.ts
generated
vendored
Normal file
459
node_modules/consola/dist/core.d.ts
generated
vendored
Normal file
@@ -0,0 +1,459 @@
|
||||
type SelectOption = {
|
||||
label: string;
|
||||
value: string;
|
||||
hint?: string;
|
||||
};
|
||||
declare const kCancel: unique symbol;
|
||||
type PromptCommonOptions = {
|
||||
/**
|
||||
* Specify how to handle a cancelled prompt (e.g. by pressing Ctrl+C).
|
||||
*
|
||||
* Default strategy is `"default"`.
|
||||
*
|
||||
* - `"default"` - Resolve the promise with the `default` value or `initial` value.
|
||||
* - `"undefined`" - Resolve the promise with `undefined`.
|
||||
* - `"null"` - Resolve the promise with `null`.
|
||||
* - `"symbol"` - Resolve the promise with a symbol `Symbol.for("cancel")`.
|
||||
* - `"reject"` - Reject the promise with an error.
|
||||
*/
|
||||
cancel?: "reject" | "default" | "undefined" | "null" | "symbol";
|
||||
};
|
||||
type TextPromptOptions = PromptCommonOptions & {
|
||||
/**
|
||||
* Specifies the prompt type as text.
|
||||
* @optional
|
||||
* @default "text"
|
||||
*/
|
||||
type?: "text";
|
||||
/**
|
||||
* The default text value.
|
||||
* @optional
|
||||
*/
|
||||
default?: string;
|
||||
/**
|
||||
* A placeholder text displayed in the prompt.
|
||||
* @optional
|
||||
*/
|
||||
placeholder?: string;
|
||||
/**
|
||||
* The initial text value.
|
||||
* @optional
|
||||
*/
|
||||
initial?: string;
|
||||
};
|
||||
type ConfirmPromptOptions = PromptCommonOptions & {
|
||||
/**
|
||||
* Specifies the prompt type as confirm.
|
||||
*/
|
||||
type: "confirm";
|
||||
/**
|
||||
* The initial value for the confirm prompt.
|
||||
* @optional
|
||||
*/
|
||||
initial?: boolean;
|
||||
};
|
||||
type SelectPromptOptions = PromptCommonOptions & {
|
||||
/**
|
||||
* Specifies the prompt type as select.
|
||||
*/
|
||||
type: "select";
|
||||
/**
|
||||
* The initial value for the select prompt.
|
||||
* @optional
|
||||
*/
|
||||
initial?: string;
|
||||
/**
|
||||
* The options to select from. See {@link SelectOption}.
|
||||
*/
|
||||
options: (string | SelectOption)[];
|
||||
};
|
||||
type MultiSelectOptions = PromptCommonOptions & {
|
||||
/**
|
||||
* Specifies the prompt type as multiselect.
|
||||
*/
|
||||
type: "multiselect";
|
||||
/**
|
||||
* The options to select from. See {@link SelectOption}.
|
||||
*/
|
||||
initial?: string[];
|
||||
/**
|
||||
* The options to select from. See {@link SelectOption}.
|
||||
*/
|
||||
options: (string | SelectOption)[];
|
||||
/**
|
||||
* Whether the prompt requires at least one selection.
|
||||
*/
|
||||
required?: boolean;
|
||||
};
|
||||
/**
|
||||
* Defines a combined type for all prompt options.
|
||||
*/
|
||||
type PromptOptions = TextPromptOptions | ConfirmPromptOptions | SelectPromptOptions | MultiSelectOptions;
|
||||
type inferPromptReturnType<T extends PromptOptions> = T extends TextPromptOptions ? string : T extends ConfirmPromptOptions ? boolean : T extends SelectPromptOptions ? T["options"][number] extends SelectOption ? T["options"][number]["value"] : T["options"][number] : T extends MultiSelectOptions ? T["options"] : unknown;
|
||||
type inferPromptCancalReturnType<T extends PromptOptions> = T extends {
|
||||
cancel: "reject";
|
||||
} ? never : T extends {
|
||||
cancel: "default";
|
||||
} ? inferPromptReturnType<T> : T extends {
|
||||
cancel: "undefined";
|
||||
} ? undefined : T extends {
|
||||
cancel: "null";
|
||||
} ? null : T extends {
|
||||
cancel: "symbol";
|
||||
} ? typeof kCancel : inferPromptReturnType<T>;
|
||||
/**
|
||||
* Asynchronously prompts the user for input based on specified options.
|
||||
* Supports text, confirm, select and multi-select prompts.
|
||||
*
|
||||
* @param {string} message - The message to display in the prompt.
|
||||
* @param {PromptOptions} [opts={}] - The prompt options. See {@link PromptOptions}.
|
||||
* @returns {Promise<inferPromptReturnType<T>>} - A promise that resolves with the user's response, the type of which is inferred from the options. See {@link inferPromptReturnType}.
|
||||
*/
|
||||
declare function prompt<_ = any, __ = any, T extends PromptOptions = TextPromptOptions>(message: string, opts?: PromptOptions): Promise<inferPromptReturnType<T> | inferPromptCancalReturnType<T>>;
|
||||
|
||||
/**
|
||||
* Defines the level of logs as specific numbers or special number types.
|
||||
*
|
||||
* @type {0 | 1 | 2 | 3 | 4 | 5 | (number & {})} LogLevel - Represents the log level.
|
||||
* @default 0 - Represents the default log level.
|
||||
*/
|
||||
type LogLevel = 0 | 1 | 2 | 3 | 4 | 5 | (number & {});
|
||||
/**
|
||||
* A mapping of `LogType` to its corresponding numeric log level.
|
||||
*
|
||||
* @type {Record<LogType, number>} LogLevels - key-value pairs of log types to their numeric levels. See {@link LogType}.
|
||||
*/
|
||||
declare const LogLevels: Record<LogType, number>;
|
||||
/**
|
||||
* Lists the types of log messages supported by the system.
|
||||
*
|
||||
* @type {"silent" | "fatal" | "error" | "warn" | "log" | "info" | "success" | "fail" | "ready" | "start" | "box" | "debug" | "trace" | "verbose"} LogType - Represents the specific type of log message.
|
||||
*/
|
||||
type LogType = "silent" | "fatal" | "error" | "warn" | "log" | "info" | "success" | "fail" | "ready" | "start" | "box" | "debug" | "trace" | "verbose";
|
||||
/**
|
||||
* Maps `LogType` to a `Partial<LogObject>`, primarily defining the log level.
|
||||
*
|
||||
* @type {Record<LogType, Partial<LogObject>>} LogTypes - key-value pairs of log types to partial log objects, specifying log levels. See {@link LogType} and {@link LogObject}.
|
||||
*/
|
||||
declare const LogTypes: Record<LogType, Partial<LogObject>>;
|
||||
|
||||
interface ConsolaOptions {
|
||||
/**
|
||||
* An array of ConsolaReporter instances used to handle and output log messages.
|
||||
*/
|
||||
reporters: ConsolaReporter[];
|
||||
/**
|
||||
* A record mapping LogType to InputLogObject, defining the log configuration for each log type.
|
||||
* See {@link LogType} and {@link InputLogObject}.
|
||||
*/
|
||||
types: Record<LogType, InputLogObject>;
|
||||
/**
|
||||
* The minimum log level to output. See {@link LogLevel}.
|
||||
*/
|
||||
level: LogLevel;
|
||||
/**
|
||||
* Default properties applied to all log messages unless overridden. See {@link InputLogObject}.
|
||||
*/
|
||||
defaults: InputLogObject;
|
||||
/**
|
||||
* The maximum number of times a log message can be repeated within a given timeframe.
|
||||
*/
|
||||
throttle: number;
|
||||
/**
|
||||
* The minimum time in milliseconds that must elapse before a throttled log message can be logged again.
|
||||
*/
|
||||
throttleMin: number;
|
||||
/**
|
||||
* The Node.js writable stream for standard output. See {@link NodeJS.WriteStream}.
|
||||
* @optional
|
||||
*/
|
||||
stdout?: NodeJS.WriteStream;
|
||||
/**
|
||||
* The Node.js writeable stream for standard error output. See {@link NodeJS.WriteStream}.
|
||||
* @optional
|
||||
*/
|
||||
stderr?: NodeJS.WriteStream;
|
||||
/**
|
||||
* A function that allows you to mock log messages for testing purposes.
|
||||
* @optional
|
||||
*/
|
||||
mockFn?: (type: LogType, defaults: InputLogObject) => (...args: any) => void;
|
||||
/**
|
||||
* Custom prompt function to use. It can be undefined.
|
||||
* @optional
|
||||
*/
|
||||
prompt?: typeof prompt | undefined;
|
||||
/**
|
||||
* Configuration options for formatting log messages. See {@link FormatOptions}.
|
||||
*/
|
||||
formatOptions: FormatOptions;
|
||||
}
|
||||
/**
|
||||
* @see https://nodejs.org/api/util.html#util_util_inspect_object_showhidden_depth_colors
|
||||
*/
|
||||
interface FormatOptions {
|
||||
/**
|
||||
* The maximum number of columns to output, affects formatting.
|
||||
* @optional
|
||||
*/
|
||||
columns?: number;
|
||||
/**
|
||||
* Whether to include timestamp information in log messages.
|
||||
* @optional
|
||||
*/
|
||||
date?: boolean;
|
||||
/**
|
||||
* Whether to use colors in the output.
|
||||
* @optional
|
||||
*/
|
||||
colors?: boolean;
|
||||
/**
|
||||
* Specifies whether or not the output should be compact. Accepts a boolean or numeric level of compactness.
|
||||
* @optional
|
||||
*/
|
||||
compact?: boolean | number;
|
||||
/**
|
||||
* Error cause level.
|
||||
*/
|
||||
errorLevel?: number;
|
||||
/**
|
||||
* Allows additional custom formatting options.
|
||||
*/
|
||||
[key: string]: unknown;
|
||||
}
|
||||
interface InputLogObject {
|
||||
/**
|
||||
* The logging level of the message. See {@link LogLevel}.
|
||||
* @optional
|
||||
*/
|
||||
level?: LogLevel;
|
||||
/**
|
||||
* A string tag to categorise or identify the log message.
|
||||
* @optional
|
||||
*/
|
||||
tag?: string;
|
||||
/**
|
||||
* The type of log message, which affects how it's processed and displayed. See {@link LogType}.
|
||||
* @optional
|
||||
*/
|
||||
type?: LogType;
|
||||
/**
|
||||
* The main log message text.
|
||||
* @optional
|
||||
*/
|
||||
message?: string;
|
||||
/**
|
||||
* Additional text or texts to be logged with the message.
|
||||
* @optional
|
||||
*/
|
||||
additional?: string | string[];
|
||||
/**
|
||||
* Additional arguments to be logged with the message.
|
||||
* @optional
|
||||
*/
|
||||
args?: any[];
|
||||
/**
|
||||
* The date and time when the log message was created.
|
||||
* @optional
|
||||
*/
|
||||
date?: Date;
|
||||
}
|
||||
interface LogObject extends InputLogObject {
|
||||
/**
|
||||
* The logging level of the message, overridden if required. See {@link LogLevel}.
|
||||
*/
|
||||
level: LogLevel;
|
||||
/**
|
||||
* The type of log message, overridden if required. See {@link LogType}.
|
||||
*/
|
||||
type: LogType;
|
||||
/**
|
||||
* A string tag to categorise or identify the log message, overridden if necessary.
|
||||
*/
|
||||
tag: string;
|
||||
/**
|
||||
* Additional arguments to be logged with the message, overridden if necessary.
|
||||
*/
|
||||
args: any[];
|
||||
/**
|
||||
* The date and time the log message was created, overridden if necessary.
|
||||
*/
|
||||
date: Date;
|
||||
/**
|
||||
* Allows additional custom properties to be set on the log object.
|
||||
*/
|
||||
[key: string]: unknown;
|
||||
}
|
||||
interface ConsolaReporter {
|
||||
/**
|
||||
* Defines how a log message is processed and displayed by this reporter.
|
||||
* @param logObj The LogObject containing the log information to process. See {@link LogObject}.
|
||||
* @param ctx An object containing context information such as options. See {@link ConsolaOptions}.
|
||||
*/
|
||||
log: (logObj: LogObject, ctx: {
|
||||
options: ConsolaOptions;
|
||||
}) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consola class for logging management with support for pause/resume, mocking and customisable reporting.
|
||||
* Provides flexible logging capabilities including level-based logging, custom reporters and integration options.
|
||||
*
|
||||
* @class Consola
|
||||
*/
|
||||
declare class Consola {
|
||||
options: ConsolaOptions;
|
||||
_lastLog: {
|
||||
serialized?: string;
|
||||
object?: LogObject;
|
||||
count?: number;
|
||||
time?: Date;
|
||||
timeout?: ReturnType<typeof setTimeout>;
|
||||
};
|
||||
_mockFn?: ConsolaOptions["mockFn"];
|
||||
/**
|
||||
* Creates an instance of Consola with specified options or defaults.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} [options={}] - Configuration options for the Consola instance.
|
||||
*/
|
||||
constructor(options?: Partial<ConsolaOptions>);
|
||||
/**
|
||||
* Gets the current log level of the Consola instance.
|
||||
*
|
||||
* @returns {number} The current log level.
|
||||
*/
|
||||
get level(): LogLevel;
|
||||
/**
|
||||
* Sets the minimum log level that will be output by the instance.
|
||||
*
|
||||
* @param {number} level - The new log level to set.
|
||||
*/
|
||||
set level(level: LogLevel);
|
||||
/**
|
||||
* Displays a prompt to the user and returns the response.
|
||||
* Throw an error if `prompt` is not supported by the current configuration.
|
||||
*
|
||||
* @template T
|
||||
* @param {string} message - The message to display in the prompt.
|
||||
* @param {T} [opts] - Optional options for the prompt. See {@link PromptOptions}.
|
||||
* @returns {promise<T>} A promise that infer with the prompt options. See {@link PromptOptions}.
|
||||
*/
|
||||
prompt<T extends PromptOptions>(message: string, opts?: T): Promise<(T extends TextPromptOptions ? string : T extends ConfirmPromptOptions ? boolean : T extends SelectPromptOptions ? T["options"][number] extends {
|
||||
label: string;
|
||||
value: string;
|
||||
hint?: string;
|
||||
} ? T["options"][number]["value"] : T["options"][number] : T extends MultiSelectOptions ? T["options"] : unknown) | (T extends {
|
||||
cancel: "reject";
|
||||
} ? never : T extends {
|
||||
cancel: "default";
|
||||
} ? T extends infer T_1 ? T_1 extends T ? T_1 extends TextPromptOptions ? string : T_1 extends ConfirmPromptOptions ? boolean : T_1 extends SelectPromptOptions ? T_1["options"][number] extends {
|
||||
label: string;
|
||||
value: string;
|
||||
hint?: string;
|
||||
} ? T_1["options"][number]["value"] : T_1["options"][number] : T_1 extends MultiSelectOptions ? T_1["options"] : unknown : never : never : T extends {
|
||||
cancel: "undefined";
|
||||
} ? undefined : T extends {
|
||||
cancel: "null";
|
||||
} ? null : T extends {
|
||||
cancel: "symbol";
|
||||
} ? typeof kCancel : T extends TextPromptOptions ? string : T extends ConfirmPromptOptions ? boolean : T extends SelectPromptOptions ? T["options"][number] extends {
|
||||
label: string;
|
||||
value: string;
|
||||
hint?: string;
|
||||
} ? T["options"][number]["value"] : T["options"][number] : T extends MultiSelectOptions ? T["options"] : unknown)>;
|
||||
/**
|
||||
* Creates a new instance of Consola, inheriting options from the current instance, with possible overrides.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} options - Optional overrides for the new instance. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
create(options: Partial<ConsolaOptions>): ConsolaInstance;
|
||||
/**
|
||||
* Creates a new Consola instance with the specified default log object properties.
|
||||
*
|
||||
* @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
withDefaults(defaults: InputLogObject): ConsolaInstance;
|
||||
/**
|
||||
* Creates a new Consola instance with a specified tag, which will be included in every log.
|
||||
*
|
||||
* @param {string} tag - The tag to include in each log of the new instance.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
withTag(tag: string): ConsolaInstance;
|
||||
/**
|
||||
* Adds a custom reporter to the Consola instance.
|
||||
* Reporters will be called for each log message, depending on their implementation and log level.
|
||||
*
|
||||
* @param {ConsolaReporter} reporter - The reporter to add. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
addReporter(reporter: ConsolaReporter): this;
|
||||
/**
|
||||
* Removes a custom reporter from the Consola instance.
|
||||
* If no reporter is specified, all reporters will be removed.
|
||||
*
|
||||
* @param {ConsolaReporter} reporter - The reporter to remove. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
removeReporter(reporter: ConsolaReporter): ConsolaReporter[] | this;
|
||||
/**
|
||||
* Replaces all reporters of the Consola instance with the specified array of reporters.
|
||||
*
|
||||
* @param {ConsolaReporter[]} reporters - The new reporters to set. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
setReporters(reporters: ConsolaReporter[]): this;
|
||||
wrapAll(): void;
|
||||
restoreAll(): void;
|
||||
/**
|
||||
* Overrides console methods with Consola logging methods for consistent logging.
|
||||
*/
|
||||
wrapConsole(): void;
|
||||
/**
|
||||
* Restores the original console methods, removing Consola overrides.
|
||||
*/
|
||||
restoreConsole(): void;
|
||||
/**
|
||||
* Overrides standard output and error streams to redirect them through Consola.
|
||||
*/
|
||||
wrapStd(): void;
|
||||
_wrapStream(stream: NodeJS.WriteStream | undefined, type: LogType): void;
|
||||
/**
|
||||
* Restores the original standard output and error streams, removing the Consola redirection.
|
||||
*/
|
||||
restoreStd(): void;
|
||||
_restoreStream(stream?: NodeJS.WriteStream): void;
|
||||
/**
|
||||
* Pauses logging, queues incoming logs until resumed.
|
||||
*/
|
||||
pauseLogs(): void;
|
||||
/**
|
||||
* Resumes logging, processing any queued logs.
|
||||
*/
|
||||
resumeLogs(): void;
|
||||
/**
|
||||
* Replaces logging methods with mocks if a mock function is provided.
|
||||
*
|
||||
* @param {ConsolaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link ConsolaOptions["mockFn"]}.
|
||||
*/
|
||||
mockTypes(mockFn?: ConsolaOptions["mockFn"]): void;
|
||||
_wrapLogFn(defaults: InputLogObject, isRaw?: boolean): (...args: any[]) => false | undefined;
|
||||
_logFn(defaults: InputLogObject, args: any[], isRaw?: boolean): false | undefined;
|
||||
_log(logObj: LogObject): void;
|
||||
}
|
||||
interface LogFn {
|
||||
(message: InputLogObject | any, ...args: any[]): void;
|
||||
raw: (...args: any[]) => void;
|
||||
}
|
||||
type ConsolaInstance = Consola & Record<LogType, LogFn>;
|
||||
/**
|
||||
* Utility for creating a new Consola instance with optional configuration.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} [options={}] - Optional configuration options for the new Consola instance. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new instance of Consola. See {@link ConsolaInstance}.
|
||||
*/
|
||||
declare function createConsola(options?: Partial<ConsolaOptions>): ConsolaInstance;
|
||||
|
||||
export { type ConfirmPromptOptions, Consola, type ConsolaInstance, type ConsolaOptions, type ConsolaReporter, type FormatOptions, type InputLogObject, type LogLevel, LogLevels, type LogObject, type LogType, LogTypes, type MultiSelectOptions, type PromptOptions, type SelectPromptOptions, type TextPromptOptions, createConsola };
|
||||
512
node_modules/consola/dist/core.mjs
generated
vendored
Normal file
512
node_modules/consola/dist/core.mjs
generated
vendored
Normal file
@@ -0,0 +1,512 @@
|
||||
const LogLevels = {
|
||||
silent: Number.NEGATIVE_INFINITY,
|
||||
fatal: 0,
|
||||
error: 0,
|
||||
warn: 1,
|
||||
log: 2,
|
||||
info: 3,
|
||||
success: 3,
|
||||
fail: 3,
|
||||
ready: 3,
|
||||
start: 3,
|
||||
box: 3,
|
||||
debug: 4,
|
||||
trace: 5,
|
||||
verbose: Number.POSITIVE_INFINITY
|
||||
};
|
||||
const LogTypes = {
|
||||
// Silent
|
||||
silent: {
|
||||
level: -1
|
||||
},
|
||||
// Level 0
|
||||
fatal: {
|
||||
level: LogLevels.fatal
|
||||
},
|
||||
error: {
|
||||
level: LogLevels.error
|
||||
},
|
||||
// Level 1
|
||||
warn: {
|
||||
level: LogLevels.warn
|
||||
},
|
||||
// Level 2
|
||||
log: {
|
||||
level: LogLevels.log
|
||||
},
|
||||
// Level 3
|
||||
info: {
|
||||
level: LogLevels.info
|
||||
},
|
||||
success: {
|
||||
level: LogLevels.success
|
||||
},
|
||||
fail: {
|
||||
level: LogLevels.fail
|
||||
},
|
||||
ready: {
|
||||
level: LogLevels.info
|
||||
},
|
||||
start: {
|
||||
level: LogLevels.info
|
||||
},
|
||||
box: {
|
||||
level: LogLevels.info
|
||||
},
|
||||
// Level 4
|
||||
debug: {
|
||||
level: LogLevels.debug
|
||||
},
|
||||
// Level 5
|
||||
trace: {
|
||||
level: LogLevels.trace
|
||||
},
|
||||
// Verbose
|
||||
verbose: {
|
||||
level: LogLevels.verbose
|
||||
}
|
||||
};
|
||||
|
||||
function isPlainObject$1(value) {
|
||||
if (value === null || typeof value !== "object") {
|
||||
return false;
|
||||
}
|
||||
const prototype = Object.getPrototypeOf(value);
|
||||
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
||||
return false;
|
||||
}
|
||||
if (Symbol.iterator in value) {
|
||||
return false;
|
||||
}
|
||||
if (Symbol.toStringTag in value) {
|
||||
return Object.prototype.toString.call(value) === "[object Module]";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function _defu(baseObject, defaults, namespace = ".", merger) {
|
||||
if (!isPlainObject$1(defaults)) {
|
||||
return _defu(baseObject, {}, namespace, merger);
|
||||
}
|
||||
const object = Object.assign({}, defaults);
|
||||
for (const key in baseObject) {
|
||||
if (key === "__proto__" || key === "constructor") {
|
||||
continue;
|
||||
}
|
||||
const value = baseObject[key];
|
||||
if (value === null || value === void 0) {
|
||||
continue;
|
||||
}
|
||||
if (merger && merger(object, key, value, namespace)) {
|
||||
continue;
|
||||
}
|
||||
if (Array.isArray(value) && Array.isArray(object[key])) {
|
||||
object[key] = [...value, ...object[key]];
|
||||
} else if (isPlainObject$1(value) && isPlainObject$1(object[key])) {
|
||||
object[key] = _defu(
|
||||
value,
|
||||
object[key],
|
||||
(namespace ? `${namespace}.` : "") + key.toString(),
|
||||
merger
|
||||
);
|
||||
} else {
|
||||
object[key] = value;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
function createDefu(merger) {
|
||||
return (...arguments_) => (
|
||||
// eslint-disable-next-line unicorn/no-array-reduce
|
||||
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
||||
);
|
||||
}
|
||||
const defu = createDefu();
|
||||
|
||||
function isPlainObject(obj) {
|
||||
return Object.prototype.toString.call(obj) === "[object Object]";
|
||||
}
|
||||
function isLogObj(arg) {
|
||||
if (!isPlainObject(arg)) {
|
||||
return false;
|
||||
}
|
||||
if (!arg.message && !arg.args) {
|
||||
return false;
|
||||
}
|
||||
if (arg.stack) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
let paused = false;
|
||||
const queue = [];
|
||||
class Consola {
|
||||
options;
|
||||
_lastLog;
|
||||
_mockFn;
|
||||
/**
|
||||
* Creates an instance of Consola with specified options or defaults.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} [options={}] - Configuration options for the Consola instance.
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
const types = options.types || LogTypes;
|
||||
this.options = defu(
|
||||
{
|
||||
...options,
|
||||
defaults: { ...options.defaults },
|
||||
level: _normalizeLogLevel(options.level, types),
|
||||
reporters: [...options.reporters || []]
|
||||
},
|
||||
{
|
||||
types: LogTypes,
|
||||
throttle: 1e3,
|
||||
throttleMin: 5,
|
||||
formatOptions: {
|
||||
date: true,
|
||||
colors: false,
|
||||
compact: true
|
||||
}
|
||||
}
|
||||
);
|
||||
for (const type in types) {
|
||||
const defaults = {
|
||||
type,
|
||||
...this.options.defaults,
|
||||
...types[type]
|
||||
};
|
||||
this[type] = this._wrapLogFn(defaults);
|
||||
this[type].raw = this._wrapLogFn(
|
||||
defaults,
|
||||
true
|
||||
);
|
||||
}
|
||||
if (this.options.mockFn) {
|
||||
this.mockTypes();
|
||||
}
|
||||
this._lastLog = {};
|
||||
}
|
||||
/**
|
||||
* Gets the current log level of the Consola instance.
|
||||
*
|
||||
* @returns {number} The current log level.
|
||||
*/
|
||||
get level() {
|
||||
return this.options.level;
|
||||
}
|
||||
/**
|
||||
* Sets the minimum log level that will be output by the instance.
|
||||
*
|
||||
* @param {number} level - The new log level to set.
|
||||
*/
|
||||
set level(level) {
|
||||
this.options.level = _normalizeLogLevel(
|
||||
level,
|
||||
this.options.types,
|
||||
this.options.level
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Displays a prompt to the user and returns the response.
|
||||
* Throw an error if `prompt` is not supported by the current configuration.
|
||||
*
|
||||
* @template T
|
||||
* @param {string} message - The message to display in the prompt.
|
||||
* @param {T} [opts] - Optional options for the prompt. See {@link PromptOptions}.
|
||||
* @returns {promise<T>} A promise that infer with the prompt options. See {@link PromptOptions}.
|
||||
*/
|
||||
prompt(message, opts) {
|
||||
if (!this.options.prompt) {
|
||||
throw new Error("prompt is not supported!");
|
||||
}
|
||||
return this.options.prompt(message, opts);
|
||||
}
|
||||
/**
|
||||
* Creates a new instance of Consola, inheriting options from the current instance, with possible overrides.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions>} options - Optional overrides for the new instance. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
create(options) {
|
||||
const instance = new Consola({
|
||||
...this.options,
|
||||
...options
|
||||
});
|
||||
if (this._mockFn) {
|
||||
instance.mockTypes(this._mockFn);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
/**
|
||||
* Creates a new Consola instance with the specified default log object properties.
|
||||
*
|
||||
* @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
withDefaults(defaults) {
|
||||
return this.create({
|
||||
...this.options,
|
||||
defaults: {
|
||||
...this.options.defaults,
|
||||
...defaults
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Creates a new Consola instance with a specified tag, which will be included in every log.
|
||||
*
|
||||
* @param {string} tag - The tag to include in each log of the new instance.
|
||||
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
||||
*/
|
||||
withTag(tag) {
|
||||
return this.withDefaults({
|
||||
tag: this.options.defaults.tag ? this.options.defaults.tag + ":" + tag : tag
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds a custom reporter to the Consola instance.
|
||||
* Reporters will be called for each log message, depending on their implementation and log level.
|
||||
*
|
||||
* @param {ConsolaReporter} reporter - The reporter to add. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
addReporter(reporter) {
|
||||
this.options.reporters.push(reporter);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Removes a custom reporter from the Consola instance.
|
||||
* If no reporter is specified, all reporters will be removed.
|
||||
*
|
||||
* @param {ConsolaReporter} reporter - The reporter to remove. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
removeReporter(reporter) {
|
||||
if (reporter) {
|
||||
const i = this.options.reporters.indexOf(reporter);
|
||||
if (i !== -1) {
|
||||
return this.options.reporters.splice(i, 1);
|
||||
}
|
||||
} else {
|
||||
this.options.reporters.splice(0);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Replaces all reporters of the Consola instance with the specified array of reporters.
|
||||
*
|
||||
* @param {ConsolaReporter[]} reporters - The new reporters to set. See {@link ConsolaReporter}.
|
||||
* @returns {Consola} The current Consola instance.
|
||||
*/
|
||||
setReporters(reporters) {
|
||||
this.options.reporters = Array.isArray(reporters) ? reporters : [reporters];
|
||||
return this;
|
||||
}
|
||||
wrapAll() {
|
||||
this.wrapConsole();
|
||||
this.wrapStd();
|
||||
}
|
||||
restoreAll() {
|
||||
this.restoreConsole();
|
||||
this.restoreStd();
|
||||
}
|
||||
/**
|
||||
* Overrides console methods with Consola logging methods for consistent logging.
|
||||
*/
|
||||
wrapConsole() {
|
||||
for (const type in this.options.types) {
|
||||
if (!console["__" + type]) {
|
||||
console["__" + type] = console[type];
|
||||
}
|
||||
console[type] = this[type].raw;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Restores the original console methods, removing Consola overrides.
|
||||
*/
|
||||
restoreConsole() {
|
||||
for (const type in this.options.types) {
|
||||
if (console["__" + type]) {
|
||||
console[type] = console["__" + type];
|
||||
delete console["__" + type];
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Overrides standard output and error streams to redirect them through Consola.
|
||||
*/
|
||||
wrapStd() {
|
||||
this._wrapStream(this.options.stdout, "log");
|
||||
this._wrapStream(this.options.stderr, "log");
|
||||
}
|
||||
_wrapStream(stream, type) {
|
||||
if (!stream) {
|
||||
return;
|
||||
}
|
||||
if (!stream.__write) {
|
||||
stream.__write = stream.write;
|
||||
}
|
||||
stream.write = (data) => {
|
||||
this[type].raw(String(data).trim());
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Restores the original standard output and error streams, removing the Consola redirection.
|
||||
*/
|
||||
restoreStd() {
|
||||
this._restoreStream(this.options.stdout);
|
||||
this._restoreStream(this.options.stderr);
|
||||
}
|
||||
_restoreStream(stream) {
|
||||
if (!stream) {
|
||||
return;
|
||||
}
|
||||
if (stream.__write) {
|
||||
stream.write = stream.__write;
|
||||
delete stream.__write;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Pauses logging, queues incoming logs until resumed.
|
||||
*/
|
||||
pauseLogs() {
|
||||
paused = true;
|
||||
}
|
||||
/**
|
||||
* Resumes logging, processing any queued logs.
|
||||
*/
|
||||
resumeLogs() {
|
||||
paused = false;
|
||||
const _queue = queue.splice(0);
|
||||
for (const item of _queue) {
|
||||
item[0]._logFn(item[1], item[2]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Replaces logging methods with mocks if a mock function is provided.
|
||||
*
|
||||
* @param {ConsolaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link ConsolaOptions["mockFn"]}.
|
||||
*/
|
||||
mockTypes(mockFn) {
|
||||
const _mockFn = mockFn || this.options.mockFn;
|
||||
this._mockFn = _mockFn;
|
||||
if (typeof _mockFn !== "function") {
|
||||
return;
|
||||
}
|
||||
for (const type in this.options.types) {
|
||||
this[type] = _mockFn(type, this.options.types[type]) || this[type];
|
||||
this[type].raw = this[type];
|
||||
}
|
||||
}
|
||||
_wrapLogFn(defaults, isRaw) {
|
||||
return (...args) => {
|
||||
if (paused) {
|
||||
queue.push([this, defaults, args, isRaw]);
|
||||
return;
|
||||
}
|
||||
return this._logFn(defaults, args, isRaw);
|
||||
};
|
||||
}
|
||||
_logFn(defaults, args, isRaw) {
|
||||
if ((defaults.level || 0) > this.level) {
|
||||
return false;
|
||||
}
|
||||
const logObj = {
|
||||
date: /* @__PURE__ */ new Date(),
|
||||
args: [],
|
||||
...defaults,
|
||||
level: _normalizeLogLevel(defaults.level, this.options.types)
|
||||
};
|
||||
if (!isRaw && args.length === 1 && isLogObj(args[0])) {
|
||||
Object.assign(logObj, args[0]);
|
||||
} else {
|
||||
logObj.args = [...args];
|
||||
}
|
||||
if (logObj.message) {
|
||||
logObj.args.unshift(logObj.message);
|
||||
delete logObj.message;
|
||||
}
|
||||
if (logObj.additional) {
|
||||
if (!Array.isArray(logObj.additional)) {
|
||||
logObj.additional = logObj.additional.split("\n");
|
||||
}
|
||||
logObj.args.push("\n" + logObj.additional.join("\n"));
|
||||
delete logObj.additional;
|
||||
}
|
||||
logObj.type = typeof logObj.type === "string" ? logObj.type.toLowerCase() : "log";
|
||||
logObj.tag = typeof logObj.tag === "string" ? logObj.tag : "";
|
||||
const resolveLog = (newLog = false) => {
|
||||
const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
|
||||
if (this._lastLog.object && repeated > 0) {
|
||||
const args2 = [...this._lastLog.object.args];
|
||||
if (repeated > 1) {
|
||||
args2.push(`(repeated ${repeated} times)`);
|
||||
}
|
||||
this._log({ ...this._lastLog.object, args: args2 });
|
||||
this._lastLog.count = 1;
|
||||
}
|
||||
if (newLog) {
|
||||
this._lastLog.object = logObj;
|
||||
this._log(logObj);
|
||||
}
|
||||
};
|
||||
clearTimeout(this._lastLog.timeout);
|
||||
const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
|
||||
this._lastLog.time = logObj.date;
|
||||
if (diffTime < this.options.throttle) {
|
||||
try {
|
||||
const serializedLog = JSON.stringify([
|
||||
logObj.type,
|
||||
logObj.tag,
|
||||
logObj.args
|
||||
]);
|
||||
const isSameLog = this._lastLog.serialized === serializedLog;
|
||||
this._lastLog.serialized = serializedLog;
|
||||
if (isSameLog) {
|
||||
this._lastLog.count = (this._lastLog.count || 0) + 1;
|
||||
if (this._lastLog.count > this.options.throttleMin) {
|
||||
this._lastLog.timeout = setTimeout(
|
||||
resolveLog,
|
||||
this.options.throttle
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
resolveLog(true);
|
||||
}
|
||||
_log(logObj) {
|
||||
for (const reporter of this.options.reporters) {
|
||||
reporter.log(logObj, {
|
||||
options: this.options
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
function _normalizeLogLevel(input, types = {}, defaultLevel = 3) {
|
||||
if (input === void 0) {
|
||||
return defaultLevel;
|
||||
}
|
||||
if (typeof input === "number") {
|
||||
return input;
|
||||
}
|
||||
if (types[input] && types[input].level !== void 0) {
|
||||
return types[input].level;
|
||||
}
|
||||
return defaultLevel;
|
||||
}
|
||||
Consola.prototype.add = Consola.prototype.addReporter;
|
||||
Consola.prototype.remove = Consola.prototype.removeReporter;
|
||||
Consola.prototype.clear = Consola.prototype.removeReporter;
|
||||
Consola.prototype.withScope = Consola.prototype.withTag;
|
||||
Consola.prototype.mock = Consola.prototype.mockTypes;
|
||||
Consola.prototype.pause = Consola.prototype.pauseLogs;
|
||||
Consola.prototype.resume = Consola.prototype.resumeLogs;
|
||||
function createConsola(options = {}) {
|
||||
return new Consola(options);
|
||||
}
|
||||
|
||||
export { Consola, LogLevels, LogTypes, createConsola };
|
||||
663
node_modules/consola/dist/index.cjs
generated
vendored
Normal file
663
node_modules/consola/dist/index.cjs
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
24
node_modules/consola/dist/index.d.cts
generated
vendored
Normal file
24
node_modules/consola/dist/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { ConsolaInstance, ConsolaOptions } from './core.cjs';
|
||||
export { ConfirmPromptOptions, Consola, ConsolaReporter, FormatOptions, InputLogObject, LogLevel, LogLevels, LogObject, LogType, LogTypes, MultiSelectOptions, PromptOptions, SelectPromptOptions, TextPromptOptions } from './core.cjs';
|
||||
|
||||
/**
|
||||
* Factory function to create a new Consola instance tailored for use in different environments.
|
||||
* It automatically adjusts logging levels based on environment variables and execution context.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions & { fancy: boolean }>} [options={}] - Optional configuration options. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new Consola instance with configurations based on the given options and the execution environment.
|
||||
*/
|
||||
declare function createConsola(options?: Partial<ConsolaOptions & {
|
||||
fancy: boolean;
|
||||
}>): ConsolaInstance;
|
||||
/**
|
||||
* A default instance of Consola, created and configured for immediate use.
|
||||
* This instance is configured based on the execution environment and the options provided.
|
||||
*
|
||||
* @type {ConsolaInstance} consola - The default Consola instance, ready to use.
|
||||
*/
|
||||
declare const consola: ConsolaInstance;
|
||||
|
||||
// @ts-ignore
|
||||
export = consola;
|
||||
export { ConsolaInstance, ConsolaOptions, consola, createConsola };
|
||||
22
node_modules/consola/dist/index.d.mts
generated
vendored
Normal file
22
node_modules/consola/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { ConsolaInstance, ConsolaOptions } from './core.mjs';
|
||||
export { ConfirmPromptOptions, Consola, ConsolaReporter, FormatOptions, InputLogObject, LogLevel, LogLevels, LogObject, LogType, LogTypes, MultiSelectOptions, PromptOptions, SelectPromptOptions, TextPromptOptions } from './core.mjs';
|
||||
|
||||
/**
|
||||
* Factory function to create a new Consola instance tailored for use in different environments.
|
||||
* It automatically adjusts logging levels based on environment variables and execution context.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions & { fancy: boolean }>} [options={}] - Optional configuration options. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new Consola instance with configurations based on the given options and the execution environment.
|
||||
*/
|
||||
declare function createConsola(options?: Partial<ConsolaOptions & {
|
||||
fancy: boolean;
|
||||
}>): ConsolaInstance;
|
||||
/**
|
||||
* A default instance of Consola, created and configured for immediate use.
|
||||
* This instance is configured based on the execution environment and the options provided.
|
||||
*
|
||||
* @type {ConsolaInstance} consola - The default Consola instance, ready to use.
|
||||
*/
|
||||
declare const consola: ConsolaInstance;
|
||||
|
||||
export { ConsolaInstance, ConsolaOptions, consola, createConsola, consola as default };
|
||||
24
node_modules/consola/dist/index.d.ts
generated
vendored
Normal file
24
node_modules/consola/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { ConsolaInstance, ConsolaOptions } from './core.js';
|
||||
export { ConfirmPromptOptions, Consola, ConsolaReporter, FormatOptions, InputLogObject, LogLevel, LogLevels, LogObject, LogType, LogTypes, MultiSelectOptions, PromptOptions, SelectPromptOptions, TextPromptOptions } from './core.js';
|
||||
|
||||
/**
|
||||
* Factory function to create a new Consola instance tailored for use in different environments.
|
||||
* It automatically adjusts logging levels based on environment variables and execution context.
|
||||
*
|
||||
* @param {Partial<ConsolaOptions & { fancy: boolean }>} [options={}] - Optional configuration options. See {@link ConsolaOptions}.
|
||||
* @returns {ConsolaInstance} A new Consola instance with configurations based on the given options and the execution environment.
|
||||
*/
|
||||
declare function createConsola(options?: Partial<ConsolaOptions & {
|
||||
fancy: boolean;
|
||||
}>): ConsolaInstance;
|
||||
/**
|
||||
* A default instance of Consola, created and configured for immediate use.
|
||||
* This instance is configured based on the execution environment and the options provided.
|
||||
*
|
||||
* @type {ConsolaInstance} consola - The default Consola instance, ready to use.
|
||||
*/
|
||||
declare const consola: ConsolaInstance;
|
||||
|
||||
// @ts-ignore
|
||||
export = consola;
|
||||
export { ConsolaInstance, ConsolaOptions, consola, createConsola };
|
||||
651
node_modules/consola/dist/index.mjs
generated
vendored
Normal file
651
node_modules/consola/dist/index.mjs
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
75
node_modules/consola/dist/shared/consola.DCGIlDNP.cjs
generated
vendored
Normal file
75
node_modules/consola/dist/shared/consola.DCGIlDNP.cjs
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
const node_util = require('node:util');
|
||||
const node_path = require('node:path');
|
||||
|
||||
function parseStack(stack, message) {
|
||||
const cwd = process.cwd() + node_path.sep;
|
||||
const lines = stack.split("\n").splice(message.split("\n").length).map((l) => l.trim().replace("file://", "").replace(cwd, ""));
|
||||
return lines;
|
||||
}
|
||||
|
||||
function writeStream(data, stream) {
|
||||
const write = stream.__write || stream.write;
|
||||
return write.call(stream, data);
|
||||
}
|
||||
|
||||
const bracket = (x) => x ? `[${x}]` : "";
|
||||
class BasicReporter {
|
||||
formatStack(stack, message, opts) {
|
||||
const indent = " ".repeat((opts?.errorLevel || 0) + 1);
|
||||
return indent + parseStack(stack, message).join(`
|
||||
${indent}`);
|
||||
}
|
||||
formatError(err, opts) {
|
||||
const message = err.message ?? node_util.formatWithOptions(opts, err);
|
||||
const stack = err.stack ? this.formatStack(err.stack, message, opts) : "";
|
||||
const level = opts?.errorLevel || 0;
|
||||
const causedPrefix = level > 0 ? `${" ".repeat(level)}[cause]: ` : "";
|
||||
const causedError = err.cause ? "\n\n" + this.formatError(err.cause, { ...opts, errorLevel: level + 1 }) : "";
|
||||
return causedPrefix + message + "\n" + stack + causedError;
|
||||
}
|
||||
formatArgs(args, opts) {
|
||||
const _args = args.map((arg) => {
|
||||
if (arg && typeof arg.stack === "string") {
|
||||
return this.formatError(arg, opts);
|
||||
}
|
||||
return arg;
|
||||
});
|
||||
return node_util.formatWithOptions(opts, ..._args);
|
||||
}
|
||||
formatDate(date, opts) {
|
||||
return opts.date ? date.toLocaleTimeString() : "";
|
||||
}
|
||||
filterAndJoin(arr) {
|
||||
return arr.filter(Boolean).join(" ");
|
||||
}
|
||||
formatLogObj(logObj, opts) {
|
||||
const message = this.formatArgs(logObj.args, opts);
|
||||
if (logObj.type === "box") {
|
||||
return "\n" + [
|
||||
bracket(logObj.tag),
|
||||
logObj.title && logObj.title,
|
||||
...message.split("\n")
|
||||
].filter(Boolean).map((l) => " > " + l).join("\n") + "\n";
|
||||
}
|
||||
return this.filterAndJoin([
|
||||
bracket(logObj.type),
|
||||
bracket(logObj.tag),
|
||||
message
|
||||
]);
|
||||
}
|
||||
log(logObj, ctx) {
|
||||
const line = this.formatLogObj(logObj, {
|
||||
columns: ctx.options.stdout.columns || 0,
|
||||
...ctx.options.formatOptions
|
||||
});
|
||||
return writeStream(
|
||||
line + "\n",
|
||||
logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
exports.BasicReporter = BasicReporter;
|
||||
exports.parseStack = parseStack;
|
||||
72
node_modules/consola/dist/shared/consola.DRwqZj3T.mjs
generated
vendored
Normal file
72
node_modules/consola/dist/shared/consola.DRwqZj3T.mjs
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
import { formatWithOptions } from 'node:util';
|
||||
import { sep } from 'node:path';
|
||||
|
||||
function parseStack(stack, message) {
|
||||
const cwd = process.cwd() + sep;
|
||||
const lines = stack.split("\n").splice(message.split("\n").length).map((l) => l.trim().replace("file://", "").replace(cwd, ""));
|
||||
return lines;
|
||||
}
|
||||
|
||||
function writeStream(data, stream) {
|
||||
const write = stream.__write || stream.write;
|
||||
return write.call(stream, data);
|
||||
}
|
||||
|
||||
const bracket = (x) => x ? `[${x}]` : "";
|
||||
class BasicReporter {
|
||||
formatStack(stack, message, opts) {
|
||||
const indent = " ".repeat((opts?.errorLevel || 0) + 1);
|
||||
return indent + parseStack(stack, message).join(`
|
||||
${indent}`);
|
||||
}
|
||||
formatError(err, opts) {
|
||||
const message = err.message ?? formatWithOptions(opts, err);
|
||||
const stack = err.stack ? this.formatStack(err.stack, message, opts) : "";
|
||||
const level = opts?.errorLevel || 0;
|
||||
const causedPrefix = level > 0 ? `${" ".repeat(level)}[cause]: ` : "";
|
||||
const causedError = err.cause ? "\n\n" + this.formatError(err.cause, { ...opts, errorLevel: level + 1 }) : "";
|
||||
return causedPrefix + message + "\n" + stack + causedError;
|
||||
}
|
||||
formatArgs(args, opts) {
|
||||
const _args = args.map((arg) => {
|
||||
if (arg && typeof arg.stack === "string") {
|
||||
return this.formatError(arg, opts);
|
||||
}
|
||||
return arg;
|
||||
});
|
||||
return formatWithOptions(opts, ..._args);
|
||||
}
|
||||
formatDate(date, opts) {
|
||||
return opts.date ? date.toLocaleTimeString() : "";
|
||||
}
|
||||
filterAndJoin(arr) {
|
||||
return arr.filter(Boolean).join(" ");
|
||||
}
|
||||
formatLogObj(logObj, opts) {
|
||||
const message = this.formatArgs(logObj.args, opts);
|
||||
if (logObj.type === "box") {
|
||||
return "\n" + [
|
||||
bracket(logObj.tag),
|
||||
logObj.title && logObj.title,
|
||||
...message.split("\n")
|
||||
].filter(Boolean).map((l) => " > " + l).join("\n") + "\n";
|
||||
}
|
||||
return this.filterAndJoin([
|
||||
bracket(logObj.type),
|
||||
bracket(logObj.tag),
|
||||
message
|
||||
]);
|
||||
}
|
||||
log(logObj, ctx) {
|
||||
const line = this.formatLogObj(logObj, {
|
||||
columns: ctx.options.stdout.columns || 0,
|
||||
...ctx.options.formatOptions
|
||||
});
|
||||
return writeStream(
|
||||
line + "\n",
|
||||
logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export { BasicReporter as B, parseStack as p };
|
||||
288
node_modules/consola/dist/shared/consola.DXBYu-KD.mjs
generated
vendored
Normal file
288
node_modules/consola/dist/shared/consola.DXBYu-KD.mjs
generated
vendored
Normal file
@@ -0,0 +1,288 @@
|
||||
import * as tty from 'node:tty';
|
||||
|
||||
const {
|
||||
env = {},
|
||||
argv = [],
|
||||
platform = ""
|
||||
} = typeof process === "undefined" ? {} : process;
|
||||
const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
|
||||
const isForced = "FORCE_COLOR" in env || argv.includes("--color");
|
||||
const isWindows = platform === "win32";
|
||||
const isDumbTerminal = env.TERM === "dumb";
|
||||
const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
|
||||
const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
|
||||
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
||||
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)) {
|
||||
return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
||||
}
|
||||
function clearBleed(index, string, open, close, replace) {
|
||||
return index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
|
||||
}
|
||||
function filterEmpty(open, close, replace = open, at = open.length + 1) {
|
||||
return (string) => string || !(string === "" || string === void 0) ? clearBleed(
|
||||
("" + string).indexOf(close, at),
|
||||
string,
|
||||
open,
|
||||
close,
|
||||
replace
|
||||
) : "";
|
||||
}
|
||||
function init(open, close, replace) {
|
||||
return filterEmpty(`\x1B[${open}m`, `\x1B[${close}m`, replace);
|
||||
}
|
||||
const colorDefs = {
|
||||
reset: init(0, 0),
|
||||
bold: init(1, 22, "\x1B[22m\x1B[1m"),
|
||||
dim: init(2, 22, "\x1B[22m\x1B[2m"),
|
||||
italic: init(3, 23),
|
||||
underline: init(4, 24),
|
||||
inverse: init(7, 27),
|
||||
hidden: init(8, 28),
|
||||
strikethrough: init(9, 29),
|
||||
black: init(30, 39),
|
||||
red: init(31, 39),
|
||||
green: init(32, 39),
|
||||
yellow: init(33, 39),
|
||||
blue: init(34, 39),
|
||||
magenta: init(35, 39),
|
||||
cyan: init(36, 39),
|
||||
white: init(37, 39),
|
||||
gray: init(90, 39),
|
||||
bgBlack: init(40, 49),
|
||||
bgRed: init(41, 49),
|
||||
bgGreen: init(42, 49),
|
||||
bgYellow: init(43, 49),
|
||||
bgBlue: init(44, 49),
|
||||
bgMagenta: init(45, 49),
|
||||
bgCyan: init(46, 49),
|
||||
bgWhite: init(47, 49),
|
||||
blackBright: init(90, 39),
|
||||
redBright: init(91, 39),
|
||||
greenBright: init(92, 39),
|
||||
yellowBright: init(93, 39),
|
||||
blueBright: init(94, 39),
|
||||
magentaBright: init(95, 39),
|
||||
cyanBright: init(96, 39),
|
||||
whiteBright: init(97, 39),
|
||||
bgBlackBright: init(100, 49),
|
||||
bgRedBright: init(101, 49),
|
||||
bgGreenBright: init(102, 49),
|
||||
bgYellowBright: init(103, 49),
|
||||
bgBlueBright: init(104, 49),
|
||||
bgMagentaBright: init(105, 49),
|
||||
bgCyanBright: init(106, 49),
|
||||
bgWhiteBright: init(107, 49)
|
||||
};
|
||||
function createColors(useColor = isColorSupported) {
|
||||
return useColor ? colorDefs : Object.fromEntries(Object.keys(colorDefs).map((key) => [key, String]));
|
||||
}
|
||||
const colors = createColors();
|
||||
function getColor(color, fallback = "reset") {
|
||||
return colors[color] || colors[fallback];
|
||||
}
|
||||
function colorize(color, text) {
|
||||
return getColor(color)(text);
|
||||
}
|
||||
|
||||
const ansiRegex = [
|
||||
String.raw`[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`,
|
||||
String.raw`(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`
|
||||
].join("|");
|
||||
function stripAnsi(text) {
|
||||
return text.replace(new RegExp(ansiRegex, "g"), "");
|
||||
}
|
||||
function centerAlign(str, len, space = " ") {
|
||||
const free = len - str.length;
|
||||
if (free <= 0) {
|
||||
return str;
|
||||
}
|
||||
const freeLeft = Math.floor(free / 2);
|
||||
let _str = "";
|
||||
for (let i = 0; i < len; i++) {
|
||||
_str += i < freeLeft || i >= freeLeft + str.length ? space : str[i - freeLeft];
|
||||
}
|
||||
return _str;
|
||||
}
|
||||
function rightAlign(str, len, space = " ") {
|
||||
const free = len - str.length;
|
||||
if (free <= 0) {
|
||||
return str;
|
||||
}
|
||||
let _str = "";
|
||||
for (let i = 0; i < len; i++) {
|
||||
_str += i < free ? space : str[i - free];
|
||||
}
|
||||
return _str;
|
||||
}
|
||||
function leftAlign(str, len, space = " ") {
|
||||
let _str = "";
|
||||
for (let i = 0; i < len; i++) {
|
||||
_str += i < str.length ? str[i] : space;
|
||||
}
|
||||
return _str;
|
||||
}
|
||||
function align(alignment, str, len, space = " ") {
|
||||
switch (alignment) {
|
||||
case "left": {
|
||||
return leftAlign(str, len, space);
|
||||
}
|
||||
case "right": {
|
||||
return rightAlign(str, len, space);
|
||||
}
|
||||
case "center": {
|
||||
return centerAlign(str, len, space);
|
||||
}
|
||||
default: {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const boxStylePresets = {
|
||||
solid: {
|
||||
tl: "\u250C",
|
||||
tr: "\u2510",
|
||||
bl: "\u2514",
|
||||
br: "\u2518",
|
||||
h: "\u2500",
|
||||
v: "\u2502"
|
||||
},
|
||||
double: {
|
||||
tl: "\u2554",
|
||||
tr: "\u2557",
|
||||
bl: "\u255A",
|
||||
br: "\u255D",
|
||||
h: "\u2550",
|
||||
v: "\u2551"
|
||||
},
|
||||
doubleSingle: {
|
||||
tl: "\u2553",
|
||||
tr: "\u2556",
|
||||
bl: "\u2559",
|
||||
br: "\u255C",
|
||||
h: "\u2500",
|
||||
v: "\u2551"
|
||||
},
|
||||
doubleSingleRounded: {
|
||||
tl: "\u256D",
|
||||
tr: "\u256E",
|
||||
bl: "\u2570",
|
||||
br: "\u256F",
|
||||
h: "\u2500",
|
||||
v: "\u2551"
|
||||
},
|
||||
singleThick: {
|
||||
tl: "\u250F",
|
||||
tr: "\u2513",
|
||||
bl: "\u2517",
|
||||
br: "\u251B",
|
||||
h: "\u2501",
|
||||
v: "\u2503"
|
||||
},
|
||||
singleDouble: {
|
||||
tl: "\u2552",
|
||||
tr: "\u2555",
|
||||
bl: "\u2558",
|
||||
br: "\u255B",
|
||||
h: "\u2550",
|
||||
v: "\u2502"
|
||||
},
|
||||
singleDoubleRounded: {
|
||||
tl: "\u256D",
|
||||
tr: "\u256E",
|
||||
bl: "\u2570",
|
||||
br: "\u256F",
|
||||
h: "\u2550",
|
||||
v: "\u2502"
|
||||
},
|
||||
rounded: {
|
||||
tl: "\u256D",
|
||||
tr: "\u256E",
|
||||
bl: "\u2570",
|
||||
br: "\u256F",
|
||||
h: "\u2500",
|
||||
v: "\u2502"
|
||||
}
|
||||
};
|
||||
const defaultStyle = {
|
||||
borderColor: "white",
|
||||
borderStyle: "rounded",
|
||||
valign: "center",
|
||||
padding: 2,
|
||||
marginLeft: 1,
|
||||
marginTop: 1,
|
||||
marginBottom: 1
|
||||
};
|
||||
function box(text, _opts = {}) {
|
||||
const opts = {
|
||||
..._opts,
|
||||
style: {
|
||||
...defaultStyle,
|
||||
..._opts.style
|
||||
}
|
||||
};
|
||||
const textLines = text.split("\n");
|
||||
const boxLines = [];
|
||||
const _color = getColor(opts.style.borderColor);
|
||||
const borderStyle = {
|
||||
...typeof opts.style.borderStyle === "string" ? boxStylePresets[opts.style.borderStyle] || boxStylePresets.solid : opts.style.borderStyle
|
||||
};
|
||||
if (_color) {
|
||||
for (const key in borderStyle) {
|
||||
borderStyle[key] = _color(
|
||||
borderStyle[key]
|
||||
);
|
||||
}
|
||||
}
|
||||
const paddingOffset = opts.style.padding % 2 === 0 ? opts.style.padding : opts.style.padding + 1;
|
||||
const height = textLines.length + paddingOffset;
|
||||
const width = Math.max(
|
||||
...textLines.map((line) => stripAnsi(line).length),
|
||||
opts.title ? stripAnsi(opts.title).length : 0
|
||||
) + paddingOffset;
|
||||
const widthOffset = width + paddingOffset;
|
||||
const leftSpace = opts.style.marginLeft > 0 ? " ".repeat(opts.style.marginLeft) : "";
|
||||
if (opts.style.marginTop > 0) {
|
||||
boxLines.push("".repeat(opts.style.marginTop));
|
||||
}
|
||||
if (opts.title) {
|
||||
const title = _color ? _color(opts.title) : opts.title;
|
||||
const left = borderStyle.h.repeat(
|
||||
Math.floor((width - stripAnsi(opts.title).length) / 2)
|
||||
);
|
||||
const right = borderStyle.h.repeat(
|
||||
width - stripAnsi(opts.title).length - stripAnsi(left).length + paddingOffset
|
||||
);
|
||||
boxLines.push(
|
||||
`${leftSpace}${borderStyle.tl}${left}${title}${right}${borderStyle.tr}`
|
||||
);
|
||||
} else {
|
||||
boxLines.push(
|
||||
`${leftSpace}${borderStyle.tl}${borderStyle.h.repeat(widthOffset)}${borderStyle.tr}`
|
||||
);
|
||||
}
|
||||
const valignOffset = opts.style.valign === "center" ? Math.floor((height - textLines.length) / 2) : opts.style.valign === "top" ? height - textLines.length - paddingOffset : height - textLines.length;
|
||||
for (let i = 0; i < height; i++) {
|
||||
if (i < valignOffset || i >= valignOffset + textLines.length) {
|
||||
boxLines.push(
|
||||
`${leftSpace}${borderStyle.v}${" ".repeat(widthOffset)}${borderStyle.v}`
|
||||
);
|
||||
} else {
|
||||
const line = textLines[i - valignOffset];
|
||||
const left = " ".repeat(paddingOffset);
|
||||
const right = " ".repeat(width - stripAnsi(line).length);
|
||||
boxLines.push(
|
||||
`${leftSpace}${borderStyle.v}${left}${line}${right}${borderStyle.v}`
|
||||
);
|
||||
}
|
||||
}
|
||||
boxLines.push(
|
||||
`${leftSpace}${borderStyle.bl}${borderStyle.h.repeat(widthOffset)}${borderStyle.br}`
|
||||
);
|
||||
if (opts.style.marginBottom > 0) {
|
||||
boxLines.push("".repeat(opts.style.marginBottom));
|
||||
}
|
||||
return boxLines.join("\n");
|
||||
}
|
||||
|
||||
export { centerAlign as a, align as b, colorize as c, box as d, colors as e, getColor as g, leftAlign as l, rightAlign as r, stripAnsi as s };
|
||||
312
node_modules/consola/dist/shared/consola.DwRq1yyg.cjs
generated
vendored
Normal file
312
node_modules/consola/dist/shared/consola.DwRq1yyg.cjs
generated
vendored
Normal file
@@ -0,0 +1,312 @@
|
||||
'use strict';
|
||||
|
||||
const tty = require('node:tty');
|
||||
|
||||
function _interopNamespaceCompat(e) {
|
||||
if (e && typeof e === 'object' && 'default' in e) return e;
|
||||
const n = Object.create(null);
|
||||
if (e) {
|
||||
for (const k in e) {
|
||||
n[k] = e[k];
|
||||
}
|
||||
}
|
||||
n.default = e;
|
||||
return n;
|
||||
}
|
||||
|
||||
const tty__namespace = /*#__PURE__*/_interopNamespaceCompat(tty);
|
||||
|
||||
const {
|
||||
env = {},
|
||||
argv = [],
|
||||
platform = ""
|
||||
} = typeof process === "undefined" ? {} : process;
|
||||
const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
|
||||
const isForced = "FORCE_COLOR" in env || argv.includes("--color");
|
||||
const isWindows = platform === "win32";
|
||||
const isDumbTerminal = env.TERM === "dumb";
|
||||
const isCompatibleTerminal = tty__namespace && tty__namespace.isatty && tty__namespace.isatty(1) && env.TERM && !isDumbTerminal;
|
||||
const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
|
||||
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
||||
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)) {
|
||||
return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
||||
}
|
||||
function clearBleed(index, string, open, close, replace) {
|
||||
return index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
|
||||
}
|
||||
function filterEmpty(open, close, replace = open, at = open.length + 1) {
|
||||
return (string) => string || !(string === "" || string === void 0) ? clearBleed(
|
||||
("" + string).indexOf(close, at),
|
||||
string,
|
||||
open,
|
||||
close,
|
||||
replace
|
||||
) : "";
|
||||
}
|
||||
function init(open, close, replace) {
|
||||
return filterEmpty(`\x1B[${open}m`, `\x1B[${close}m`, replace);
|
||||
}
|
||||
const colorDefs = {
|
||||
reset: init(0, 0),
|
||||
bold: init(1, 22, "\x1B[22m\x1B[1m"),
|
||||
dim: init(2, 22, "\x1B[22m\x1B[2m"),
|
||||
italic: init(3, 23),
|
||||
underline: init(4, 24),
|
||||
inverse: init(7, 27),
|
||||
hidden: init(8, 28),
|
||||
strikethrough: init(9, 29),
|
||||
black: init(30, 39),
|
||||
red: init(31, 39),
|
||||
green: init(32, 39),
|
||||
yellow: init(33, 39),
|
||||
blue: init(34, 39),
|
||||
magenta: init(35, 39),
|
||||
cyan: init(36, 39),
|
||||
white: init(37, 39),
|
||||
gray: init(90, 39),
|
||||
bgBlack: init(40, 49),
|
||||
bgRed: init(41, 49),
|
||||
bgGreen: init(42, 49),
|
||||
bgYellow: init(43, 49),
|
||||
bgBlue: init(44, 49),
|
||||
bgMagenta: init(45, 49),
|
||||
bgCyan: init(46, 49),
|
||||
bgWhite: init(47, 49),
|
||||
blackBright: init(90, 39),
|
||||
redBright: init(91, 39),
|
||||
greenBright: init(92, 39),
|
||||
yellowBright: init(93, 39),
|
||||
blueBright: init(94, 39),
|
||||
magentaBright: init(95, 39),
|
||||
cyanBright: init(96, 39),
|
||||
whiteBright: init(97, 39),
|
||||
bgBlackBright: init(100, 49),
|
||||
bgRedBright: init(101, 49),
|
||||
bgGreenBright: init(102, 49),
|
||||
bgYellowBright: init(103, 49),
|
||||
bgBlueBright: init(104, 49),
|
||||
bgMagentaBright: init(105, 49),
|
||||
bgCyanBright: init(106, 49),
|
||||
bgWhiteBright: init(107, 49)
|
||||
};
|
||||
function createColors(useColor = isColorSupported) {
|
||||
return useColor ? colorDefs : Object.fromEntries(Object.keys(colorDefs).map((key) => [key, String]));
|
||||
}
|
||||
const colors = createColors();
|
||||
function getColor(color, fallback = "reset") {
|
||||
return colors[color] || colors[fallback];
|
||||
}
|
||||
function colorize(color, text) {
|
||||
return getColor(color)(text);
|
||||
}
|
||||
|
||||
const ansiRegex = [
|
||||
String.raw`[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`,
|
||||
String.raw`(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`
|
||||
].join("|");
|
||||
function stripAnsi(text) {
|
||||
return text.replace(new RegExp(ansiRegex, "g"), "");
|
||||
}
|
||||
function centerAlign(str, len, space = " ") {
|
||||
const free = len - str.length;
|
||||
if (free <= 0) {
|
||||
return str;
|
||||
}
|
||||
const freeLeft = Math.floor(free / 2);
|
||||
let _str = "";
|
||||
for (let i = 0; i < len; i++) {
|
||||
_str += i < freeLeft || i >= freeLeft + str.length ? space : str[i - freeLeft];
|
||||
}
|
||||
return _str;
|
||||
}
|
||||
function rightAlign(str, len, space = " ") {
|
||||
const free = len - str.length;
|
||||
if (free <= 0) {
|
||||
return str;
|
||||
}
|
||||
let _str = "";
|
||||
for (let i = 0; i < len; i++) {
|
||||
_str += i < free ? space : str[i - free];
|
||||
}
|
||||
return _str;
|
||||
}
|
||||
function leftAlign(str, len, space = " ") {
|
||||
let _str = "";
|
||||
for (let i = 0; i < len; i++) {
|
||||
_str += i < str.length ? str[i] : space;
|
||||
}
|
||||
return _str;
|
||||
}
|
||||
function align(alignment, str, len, space = " ") {
|
||||
switch (alignment) {
|
||||
case "left": {
|
||||
return leftAlign(str, len, space);
|
||||
}
|
||||
case "right": {
|
||||
return rightAlign(str, len, space);
|
||||
}
|
||||
case "center": {
|
||||
return centerAlign(str, len, space);
|
||||
}
|
||||
default: {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const boxStylePresets = {
|
||||
solid: {
|
||||
tl: "\u250C",
|
||||
tr: "\u2510",
|
||||
bl: "\u2514",
|
||||
br: "\u2518",
|
||||
h: "\u2500",
|
||||
v: "\u2502"
|
||||
},
|
||||
double: {
|
||||
tl: "\u2554",
|
||||
tr: "\u2557",
|
||||
bl: "\u255A",
|
||||
br: "\u255D",
|
||||
h: "\u2550",
|
||||
v: "\u2551"
|
||||
},
|
||||
doubleSingle: {
|
||||
tl: "\u2553",
|
||||
tr: "\u2556",
|
||||
bl: "\u2559",
|
||||
br: "\u255C",
|
||||
h: "\u2500",
|
||||
v: "\u2551"
|
||||
},
|
||||
doubleSingleRounded: {
|
||||
tl: "\u256D",
|
||||
tr: "\u256E",
|
||||
bl: "\u2570",
|
||||
br: "\u256F",
|
||||
h: "\u2500",
|
||||
v: "\u2551"
|
||||
},
|
||||
singleThick: {
|
||||
tl: "\u250F",
|
||||
tr: "\u2513",
|
||||
bl: "\u2517",
|
||||
br: "\u251B",
|
||||
h: "\u2501",
|
||||
v: "\u2503"
|
||||
},
|
||||
singleDouble: {
|
||||
tl: "\u2552",
|
||||
tr: "\u2555",
|
||||
bl: "\u2558",
|
||||
br: "\u255B",
|
||||
h: "\u2550",
|
||||
v: "\u2502"
|
||||
},
|
||||
singleDoubleRounded: {
|
||||
tl: "\u256D",
|
||||
tr: "\u256E",
|
||||
bl: "\u2570",
|
||||
br: "\u256F",
|
||||
h: "\u2550",
|
||||
v: "\u2502"
|
||||
},
|
||||
rounded: {
|
||||
tl: "\u256D",
|
||||
tr: "\u256E",
|
||||
bl: "\u2570",
|
||||
br: "\u256F",
|
||||
h: "\u2500",
|
||||
v: "\u2502"
|
||||
}
|
||||
};
|
||||
const defaultStyle = {
|
||||
borderColor: "white",
|
||||
borderStyle: "rounded",
|
||||
valign: "center",
|
||||
padding: 2,
|
||||
marginLeft: 1,
|
||||
marginTop: 1,
|
||||
marginBottom: 1
|
||||
};
|
||||
function box(text, _opts = {}) {
|
||||
const opts = {
|
||||
..._opts,
|
||||
style: {
|
||||
...defaultStyle,
|
||||
..._opts.style
|
||||
}
|
||||
};
|
||||
const textLines = text.split("\n");
|
||||
const boxLines = [];
|
||||
const _color = getColor(opts.style.borderColor);
|
||||
const borderStyle = {
|
||||
...typeof opts.style.borderStyle === "string" ? boxStylePresets[opts.style.borderStyle] || boxStylePresets.solid : opts.style.borderStyle
|
||||
};
|
||||
if (_color) {
|
||||
for (const key in borderStyle) {
|
||||
borderStyle[key] = _color(
|
||||
borderStyle[key]
|
||||
);
|
||||
}
|
||||
}
|
||||
const paddingOffset = opts.style.padding % 2 === 0 ? opts.style.padding : opts.style.padding + 1;
|
||||
const height = textLines.length + paddingOffset;
|
||||
const width = Math.max(
|
||||
...textLines.map((line) => stripAnsi(line).length),
|
||||
opts.title ? stripAnsi(opts.title).length : 0
|
||||
) + paddingOffset;
|
||||
const widthOffset = width + paddingOffset;
|
||||
const leftSpace = opts.style.marginLeft > 0 ? " ".repeat(opts.style.marginLeft) : "";
|
||||
if (opts.style.marginTop > 0) {
|
||||
boxLines.push("".repeat(opts.style.marginTop));
|
||||
}
|
||||
if (opts.title) {
|
||||
const title = _color ? _color(opts.title) : opts.title;
|
||||
const left = borderStyle.h.repeat(
|
||||
Math.floor((width - stripAnsi(opts.title).length) / 2)
|
||||
);
|
||||
const right = borderStyle.h.repeat(
|
||||
width - stripAnsi(opts.title).length - stripAnsi(left).length + paddingOffset
|
||||
);
|
||||
boxLines.push(
|
||||
`${leftSpace}${borderStyle.tl}${left}${title}${right}${borderStyle.tr}`
|
||||
);
|
||||
} else {
|
||||
boxLines.push(
|
||||
`${leftSpace}${borderStyle.tl}${borderStyle.h.repeat(widthOffset)}${borderStyle.tr}`
|
||||
);
|
||||
}
|
||||
const valignOffset = opts.style.valign === "center" ? Math.floor((height - textLines.length) / 2) : opts.style.valign === "top" ? height - textLines.length - paddingOffset : height - textLines.length;
|
||||
for (let i = 0; i < height; i++) {
|
||||
if (i < valignOffset || i >= valignOffset + textLines.length) {
|
||||
boxLines.push(
|
||||
`${leftSpace}${borderStyle.v}${" ".repeat(widthOffset)}${borderStyle.v}`
|
||||
);
|
||||
} else {
|
||||
const line = textLines[i - valignOffset];
|
||||
const left = " ".repeat(paddingOffset);
|
||||
const right = " ".repeat(width - stripAnsi(line).length);
|
||||
boxLines.push(
|
||||
`${leftSpace}${borderStyle.v}${left}${line}${right}${borderStyle.v}`
|
||||
);
|
||||
}
|
||||
}
|
||||
boxLines.push(
|
||||
`${leftSpace}${borderStyle.bl}${borderStyle.h.repeat(widthOffset)}${borderStyle.br}`
|
||||
);
|
||||
if (opts.style.marginBottom > 0) {
|
||||
boxLines.push("".repeat(opts.style.marginBottom));
|
||||
}
|
||||
return boxLines.join("\n");
|
||||
}
|
||||
|
||||
exports.align = align;
|
||||
exports.box = box;
|
||||
exports.centerAlign = centerAlign;
|
||||
exports.colorize = colorize;
|
||||
exports.colors = colors;
|
||||
exports.getColor = getColor;
|
||||
exports.leftAlign = leftAlign;
|
||||
exports.rightAlign = rightAlign;
|
||||
exports.stripAnsi = stripAnsi;
|
||||
64
node_modules/consola/dist/utils.cjs
generated
vendored
Normal file
64
node_modules/consola/dist/utils.cjs
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
'use strict';
|
||||
|
||||
const box = require('./shared/consola.DwRq1yyg.cjs');
|
||||
require('node:tty');
|
||||
|
||||
function formatTree(items, options) {
|
||||
options = {
|
||||
prefix: " ",
|
||||
ellipsis: "...",
|
||||
...options
|
||||
};
|
||||
const tree = _buildTree(items, options).join("");
|
||||
if (options && options.color) {
|
||||
return box.colorize(options.color, tree);
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
function _buildTree(items, options) {
|
||||
const chunks = [];
|
||||
const total = items.length - 1;
|
||||
for (let i = 0; i <= total; i++) {
|
||||
const item = items[i];
|
||||
const isItemString = typeof item === "string";
|
||||
const isLimit = options?.maxDepth != null && options.maxDepth <= 0;
|
||||
if (isLimit) {
|
||||
const ellipsis = `${options.prefix}${options.ellipsis}
|
||||
`;
|
||||
return [
|
||||
isItemString ? ellipsis : item.color ? box.colorize(item.color, ellipsis) : ellipsis
|
||||
// prettier-ignore
|
||||
];
|
||||
}
|
||||
const isLast = i === total;
|
||||
const prefix = isLast ? `${options?.prefix}\u2514\u2500` : `${options?.prefix}\u251C\u2500`;
|
||||
if (isItemString) {
|
||||
chunks.push(`${prefix}${item}
|
||||
`);
|
||||
} else {
|
||||
const log = `${prefix}${item.text}
|
||||
`;
|
||||
chunks.push(item.color ? box.colorize(item.color, log) : log);
|
||||
if (item.children) {
|
||||
const _tree = _buildTree(item.children, {
|
||||
...options,
|
||||
maxDepth: options?.maxDepth == null ? void 0 : options.maxDepth - 1,
|
||||
prefix: `${options?.prefix}${isLast ? " " : "\u2502 "}`
|
||||
});
|
||||
chunks.push(..._tree);
|
||||
}
|
||||
}
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
exports.align = box.align;
|
||||
exports.box = box.box;
|
||||
exports.centerAlign = box.centerAlign;
|
||||
exports.colorize = box.colorize;
|
||||
exports.colors = box.colors;
|
||||
exports.getColor = box.getColor;
|
||||
exports.leftAlign = box.leftAlign;
|
||||
exports.rightAlign = box.rightAlign;
|
||||
exports.stripAnsi = box.stripAnsi;
|
||||
exports.formatTree = formatTree;
|
||||
286
node_modules/consola/dist/utils.d.cts
generated
vendored
Normal file
286
node_modules/consola/dist/utils.d.cts
generated
vendored
Normal file
@@ -0,0 +1,286 @@
|
||||
type BoxBorderStyle = {
|
||||
/**
|
||||
* Top left corner
|
||||
* @example `┌`
|
||||
* @example `╔`
|
||||
* @example `╓`
|
||||
*/
|
||||
tl: string;
|
||||
/**
|
||||
* Top right corner
|
||||
* @example `┐`
|
||||
* @example `╗`
|
||||
* @example `╖`
|
||||
*/
|
||||
tr: string;
|
||||
/**
|
||||
* Bottom left corner
|
||||
* @example `└`
|
||||
* @example `╚`
|
||||
* @example `╙`
|
||||
*/
|
||||
bl: string;
|
||||
/**
|
||||
* Bottom right corner
|
||||
* @example `┘`
|
||||
* @example `╝`
|
||||
* @example `╜`
|
||||
*/
|
||||
br: string;
|
||||
/**
|
||||
* Horizontal line
|
||||
* @example `─`
|
||||
* @example `═`
|
||||
* @example `─`
|
||||
*/
|
||||
h: string;
|
||||
/**
|
||||
* Vertical line
|
||||
* @example `│`
|
||||
* @example `║`
|
||||
* @example `║`
|
||||
*/
|
||||
v: string;
|
||||
};
|
||||
declare const boxStylePresets: Record<string, BoxBorderStyle>;
|
||||
type BoxStyle = {
|
||||
/**
|
||||
* The border color
|
||||
* @default 'white'
|
||||
*/
|
||||
borderColor: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright";
|
||||
/**
|
||||
* The border style
|
||||
* @default 'solid'
|
||||
* @example 'single-double-rounded'
|
||||
* @example
|
||||
* ```ts
|
||||
* {
|
||||
* tl: '┌',
|
||||
* tr: '┐',
|
||||
* bl: '└',
|
||||
* br: '┘',
|
||||
* h: '─',
|
||||
* v: '│',
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
borderStyle: BoxBorderStyle | keyof typeof boxStylePresets;
|
||||
/**
|
||||
* The vertical alignment of the text
|
||||
* @default 'center'
|
||||
*/
|
||||
valign: "top" | "center" | "bottom";
|
||||
/**
|
||||
* The padding of the box
|
||||
* @default 2
|
||||
*/
|
||||
padding: number;
|
||||
/**
|
||||
* The left margin of the box
|
||||
* @default 1
|
||||
*/
|
||||
marginLeft: number;
|
||||
/**
|
||||
* The top margin of the box
|
||||
* @default 1
|
||||
*/
|
||||
marginTop: number;
|
||||
/**
|
||||
* The top margin of the box
|
||||
* @default 1
|
||||
*/
|
||||
marginBottom: number;
|
||||
};
|
||||
/**
|
||||
* The border options of the box
|
||||
*/
|
||||
type BoxOpts = {
|
||||
/**
|
||||
* Title that will be displayed on top of the box
|
||||
* @example 'Hello World'
|
||||
* @example 'Hello {name}'
|
||||
*/
|
||||
title?: string;
|
||||
style?: Partial<BoxStyle>;
|
||||
};
|
||||
/**
|
||||
* Creates a styled box with text content, customisable via options.
|
||||
* @param {string} text - The text to display in the box.
|
||||
* @param {BoxOpts} [_opts={}] - Optional settings for the appearance and behaviour of the box. See {@link BoxOpts}.
|
||||
* @returns {string} The formatted box as a string, ready for printing or logging.
|
||||
*/
|
||||
declare function box(text: string, _opts?: BoxOpts): string;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/jorgebucaran/colorette
|
||||
* Read LICENSE file for more information
|
||||
* https://github.com/jorgebucaran/colorette/blob/20fc196d07d0f87c61e0256eadd7831c79b24108/index.js
|
||||
*/
|
||||
declare const colorDefs: {
|
||||
reset: (string: string) => string;
|
||||
bold: (string: string) => string;
|
||||
dim: (string: string) => string;
|
||||
italic: (string: string) => string;
|
||||
underline: (string: string) => string;
|
||||
inverse: (string: string) => string;
|
||||
hidden: (string: string) => string;
|
||||
strikethrough: (string: string) => string;
|
||||
black: (string: string) => string;
|
||||
red: (string: string) => string;
|
||||
green: (string: string) => string;
|
||||
yellow: (string: string) => string;
|
||||
blue: (string: string) => string;
|
||||
magenta: (string: string) => string;
|
||||
cyan: (string: string) => string;
|
||||
white: (string: string) => string;
|
||||
gray: (string: string) => string;
|
||||
bgBlack: (string: string) => string;
|
||||
bgRed: (string: string) => string;
|
||||
bgGreen: (string: string) => string;
|
||||
bgYellow: (string: string) => string;
|
||||
bgBlue: (string: string) => string;
|
||||
bgMagenta: (string: string) => string;
|
||||
bgCyan: (string: string) => string;
|
||||
bgWhite: (string: string) => string;
|
||||
blackBright: (string: string) => string;
|
||||
redBright: (string: string) => string;
|
||||
greenBright: (string: string) => string;
|
||||
yellowBright: (string: string) => string;
|
||||
blueBright: (string: string) => string;
|
||||
magentaBright: (string: string) => string;
|
||||
cyanBright: (string: string) => string;
|
||||
whiteBright: (string: string) => string;
|
||||
bgBlackBright: (string: string) => string;
|
||||
bgRedBright: (string: string) => string;
|
||||
bgGreenBright: (string: string) => string;
|
||||
bgYellowBright: (string: string) => string;
|
||||
bgBlueBright: (string: string) => string;
|
||||
bgMagentaBright: (string: string) => string;
|
||||
bgCyanBright: (string: string) => string;
|
||||
bgWhiteBright: (string: string) => string;
|
||||
};
|
||||
type ColorName = keyof typeof colorDefs;
|
||||
type ColorFunction = (text: string | number) => string;
|
||||
/**
|
||||
* An object containing functions for colouring text. Each function corresponds to a terminal colour. See {@link ColorName} for available colours.
|
||||
*/
|
||||
declare const colors: Record<ColorName, ColorFunction>;
|
||||
/**
|
||||
* Gets a colour function by name, with an option for a fallback colour if the requested colour is not found.
|
||||
* @param {ColorName} color - The name of the colour function to get. See {@link ColorName}.
|
||||
* @param {ColorName} [fallback="reset"] - The name of the fallback colour function if the requested colour is not found. See {@link ColorName}.
|
||||
* @returns {ColorFunction} The colour function that corresponds to the requested colour, or the fallback colour function. See {@link ColorFunction}.
|
||||
*/
|
||||
declare function getColor(color: ColorName, fallback?: ColorName): ColorFunction;
|
||||
/**
|
||||
* Applies a specified colour to a given text string or number.
|
||||
* @param {ColorName} color - The colour to apply. See {@link ColorName}.
|
||||
* @param {string | number} text - The text to colour.
|
||||
* @returns {string} The coloured text.
|
||||
*/
|
||||
declare function colorize(color: ColorName, text: string | number): string;
|
||||
|
||||
/**
|
||||
* Removes ANSI escape codes from a given string. This is particularly useful for
|
||||
* processing text that contains formatting codes, such as colours or styles, so that the
|
||||
* the raw text without any visual formatting.
|
||||
*
|
||||
* @param {string} text - The text string from which to strip the ANSI escape codes.
|
||||
* @returns {string} The text without ANSI escape codes.
|
||||
*/
|
||||
declare function stripAnsi(text: string): string;
|
||||
/**
|
||||
* Centers a string within a specified total width, padding it with spaces or another specified character.
|
||||
* If the string is longer than the total width, it is returned as is.
|
||||
*
|
||||
* @param {string} str - The string to centre.
|
||||
* @param {number} len - The total width in which to centre the string.
|
||||
* @param {string} [space=" "] - The character to use for padding. Defaults to a space.
|
||||
* @returns {string} The centred string.
|
||||
*/
|
||||
declare function centerAlign(str: string, len: number, space?: string): string;
|
||||
/**
|
||||
* Right-justifies a string within a given total width, padding it with whitespace or another specified character.
|
||||
* If the string is longer than the total width, it is returned as is.
|
||||
*
|
||||
* @param {string} str - The string to right-justify.
|
||||
* @param {number} len - The total width to align the string.
|
||||
* @param {string} [space=" "] - The character to use for padding. Defaults to a space.
|
||||
* @returns {string} The right-justified string.
|
||||
*/
|
||||
declare function rightAlign(str: string, len: number, space?: string): string;
|
||||
/**
|
||||
* Left-aligns a string within a given total width, padding it with whitespace or another specified character on the right.
|
||||
* If the string is longer than the total width, it is returned as is.
|
||||
*
|
||||
* @param {string} str - The string to align left.
|
||||
* @param {number} len - The total width to align the string.
|
||||
* @param {string} [space=" "] - The character to use for padding. Defaults to a space.
|
||||
* @returns {string} The left-justified string.
|
||||
*/
|
||||
declare function leftAlign(str: string, len: number, space?: string): string;
|
||||
/**
|
||||
* Aligns a string (left, right, or centre) within a given total width, padding it with spaces or another specified character.
|
||||
* If the string is longer than the total width, it is returned as is. This function acts as a wrapper for individual alignment functions.
|
||||
*
|
||||
* @param {"left" | "right" | "centre"} alignment - The desired alignment of the string.
|
||||
* @param {string} str - The string to align.
|
||||
* @param {number} len - The total width in which to align the string.
|
||||
* @param {string} [space=" "] - The character to use for padding. Defaults to a space.
|
||||
* @returns {string} The aligned string, according to the given alignment.
|
||||
*/
|
||||
declare function align(alignment: "left" | "right" | "center", str: string, len: number, space?: string): string;
|
||||
|
||||
type TreeItemObject = {
|
||||
/**
|
||||
* Text of the item
|
||||
*/
|
||||
text: string;
|
||||
/**
|
||||
* Children of the item
|
||||
*/
|
||||
children?: TreeItem[];
|
||||
/**
|
||||
* Color of the item
|
||||
*/
|
||||
color?: ColorName;
|
||||
};
|
||||
type TreeItem = string | TreeItemObject;
|
||||
type TreeOptions = {
|
||||
/**
|
||||
* Color of the tree
|
||||
*/
|
||||
color?: ColorName;
|
||||
/**
|
||||
* Prefix of the tree
|
||||
*
|
||||
* @default " "
|
||||
*/
|
||||
prefix?: string;
|
||||
/**
|
||||
* The max depth of tree
|
||||
*/
|
||||
maxDepth?: number;
|
||||
/**
|
||||
* Ellipsis of the tree
|
||||
*
|
||||
* @default "..."
|
||||
*/
|
||||
ellipsis?: string;
|
||||
};
|
||||
/**
|
||||
* Formats a hierarchical list of items into a string representing a tree structure.
|
||||
* Each item in the tree can be a simple string or an object defining the text of the item,
|
||||
* optional children, and colour. The tree structure can be customised with options
|
||||
* Specify the overall colour and the prefix used for indentation and tree lines.
|
||||
*
|
||||
* @param {TreeItem[]} items - An array of items to include in the tree. Each item can be
|
||||
* either a string or an object with `text', `children' and `colour' properties.
|
||||
* @param {TreeOptions} [options] - Optional settings to customise the appearance of the tree, including
|
||||
* the colour of the tree text and the prefix for branches. See {@link TreeOptions}.
|
||||
* @returns {string} The formatted tree as a string, ready for printing to the console or elsewhere.
|
||||
*/
|
||||
declare function formatTree(items: TreeItem[], options?: TreeOptions): string;
|
||||
|
||||
export { type BoxBorderStyle, type BoxOpts, type BoxStyle, type ColorFunction, type ColorName, type TreeItem, type TreeItemObject, type TreeOptions, align, box, centerAlign, colorize, colors, formatTree, getColor, leftAlign, rightAlign, stripAnsi };
|
||||
286
node_modules/consola/dist/utils.d.mts
generated
vendored
Normal file
286
node_modules/consola/dist/utils.d.mts
generated
vendored
Normal file
@@ -0,0 +1,286 @@
|
||||
type BoxBorderStyle = {
|
||||
/**
|
||||
* Top left corner
|
||||
* @example `┌`
|
||||
* @example `╔`
|
||||
* @example `╓`
|
||||
*/
|
||||
tl: string;
|
||||
/**
|
||||
* Top right corner
|
||||
* @example `┐`
|
||||
* @example `╗`
|
||||
* @example `╖`
|
||||
*/
|
||||
tr: string;
|
||||
/**
|
||||
* Bottom left corner
|
||||
* @example `└`
|
||||
* @example `╚`
|
||||
* @example `╙`
|
||||
*/
|
||||
bl: string;
|
||||
/**
|
||||
* Bottom right corner
|
||||
* @example `┘`
|
||||
* @example `╝`
|
||||
* @example `╜`
|
||||
*/
|
||||
br: string;
|
||||
/**
|
||||
* Horizontal line
|
||||
* @example `─`
|
||||
* @example `═`
|
||||
* @example `─`
|
||||
*/
|
||||
h: string;
|
||||
/**
|
||||
* Vertical line
|
||||
* @example `│`
|
||||
* @example `║`
|
||||
* @example `║`
|
||||
*/
|
||||
v: string;
|
||||
};
|
||||
declare const boxStylePresets: Record<string, BoxBorderStyle>;
|
||||
type BoxStyle = {
|
||||
/**
|
||||
* The border color
|
||||
* @default 'white'
|
||||
*/
|
||||
borderColor: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright";
|
||||
/**
|
||||
* The border style
|
||||
* @default 'solid'
|
||||
* @example 'single-double-rounded'
|
||||
* @example
|
||||
* ```ts
|
||||
* {
|
||||
* tl: '┌',
|
||||
* tr: '┐',
|
||||
* bl: '└',
|
||||
* br: '┘',
|
||||
* h: '─',
|
||||
* v: '│',
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
borderStyle: BoxBorderStyle | keyof typeof boxStylePresets;
|
||||
/**
|
||||
* The vertical alignment of the text
|
||||
* @default 'center'
|
||||
*/
|
||||
valign: "top" | "center" | "bottom";
|
||||
/**
|
||||
* The padding of the box
|
||||
* @default 2
|
||||
*/
|
||||
padding: number;
|
||||
/**
|
||||
* The left margin of the box
|
||||
* @default 1
|
||||
*/
|
||||
marginLeft: number;
|
||||
/**
|
||||
* The top margin of the box
|
||||
* @default 1
|
||||
*/
|
||||
marginTop: number;
|
||||
/**
|
||||
* The top margin of the box
|
||||
* @default 1
|
||||
*/
|
||||
marginBottom: number;
|
||||
};
|
||||
/**
|
||||
* The border options of the box
|
||||
*/
|
||||
type BoxOpts = {
|
||||
/**
|
||||
* Title that will be displayed on top of the box
|
||||
* @example 'Hello World'
|
||||
* @example 'Hello {name}'
|
||||
*/
|
||||
title?: string;
|
||||
style?: Partial<BoxStyle>;
|
||||
};
|
||||
/**
|
||||
* Creates a styled box with text content, customisable via options.
|
||||
* @param {string} text - The text to display in the box.
|
||||
* @param {BoxOpts} [_opts={}] - Optional settings for the appearance and behaviour of the box. See {@link BoxOpts}.
|
||||
* @returns {string} The formatted box as a string, ready for printing or logging.
|
||||
*/
|
||||
declare function box(text: string, _opts?: BoxOpts): string;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/jorgebucaran/colorette
|
||||
* Read LICENSE file for more information
|
||||
* https://github.com/jorgebucaran/colorette/blob/20fc196d07d0f87c61e0256eadd7831c79b24108/index.js
|
||||
*/
|
||||
declare const colorDefs: {
|
||||
reset: (string: string) => string;
|
||||
bold: (string: string) => string;
|
||||
dim: (string: string) => string;
|
||||
italic: (string: string) => string;
|
||||
underline: (string: string) => string;
|
||||
inverse: (string: string) => string;
|
||||
hidden: (string: string) => string;
|
||||
strikethrough: (string: string) => string;
|
||||
black: (string: string) => string;
|
||||
red: (string: string) => string;
|
||||
green: (string: string) => string;
|
||||
yellow: (string: string) => string;
|
||||
blue: (string: string) => string;
|
||||
magenta: (string: string) => string;
|
||||
cyan: (string: string) => string;
|
||||
white: (string: string) => string;
|
||||
gray: (string: string) => string;
|
||||
bgBlack: (string: string) => string;
|
||||
bgRed: (string: string) => string;
|
||||
bgGreen: (string: string) => string;
|
||||
bgYellow: (string: string) => string;
|
||||
bgBlue: (string: string) => string;
|
||||
bgMagenta: (string: string) => string;
|
||||
bgCyan: (string: string) => string;
|
||||
bgWhite: (string: string) => string;
|
||||
blackBright: (string: string) => string;
|
||||
redBright: (string: string) => string;
|
||||
greenBright: (string: string) => string;
|
||||
yellowBright: (string: string) => string;
|
||||
blueBright: (string: string) => string;
|
||||
magentaBright: (string: string) => string;
|
||||
cyanBright: (string: string) => string;
|
||||
whiteBright: (string: string) => string;
|
||||
bgBlackBright: (string: string) => string;
|
||||
bgRedBright: (string: string) => string;
|
||||
bgGreenBright: (string: string) => string;
|
||||
bgYellowBright: (string: string) => string;
|
||||
bgBlueBright: (string: string) => string;
|
||||
bgMagentaBright: (string: string) => string;
|
||||
bgCyanBright: (string: string) => string;
|
||||
bgWhiteBright: (string: string) => string;
|
||||
};
|
||||
type ColorName = keyof typeof colorDefs;
|
||||
type ColorFunction = (text: string | number) => string;
|
||||
/**
|
||||
* An object containing functions for colouring text. Each function corresponds to a terminal colour. See {@link ColorName} for available colours.
|
||||
*/
|
||||
declare const colors: Record<ColorName, ColorFunction>;
|
||||
/**
|
||||
* Gets a colour function by name, with an option for a fallback colour if the requested colour is not found.
|
||||
* @param {ColorName} color - The name of the colour function to get. See {@link ColorName}.
|
||||
* @param {ColorName} [fallback="reset"] - The name of the fallback colour function if the requested colour is not found. See {@link ColorName}.
|
||||
* @returns {ColorFunction} The colour function that corresponds to the requested colour, or the fallback colour function. See {@link ColorFunction}.
|
||||
*/
|
||||
declare function getColor(color: ColorName, fallback?: ColorName): ColorFunction;
|
||||
/**
|
||||
* Applies a specified colour to a given text string or number.
|
||||
* @param {ColorName} color - The colour to apply. See {@link ColorName}.
|
||||
* @param {string | number} text - The text to colour.
|
||||
* @returns {string} The coloured text.
|
||||
*/
|
||||
declare function colorize(color: ColorName, text: string | number): string;
|
||||
|
||||
/**
|
||||
* Removes ANSI escape codes from a given string. This is particularly useful for
|
||||
* processing text that contains formatting codes, such as colours or styles, so that the
|
||||
* the raw text without any visual formatting.
|
||||
*
|
||||
* @param {string} text - The text string from which to strip the ANSI escape codes.
|
||||
* @returns {string} The text without ANSI escape codes.
|
||||
*/
|
||||
declare function stripAnsi(text: string): string;
|
||||
/**
|
||||
* Centers a string within a specified total width, padding it with spaces or another specified character.
|
||||
* If the string is longer than the total width, it is returned as is.
|
||||
*
|
||||
* @param {string} str - The string to centre.
|
||||
* @param {number} len - The total width in which to centre the string.
|
||||
* @param {string} [space=" "] - The character to use for padding. Defaults to a space.
|
||||
* @returns {string} The centred string.
|
||||
*/
|
||||
declare function centerAlign(str: string, len: number, space?: string): string;
|
||||
/**
|
||||
* Right-justifies a string within a given total width, padding it with whitespace or another specified character.
|
||||
* If the string is longer than the total width, it is returned as is.
|
||||
*
|
||||
* @param {string} str - The string to right-justify.
|
||||
* @param {number} len - The total width to align the string.
|
||||
* @param {string} [space=" "] - The character to use for padding. Defaults to a space.
|
||||
* @returns {string} The right-justified string.
|
||||
*/
|
||||
declare function rightAlign(str: string, len: number, space?: string): string;
|
||||
/**
|
||||
* Left-aligns a string within a given total width, padding it with whitespace or another specified character on the right.
|
||||
* If the string is longer than the total width, it is returned as is.
|
||||
*
|
||||
* @param {string} str - The string to align left.
|
||||
* @param {number} len - The total width to align the string.
|
||||
* @param {string} [space=" "] - The character to use for padding. Defaults to a space.
|
||||
* @returns {string} The left-justified string.
|
||||
*/
|
||||
declare function leftAlign(str: string, len: number, space?: string): string;
|
||||
/**
|
||||
* Aligns a string (left, right, or centre) within a given total width, padding it with spaces or another specified character.
|
||||
* If the string is longer than the total width, it is returned as is. This function acts as a wrapper for individual alignment functions.
|
||||
*
|
||||
* @param {"left" | "right" | "centre"} alignment - The desired alignment of the string.
|
||||
* @param {string} str - The string to align.
|
||||
* @param {number} len - The total width in which to align the string.
|
||||
* @param {string} [space=" "] - The character to use for padding. Defaults to a space.
|
||||
* @returns {string} The aligned string, according to the given alignment.
|
||||
*/
|
||||
declare function align(alignment: "left" | "right" | "center", str: string, len: number, space?: string): string;
|
||||
|
||||
type TreeItemObject = {
|
||||
/**
|
||||
* Text of the item
|
||||
*/
|
||||
text: string;
|
||||
/**
|
||||
* Children of the item
|
||||
*/
|
||||
children?: TreeItem[];
|
||||
/**
|
||||
* Color of the item
|
||||
*/
|
||||
color?: ColorName;
|
||||
};
|
||||
type TreeItem = string | TreeItemObject;
|
||||
type TreeOptions = {
|
||||
/**
|
||||
* Color of the tree
|
||||
*/
|
||||
color?: ColorName;
|
||||
/**
|
||||
* Prefix of the tree
|
||||
*
|
||||
* @default " "
|
||||
*/
|
||||
prefix?: string;
|
||||
/**
|
||||
* The max depth of tree
|
||||
*/
|
||||
maxDepth?: number;
|
||||
/**
|
||||
* Ellipsis of the tree
|
||||
*
|
||||
* @default "..."
|
||||
*/
|
||||
ellipsis?: string;
|
||||
};
|
||||
/**
|
||||
* Formats a hierarchical list of items into a string representing a tree structure.
|
||||
* Each item in the tree can be a simple string or an object defining the text of the item,
|
||||
* optional children, and colour. The tree structure can be customised with options
|
||||
* Specify the overall colour and the prefix used for indentation and tree lines.
|
||||
*
|
||||
* @param {TreeItem[]} items - An array of items to include in the tree. Each item can be
|
||||
* either a string or an object with `text', `children' and `colour' properties.
|
||||
* @param {TreeOptions} [options] - Optional settings to customise the appearance of the tree, including
|
||||
* the colour of the tree text and the prefix for branches. See {@link TreeOptions}.
|
||||
* @returns {string} The formatted tree as a string, ready for printing to the console or elsewhere.
|
||||
*/
|
||||
declare function formatTree(items: TreeItem[], options?: TreeOptions): string;
|
||||
|
||||
export { type BoxBorderStyle, type BoxOpts, type BoxStyle, type ColorFunction, type ColorName, type TreeItem, type TreeItemObject, type TreeOptions, align, box, centerAlign, colorize, colors, formatTree, getColor, leftAlign, rightAlign, stripAnsi };
|
||||
286
node_modules/consola/dist/utils.d.ts
generated
vendored
Normal file
286
node_modules/consola/dist/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,286 @@
|
||||
type BoxBorderStyle = {
|
||||
/**
|
||||
* Top left corner
|
||||
* @example `┌`
|
||||
* @example `╔`
|
||||
* @example `╓`
|
||||
*/
|
||||
tl: string;
|
||||
/**
|
||||
* Top right corner
|
||||
* @example `┐`
|
||||
* @example `╗`
|
||||
* @example `╖`
|
||||
*/
|
||||
tr: string;
|
||||
/**
|
||||
* Bottom left corner
|
||||
* @example `└`
|
||||
* @example `╚`
|
||||
* @example `╙`
|
||||
*/
|
||||
bl: string;
|
||||
/**
|
||||
* Bottom right corner
|
||||
* @example `┘`
|
||||
* @example `╝`
|
||||
* @example `╜`
|
||||
*/
|
||||
br: string;
|
||||
/**
|
||||
* Horizontal line
|
||||
* @example `─`
|
||||
* @example `═`
|
||||
* @example `─`
|
||||
*/
|
||||
h: string;
|
||||
/**
|
||||
* Vertical line
|
||||
* @example `│`
|
||||
* @example `║`
|
||||
* @example `║`
|
||||
*/
|
||||
v: string;
|
||||
};
|
||||
declare const boxStylePresets: Record<string, BoxBorderStyle>;
|
||||
type BoxStyle = {
|
||||
/**
|
||||
* The border color
|
||||
* @default 'white'
|
||||
*/
|
||||
borderColor: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright";
|
||||
/**
|
||||
* The border style
|
||||
* @default 'solid'
|
||||
* @example 'single-double-rounded'
|
||||
* @example
|
||||
* ```ts
|
||||
* {
|
||||
* tl: '┌',
|
||||
* tr: '┐',
|
||||
* bl: '└',
|
||||
* br: '┘',
|
||||
* h: '─',
|
||||
* v: '│',
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
borderStyle: BoxBorderStyle | keyof typeof boxStylePresets;
|
||||
/**
|
||||
* The vertical alignment of the text
|
||||
* @default 'center'
|
||||
*/
|
||||
valign: "top" | "center" | "bottom";
|
||||
/**
|
||||
* The padding of the box
|
||||
* @default 2
|
||||
*/
|
||||
padding: number;
|
||||
/**
|
||||
* The left margin of the box
|
||||
* @default 1
|
||||
*/
|
||||
marginLeft: number;
|
||||
/**
|
||||
* The top margin of the box
|
||||
* @default 1
|
||||
*/
|
||||
marginTop: number;
|
||||
/**
|
||||
* The top margin of the box
|
||||
* @default 1
|
||||
*/
|
||||
marginBottom: number;
|
||||
};
|
||||
/**
|
||||
* The border options of the box
|
||||
*/
|
||||
type BoxOpts = {
|
||||
/**
|
||||
* Title that will be displayed on top of the box
|
||||
* @example 'Hello World'
|
||||
* @example 'Hello {name}'
|
||||
*/
|
||||
title?: string;
|
||||
style?: Partial<BoxStyle>;
|
||||
};
|
||||
/**
|
||||
* Creates a styled box with text content, customisable via options.
|
||||
* @param {string} text - The text to display in the box.
|
||||
* @param {BoxOpts} [_opts={}] - Optional settings for the appearance and behaviour of the box. See {@link BoxOpts}.
|
||||
* @returns {string} The formatted box as a string, ready for printing or logging.
|
||||
*/
|
||||
declare function box(text: string, _opts?: BoxOpts): string;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/jorgebucaran/colorette
|
||||
* Read LICENSE file for more information
|
||||
* https://github.com/jorgebucaran/colorette/blob/20fc196d07d0f87c61e0256eadd7831c79b24108/index.js
|
||||
*/
|
||||
declare const colorDefs: {
|
||||
reset: (string: string) => string;
|
||||
bold: (string: string) => string;
|
||||
dim: (string: string) => string;
|
||||
italic: (string: string) => string;
|
||||
underline: (string: string) => string;
|
||||
inverse: (string: string) => string;
|
||||
hidden: (string: string) => string;
|
||||
strikethrough: (string: string) => string;
|
||||
black: (string: string) => string;
|
||||
red: (string: string) => string;
|
||||
green: (string: string) => string;
|
||||
yellow: (string: string) => string;
|
||||
blue: (string: string) => string;
|
||||
magenta: (string: string) => string;
|
||||
cyan: (string: string) => string;
|
||||
white: (string: string) => string;
|
||||
gray: (string: string) => string;
|
||||
bgBlack: (string: string) => string;
|
||||
bgRed: (string: string) => string;
|
||||
bgGreen: (string: string) => string;
|
||||
bgYellow: (string: string) => string;
|
||||
bgBlue: (string: string) => string;
|
||||
bgMagenta: (string: string) => string;
|
||||
bgCyan: (string: string) => string;
|
||||
bgWhite: (string: string) => string;
|
||||
blackBright: (string: string) => string;
|
||||
redBright: (string: string) => string;
|
||||
greenBright: (string: string) => string;
|
||||
yellowBright: (string: string) => string;
|
||||
blueBright: (string: string) => string;
|
||||
magentaBright: (string: string) => string;
|
||||
cyanBright: (string: string) => string;
|
||||
whiteBright: (string: string) => string;
|
||||
bgBlackBright: (string: string) => string;
|
||||
bgRedBright: (string: string) => string;
|
||||
bgGreenBright: (string: string) => string;
|
||||
bgYellowBright: (string: string) => string;
|
||||
bgBlueBright: (string: string) => string;
|
||||
bgMagentaBright: (string: string) => string;
|
||||
bgCyanBright: (string: string) => string;
|
||||
bgWhiteBright: (string: string) => string;
|
||||
};
|
||||
type ColorName = keyof typeof colorDefs;
|
||||
type ColorFunction = (text: string | number) => string;
|
||||
/**
|
||||
* An object containing functions for colouring text. Each function corresponds to a terminal colour. See {@link ColorName} for available colours.
|
||||
*/
|
||||
declare const colors: Record<ColorName, ColorFunction>;
|
||||
/**
|
||||
* Gets a colour function by name, with an option for a fallback colour if the requested colour is not found.
|
||||
* @param {ColorName} color - The name of the colour function to get. See {@link ColorName}.
|
||||
* @param {ColorName} [fallback="reset"] - The name of the fallback colour function if the requested colour is not found. See {@link ColorName}.
|
||||
* @returns {ColorFunction} The colour function that corresponds to the requested colour, or the fallback colour function. See {@link ColorFunction}.
|
||||
*/
|
||||
declare function getColor(color: ColorName, fallback?: ColorName): ColorFunction;
|
||||
/**
|
||||
* Applies a specified colour to a given text string or number.
|
||||
* @param {ColorName} color - The colour to apply. See {@link ColorName}.
|
||||
* @param {string | number} text - The text to colour.
|
||||
* @returns {string} The coloured text.
|
||||
*/
|
||||
declare function colorize(color: ColorName, text: string | number): string;
|
||||
|
||||
/**
|
||||
* Removes ANSI escape codes from a given string. This is particularly useful for
|
||||
* processing text that contains formatting codes, such as colours or styles, so that the
|
||||
* the raw text without any visual formatting.
|
||||
*
|
||||
* @param {string} text - The text string from which to strip the ANSI escape codes.
|
||||
* @returns {string} The text without ANSI escape codes.
|
||||
*/
|
||||
declare function stripAnsi(text: string): string;
|
||||
/**
|
||||
* Centers a string within a specified total width, padding it with spaces or another specified character.
|
||||
* If the string is longer than the total width, it is returned as is.
|
||||
*
|
||||
* @param {string} str - The string to centre.
|
||||
* @param {number} len - The total width in which to centre the string.
|
||||
* @param {string} [space=" "] - The character to use for padding. Defaults to a space.
|
||||
* @returns {string} The centred string.
|
||||
*/
|
||||
declare function centerAlign(str: string, len: number, space?: string): string;
|
||||
/**
|
||||
* Right-justifies a string within a given total width, padding it with whitespace or another specified character.
|
||||
* If the string is longer than the total width, it is returned as is.
|
||||
*
|
||||
* @param {string} str - The string to right-justify.
|
||||
* @param {number} len - The total width to align the string.
|
||||
* @param {string} [space=" "] - The character to use for padding. Defaults to a space.
|
||||
* @returns {string} The right-justified string.
|
||||
*/
|
||||
declare function rightAlign(str: string, len: number, space?: string): string;
|
||||
/**
|
||||
* Left-aligns a string within a given total width, padding it with whitespace or another specified character on the right.
|
||||
* If the string is longer than the total width, it is returned as is.
|
||||
*
|
||||
* @param {string} str - The string to align left.
|
||||
* @param {number} len - The total width to align the string.
|
||||
* @param {string} [space=" "] - The character to use for padding. Defaults to a space.
|
||||
* @returns {string} The left-justified string.
|
||||
*/
|
||||
declare function leftAlign(str: string, len: number, space?: string): string;
|
||||
/**
|
||||
* Aligns a string (left, right, or centre) within a given total width, padding it with spaces or another specified character.
|
||||
* If the string is longer than the total width, it is returned as is. This function acts as a wrapper for individual alignment functions.
|
||||
*
|
||||
* @param {"left" | "right" | "centre"} alignment - The desired alignment of the string.
|
||||
* @param {string} str - The string to align.
|
||||
* @param {number} len - The total width in which to align the string.
|
||||
* @param {string} [space=" "] - The character to use for padding. Defaults to a space.
|
||||
* @returns {string} The aligned string, according to the given alignment.
|
||||
*/
|
||||
declare function align(alignment: "left" | "right" | "center", str: string, len: number, space?: string): string;
|
||||
|
||||
type TreeItemObject = {
|
||||
/**
|
||||
* Text of the item
|
||||
*/
|
||||
text: string;
|
||||
/**
|
||||
* Children of the item
|
||||
*/
|
||||
children?: TreeItem[];
|
||||
/**
|
||||
* Color of the item
|
||||
*/
|
||||
color?: ColorName;
|
||||
};
|
||||
type TreeItem = string | TreeItemObject;
|
||||
type TreeOptions = {
|
||||
/**
|
||||
* Color of the tree
|
||||
*/
|
||||
color?: ColorName;
|
||||
/**
|
||||
* Prefix of the tree
|
||||
*
|
||||
* @default " "
|
||||
*/
|
||||
prefix?: string;
|
||||
/**
|
||||
* The max depth of tree
|
||||
*/
|
||||
maxDepth?: number;
|
||||
/**
|
||||
* Ellipsis of the tree
|
||||
*
|
||||
* @default "..."
|
||||
*/
|
||||
ellipsis?: string;
|
||||
};
|
||||
/**
|
||||
* Formats a hierarchical list of items into a string representing a tree structure.
|
||||
* Each item in the tree can be a simple string or an object defining the text of the item,
|
||||
* optional children, and colour. The tree structure can be customised with options
|
||||
* Specify the overall colour and the prefix used for indentation and tree lines.
|
||||
*
|
||||
* @param {TreeItem[]} items - An array of items to include in the tree. Each item can be
|
||||
* either a string or an object with `text', `children' and `colour' properties.
|
||||
* @param {TreeOptions} [options] - Optional settings to customise the appearance of the tree, including
|
||||
* the colour of the tree text and the prefix for branches. See {@link TreeOptions}.
|
||||
* @returns {string} The formatted tree as a string, ready for printing to the console or elsewhere.
|
||||
*/
|
||||
declare function formatTree(items: TreeItem[], options?: TreeOptions): string;
|
||||
|
||||
export { type BoxBorderStyle, type BoxOpts, type BoxStyle, type ColorFunction, type ColorName, type TreeItem, type TreeItemObject, type TreeOptions, align, box, centerAlign, colorize, colors, formatTree, getColor, leftAlign, rightAlign, stripAnsi };
|
||||
54
node_modules/consola/dist/utils.mjs
generated
vendored
Normal file
54
node_modules/consola/dist/utils.mjs
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import { c as colorize } from './shared/consola.DXBYu-KD.mjs';
|
||||
export { b as align, d as box, a as centerAlign, e as colors, g as getColor, l as leftAlign, r as rightAlign, s as stripAnsi } from './shared/consola.DXBYu-KD.mjs';
|
||||
import 'node:tty';
|
||||
|
||||
function formatTree(items, options) {
|
||||
options = {
|
||||
prefix: " ",
|
||||
ellipsis: "...",
|
||||
...options
|
||||
};
|
||||
const tree = _buildTree(items, options).join("");
|
||||
if (options && options.color) {
|
||||
return colorize(options.color, tree);
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
function _buildTree(items, options) {
|
||||
const chunks = [];
|
||||
const total = items.length - 1;
|
||||
for (let i = 0; i <= total; i++) {
|
||||
const item = items[i];
|
||||
const isItemString = typeof item === "string";
|
||||
const isLimit = options?.maxDepth != null && options.maxDepth <= 0;
|
||||
if (isLimit) {
|
||||
const ellipsis = `${options.prefix}${options.ellipsis}
|
||||
`;
|
||||
return [
|
||||
isItemString ? ellipsis : item.color ? colorize(item.color, ellipsis) : ellipsis
|
||||
// prettier-ignore
|
||||
];
|
||||
}
|
||||
const isLast = i === total;
|
||||
const prefix = isLast ? `${options?.prefix}\u2514\u2500` : `${options?.prefix}\u251C\u2500`;
|
||||
if (isItemString) {
|
||||
chunks.push(`${prefix}${item}
|
||||
`);
|
||||
} else {
|
||||
const log = `${prefix}${item.text}
|
||||
`;
|
||||
chunks.push(item.color ? colorize(item.color, log) : log);
|
||||
if (item.children) {
|
||||
const _tree = _buildTree(item.children, {
|
||||
...options,
|
||||
maxDepth: options?.maxDepth == null ? void 0 : options.maxDepth - 1,
|
||||
prefix: `${options?.prefix}${isLast ? " " : "\u2502 "}`
|
||||
});
|
||||
chunks.push(..._tree);
|
||||
}
|
||||
}
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
export { colorize, formatTree };
|
||||
Reference in New Issue
Block a user