@plugjs/plug
Version:
PlugJS Build System ===================
193 lines (191 loc) • 5.67 kB
JavaScript
"use strict";
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/options.ts
var options_exports = {};
__export(options_exports, {
logOptions: () => logOptions
});
module.exports = __toCommonJS(options_exports);
var import_node_events = require("node:events");
var import_singleton = require("../utils/singleton.cjs");
var import_levels = require("./levels.cjs");
var LogOptionsImpl = class extends import_node_events.EventEmitter {
_output = process.stderr;
_level = import_levels.NOTICE;
_colors = this._output.isTTY;
_format = this._colors ? "fancy" : "plain";
_colorsSet = false;
// have colors been set manually?
_spinner = true;
// by default, the spinner is enabled
_lineLength = this._output.columns || 80;
_lineLengthSet = false;
// has line length been set manually?
_showSources = true;
// by default, always show source snippets
_githubAnnotations = false;
// ultimately set by the constructor
_inspectOptions = {};
_taskLength = 0;
_indentSize = 2;
constructor() {
super();
this.setMaxListeners(20);
if (process.env.LOG_LEVEL) {
this._level = (0, import_levels.getLevelNumber)(process.env.LOG_LEVEL);
}
if (process.env.LOG_COLORS) {
if (process.env.LOG_COLORS.toLowerCase() === "true") this.colors = true;
if (process.env.LOG_COLORS.toLowerCase() === "false") this.colors = false;
}
this._githubAnnotations = process.env.GITHUB_ACTIONS === "true";
if (this._githubAnnotations) {
this._colors = true;
this._format = "plain";
this._spinner = false;
}
const options = JSON.parse(process.env.__LOG_OPTIONS || "{}");
Object.assign(this, options);
}
_notifyListeners() {
super.emit("changed", this);
}
forkEnv(taskName) {
void taskName;
return {
__LOG_OPTIONS: JSON.stringify({
level: this._level,
colors: this._colors,
format: this._format,
lineLength: this._lineLength,
taskLength: this._taskLength,
showSources: this._showSources,
githubAnnotations: this.githubAnnotations,
indentSize: this.indentSize,
spinner: false
// forked spinner is always false
})
};
}
get output() {
return this._output;
}
set output(output) {
this._output = output;
if (!this._colorsSet) this._colors = !!output.isTTY;
if (!this._lineLengthSet) this._lineLength = output.columns;
this._notifyListeners();
}
get level() {
return this._level;
}
set level(level) {
this._level = level;
this._notifyListeners();
}
get colors() {
return this._colors;
}
set colors(color) {
this._colors = color;
this._colorsSet = true;
this._inspectOptions.colors = color;
this._notifyListeners();
}
get format() {
return this._format;
}
set format(format) {
this._format = format === "fancy" ? "fancy" : "plain";
this._notifyListeners();
}
get spinner() {
return this._spinner;
}
set spinner(spinner) {
this._spinner = spinner;
this._notifyListeners();
}
get lineLength() {
return this._lineLength;
}
set lineLength(lineLength) {
this._lineLength = lineLength;
this._lineLengthSet = true;
this._notifyListeners();
}
get taskLength() {
return this._taskLength;
}
set taskLength(taskLength) {
this._taskLength = taskLength;
this._notifyListeners();
}
get indentSize() {
return this._indentSize;
}
set indentSize(indentSize) {
this._indentSize = indentSize;
if (this._indentSize < 1) this._indentSize = 1;
this._notifyListeners();
}
get showSources() {
return this._showSources;
}
set showSources(showSources) {
this._showSources = showSources;
this._notifyListeners();
}
get githubAnnotations() {
return this._githubAnnotations;
}
set githubAnnotations(githubAnnotations) {
this._githubAnnotations = githubAnnotations;
this._notifyListeners();
}
get inspectOptions() {
return new Proxy(this._inspectOptions, {
get: (target, prop) => {
if (prop === "colors") return this.colors;
if (prop === "breakLength") return this._lineLength;
return target[prop];
},
set: (target, prop, value) => {
if (prop === "colors") {
this.colors = !!value;
} else if (prop === "breakLength") {
const length = parseInt(value);
if (isNaN(length)) return false;
this.lineLength = length;
} else {
target[prop] = value;
}
this._notifyListeners();
return true;
}
});
}
};
var optionsKey = Symbol.for("plugjs:plug:types:LogOptions");
var logOptions = (0, import_singleton.getSingleton)(optionsKey, () => new LogOptionsImpl());
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
logOptions
});
//# sourceMappingURL=options.cjs.map