@storm-software/config-tools
Version:
A package containing various utilities to support custom workspace configurations and environment management for Storm Software projects, including configuration file handling, environment variable management, and logging utilities.
159 lines (132 loc) • 8.68 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunkKH5SONKWcjs = require('./chunk-KH5SONKW.cjs');
var _chunkCTYIEJ7Ccjs = require('./chunk-CTYIEJ7C.cjs');
var _chunkWBQ4VS7Ecjs = require('./chunk-WBQ4VS7E.cjs');
var _chunkBN6MEGGYcjs = require('./chunk-BN6MEGGY.cjs');
var _chunk4PX5UVANcjs = require('./chunk-4PX5UVAN.cjs');
var _chunkIRCFHYKZcjs = require('./chunk-IRCFHYKZ.cjs');
// src/logger/console.ts
var getLogFn = (logLevel = _chunkIRCFHYKZcjs.LogLevel.INFO, config = {}, _chalk = _chunkCTYIEJ7Ccjs.getChalk.call(void 0, )) => {
const colors = !_optionalChain([config, 'access', _2 => _2.colors, 'optionalAccess', _3 => _3.dark]) && !_optionalChain([config, 'access', _4 => _4.colors, 'optionalAccess', _5 => _5["base"]]) && !_optionalChain([config, 'access', _6 => _6.colors, 'optionalAccess', _7 => _7["base"], 'optionalAccess', _8 => _8.dark]) ? _chunkKH5SONKWcjs.DEFAULT_COLOR_CONFIG : _optionalChain([config, 'access', _9 => _9.colors, 'optionalAccess', _10 => _10.dark]) && typeof config.colors.dark === "string" ? config.colors : _optionalChain([config, 'access', _11 => _11.colors, 'optionalAccess', _12 => _12["base"], 'optionalAccess', _13 => _13.dark]) && typeof config.colors["base"].dark === "string" ? config.colors["base"].dark : _optionalChain([config, 'access', _14 => _14.colors, 'optionalAccess', _15 => _15["base"]]) ? _optionalChain([config, 'access', _16 => _16.colors, 'optionalAccess', _17 => _17["base"]]) : _chunkKH5SONKWcjs.DEFAULT_COLOR_CONFIG;
const configLogLevel = config.logLevel || process.env.STORM_LOG_LEVEL || _chunkIRCFHYKZcjs.LogLevelLabel.INFO;
if (logLevel > _chunk4PX5UVANcjs.getLogLevel.call(void 0, configLogLevel) || logLevel <= _chunkIRCFHYKZcjs.LogLevel.SILENT || _chunk4PX5UVANcjs.getLogLevel.call(void 0, configLogLevel) <= _chunkIRCFHYKZcjs.LogLevel.SILENT) {
return (_) => {
};
}
if (typeof logLevel === "number" && _chunkIRCFHYKZcjs.LogLevel.FATAL >= logLevel) {
return (message) => {
console.error(
`
${_chalk.gray(_chunkBN6MEGGYcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.fatal, () => ( "#7d1a1a")))(`[${_chunkWBQ4VS7Ecjs.CONSOLE_ICONS[_chunkIRCFHYKZcjs.LogLevelLabel.FATAL]} Fatal] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
);
};
}
if (typeof logLevel === "number" && _chunkIRCFHYKZcjs.LogLevel.ERROR >= logLevel) {
return (message) => {
console.error(
`
${_chalk.gray(_chunkBN6MEGGYcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.danger, () => ( "#f85149")))(`[${_chunkWBQ4VS7Ecjs.CONSOLE_ICONS[_chunkIRCFHYKZcjs.LogLevelLabel.ERROR]} Error] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
);
};
}
if (typeof logLevel === "number" && _chunkIRCFHYKZcjs.LogLevel.WARN >= logLevel) {
return (message) => {
console.warn(
`
${_chalk.gray(_chunkBN6MEGGYcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.warning, () => ( "#e3b341")))(`[${_chunkWBQ4VS7Ecjs.CONSOLE_ICONS[_chunkIRCFHYKZcjs.LogLevelLabel.WARN]} Warn] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
);
};
}
if (typeof logLevel === "number" && _chunkIRCFHYKZcjs.LogLevel.SUCCESS >= logLevel) {
return (message) => {
console.info(
`
${_chalk.gray(_chunkBN6MEGGYcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.success, () => ( "#56d364")))(`[${_chunkWBQ4VS7Ecjs.CONSOLE_ICONS[_chunkIRCFHYKZcjs.LogLevelLabel.SUCCESS]} Success] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
);
};
}
if (typeof logLevel === "number" && _chunkIRCFHYKZcjs.LogLevel.INFO >= logLevel) {
return (message) => {
console.info(
`
${_chalk.gray(_chunkBN6MEGGYcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.info, () => ( "#58a6ff")))(`[${_chunkWBQ4VS7Ecjs.CONSOLE_ICONS[_chunkIRCFHYKZcjs.LogLevelLabel.INFO]} Info] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
);
};
}
if (typeof logLevel === "number" && _chunkIRCFHYKZcjs.LogLevel.DEBUG >= logLevel) {
return (message) => {
console.debug(
`
${_chalk.gray(_chunkBN6MEGGYcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.brand, () => ( "#1fb2a6")))(`[${_chunkWBQ4VS7Ecjs.CONSOLE_ICONS[_chunkIRCFHYKZcjs.LogLevelLabel.DEBUG]} Debug] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
);
};
}
if (typeof logLevel === "number" && _chunkIRCFHYKZcjs.LogLevel.TRACE >= logLevel) {
return (message) => {
console.debug(
`
${_chalk.gray(_chunkBN6MEGGYcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.brand, () => ( "#1fb2a6")))(`[${_chunkWBQ4VS7Ecjs.CONSOLE_ICONS[_chunkIRCFHYKZcjs.LogLevelLabel.TRACE]} Trace] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
);
};
}
return (message) => {
console.log(
`
${_chalk.gray(_chunkBN6MEGGYcjs.formatTimestamp.call(void 0, ))} ${_chalk.hex(_nullishCoalesce(colors.brand, () => ( "#1fb2a6")))(`[${_chunkWBQ4VS7Ecjs.CONSOLE_ICONS[_chunkIRCFHYKZcjs.LogLevelLabel.ALL]} System] `)}${_chalk.bold.whiteBright(formatLogMessage(message))}
`
);
};
};
var writeFatal = (message, config) => getLogFn(_chunkIRCFHYKZcjs.LogLevel.FATAL, config)(message);
var writeError = (message, config) => getLogFn(_chunkIRCFHYKZcjs.LogLevel.ERROR, config)(message);
var writeWarning = (message, config) => getLogFn(_chunkIRCFHYKZcjs.LogLevel.WARN, config)(message);
var writeInfo = (message, config) => getLogFn(_chunkIRCFHYKZcjs.LogLevel.INFO, config)(message);
var writeSuccess = (message, config) => getLogFn(_chunkIRCFHYKZcjs.LogLevel.SUCCESS, config)(message);
var writeDebug = (message, config) => getLogFn(_chunkIRCFHYKZcjs.LogLevel.DEBUG, config)(message);
var writeTrace = (message, config) => getLogFn(_chunkIRCFHYKZcjs.LogLevel.TRACE, config)(message);
var writeSystem = (message, config) => getLogFn(_chunkIRCFHYKZcjs.LogLevel.ALL, config)(message);
var getStopwatch = (name) => {
const start = process.hrtime();
return () => {
const end = process.hrtime(start);
console.info(
`
> \u23F1\uFE0F The${name ? ` ${name}` : ""} process took ${Math.round(
end[0] * 1e3 + end[1] / 1e6
)}ms to complete
`
);
};
};
var MAX_DEPTH = 4;
var formatLogMessage = (message, options = {}, depth = 0) => {
if (depth > MAX_DEPTH) {
return "<max depth>";
}
const prefix = _nullishCoalesce(options.prefix, () => ( "-"));
const skip = _nullishCoalesce(options.skip, () => ( []));
return typeof message === "undefined" || message === null || !message && typeof message !== "boolean" ? "<none>" : typeof message === "string" ? message : Array.isArray(message) ? `
${message.map((item, index) => ` ${prefix}> #${index} = ${formatLogMessage(item, { prefix: `${prefix}-`, skip }, depth + 1)}`).join("\n")}` : typeof message === "object" ? `
${Object.keys(message).filter((key) => !skip.includes(key)).map(
(key) => ` ${prefix}> ${key} = ${_isFunction(message[key]) ? "<function>" : typeof message[key] === "object" ? formatLogMessage(
message[key],
{ prefix: `${prefix}-`, skip },
depth + 1
) : message[key]}`
).join("\n")}` : message;
};
var _isFunction = (value) => {
try {
return value instanceof Function || typeof value === "function" || !!(_optionalChain([value, 'optionalAccess', _18 => _18.constructor]) && _optionalChain([value, 'optionalAccess', _19 => _19.call]) && _optionalChain([value, 'optionalAccess', _20 => _20.apply]));
} catch (e) {
return false;
}
};
exports.getLogFn = getLogFn; exports.writeFatal = writeFatal; exports.writeError = writeError; exports.writeWarning = writeWarning; exports.writeInfo = writeInfo; exports.writeSuccess = writeSuccess; exports.writeDebug = writeDebug; exports.writeTrace = writeTrace; exports.writeSystem = writeSystem; exports.getStopwatch = getStopwatch; exports.formatLogMessage = formatLogMessage;