@plugjs/plug
Version:
PlugJS Build System ===================
135 lines (133 loc) • 6.26 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// logging/emit.ts
var emit_exports = {};
__export(emit_exports, {
emit: () => emit2,
emitFancy: () => emitFancy,
emitForked: () => emitForked,
emitPlain: () => emitPlain
});
module.exports = __toCommonJS(emit_exports);
var import_node_util = require("node:util");
var import_asserts = require("../asserts.cjs");
var import_colors = require("./colors.cjs");
var import_levels = require("./levels.cjs");
var import_options = require("./options.cjs");
var import_spinner = require("./spinner.cjs");
var _output = import_options.logOptions.output;
var _indentSize = import_options.logOptions.indentSize;
var _taskLength = import_options.logOptions.taskLength;
var _lineLength = import_options.logOptions.lineLength;
var _inspectOptions = { ...import_options.logOptions.inspectOptions };
import_options.logOptions.on("changed", (options) => {
_output = options.output;
_indentSize = options.indentSize;
_taskLength = options.taskLength;
_lineLength = options.lineLength;
_inspectOptions = { ...options.inspectOptions };
_defaultEmitter = options.format === "fancy" ? emitFancy : options.format === "plain" ? emitPlain : (0, import_asserts.fail)(`Invalid log format "${import_options.logOptions.format}"`);
});
var emitFancy = (options, args) => {
const { taskName, level, prefix = "", indent = 0 } = options;
const logPrefix = "".padStart(indent * _indentSize) + prefix;
const prefixes = [];
prefixes.push("".padStart(_taskLength - taskName.length, " "));
prefixes.push(`${(0, import_colors.$t)(taskName, false)}`);
if (level <= import_levels.TRACE) {
prefixes.push(` ${(0, import_colors.$gry)("\u25A1")} `);
} else if (level <= import_levels.DEBUG) {
prefixes.push(` ${(0, import_colors.$gry)("\u25A0")} `);
} else if (level <= import_levels.INFO) {
prefixes.push(` ${(0, import_colors.$grn)("\u25A0")} `);
} else if (level <= import_levels.NOTICE) {
prefixes.push(` ${(0, import_colors.$blu)("\u25A0")} `);
} else if (level <= import_levels.WARN) {
prefixes.push(` ${(0, import_colors.$ylw)("\u25A0")} `);
} else {
prefixes.push(` ${(0, import_colors.$red)("\u25A0")} `);
}
prefixes.push(logPrefix);
const linePrefix = prefixes.join("");
const breakLength = _lineLength - _taskLength - logPrefix.length - 3;
const message = (0, import_node_util.formatWithOptions)({ ..._inspectOptions, breakLength }, ...args);
for (const line of message.split("\n")) {
_output.write(`${import_spinner.zapSpinner}${linePrefix}${line}
`);
}
};
var emitPlain = (options, args) => {
const { taskName, level, prefix = "", indent = 0 } = options;
const logPrefix = "".padStart(indent * _indentSize) + prefix;
const prefixes = [];
const pad = "".padStart(_taskLength - taskName.length, " ");
prefixes.push(`${pad}${(0, import_colors.$t)(taskName, false)}`);
if (level <= import_levels.TRACE) {
prefixes.push(` ${(0, import_colors.$gry)("\u2502")} ${(0, import_colors.$gry)(" trace")} ${(0, import_colors.$gry)("\u2502")} `);
} else if (level <= import_levels.DEBUG) {
prefixes.push(` ${(0, import_colors.$gry)("\u2502")} ${(0, import_colors.$gry)(" debug")} ${(0, import_colors.$gry)("\u2502")} `);
} else if (level <= import_levels.INFO) {
prefixes.push(` ${(0, import_colors.$gry)("\u2502")} ${(0, import_colors.$grn)(" info")} ${(0, import_colors.$gry)("\u2502")} `);
} else if (level <= import_levels.NOTICE) {
prefixes.push(` ${(0, import_colors.$gry)("\u2502")} ${(0, import_colors.$blu)("notice")} ${(0, import_colors.$gry)("\u2502")} `);
} else if (level <= import_levels.WARN) {
prefixes.push(` ${(0, import_colors.$gry)("\u2502")} ${(0, import_colors.$ylw)(" warn")} ${(0, import_colors.$gry)("\u2502")} `);
} else {
prefixes.push(` ${(0, import_colors.$gry)("\u2502")} ${(0, import_colors.$red)(" error")} ${(0, import_colors.$gry)("\u2502")} `);
}
prefixes.push(logPrefix);
const linePrefix = prefixes.join("");
const breakLength = _lineLength - _taskLength - logPrefix.length - 12;
const message = (0, import_node_util.formatWithOptions)({ ..._inspectOptions, breakLength }, ...args);
for (const line of message.split("\n")) {
_output.write(`${linePrefix}${line}
`);
}
};
var emitForked = (options, args) => {
if (process.connected && process.send) {
const { taskName, level, prefix = "", indent = 0 } = options;
const linePrefix = "".padStart(indent * _indentSize) + prefix;
const breakLength = _lineLength - _taskLength - linePrefix.length - 20;
const message = (0, import_node_util.formatWithOptions)({ ..._inspectOptions, breakLength }, ...args);
const lines = message.split("\n").map((line) => `${linePrefix}${line}`);
process.send({ logLevel: level, taskName, lines });
} else {
_defaultEmitter(options, args);
}
};
var _defaultEmitter = import_options.logOptions.format === "fancy" ? emitFancy : import_options.logOptions.format === "plain" ? emitPlain : (0, import_asserts.fail)(`Invalid log format "${import_options.logOptions.format}"`);
var _emitter = _defaultEmitter;
var wrapper = function emit(options, args) {
_defaultEmitter(options, args);
};
var emit2 = Object.defineProperty(wrapper, "emitter", {
get: () => _emitter,
set: (emitter) => {
_emitter = emitter || _defaultEmitter;
}
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
emit,
emitFancy,
emitForked,
emitPlain
});
//# sourceMappingURL=emit.cjs.map