es-node-runner
Version:
Node runner that transpiles typescript or es modules using blazing fast ⚡ esbuild and restarts the process automatically on change. Suitable for node development server.
59 lines (58 loc) • 1.6 kB
JavaScript
import {Console} from 'console';
import {spawnOptions} from '../config.js';
var COLORS;
(function (COLORS) {
COLORS['gray'] = '242m';
COLORS['blue'] = '45m';
COLORS['green'] = '46m';
COLORS['red'] = '196m';
COLORS['yellow'] = '227m';
COLORS['orange'] = '208m';
COLORS['magenta'] = '207m';
})(COLORS || (COLORS = {}));
class Logger extends Console {
constructor() {
super(process.stdout, process.stderr, false);
this.printToConsole = (message, optionalParams, color) => {
super.log(
`\x1B[38;5;${COLORS[color]}${message}\x1B[0m`,
...optionalParams
);
};
if (!process.stdout.isTTY) {
this.printToConsole = (message, optionalParams) => {
super.log(message, ...optionalParams);
};
}
}
log(message, ...optionalParams) {
this.printToConsole(message, optionalParams, 'gray');
}
info(message, ...optionalParams) {
this.printToConsole(message, optionalParams, 'blue');
}
warn(message, ...optionalParams) {
this.printToConsole(message, optionalParams, 'yellow');
}
error(message, ...optionalParams) {
this.printToConsole(message, optionalParams, 'red');
}
success(message, ...optionalParams) {
this.printToConsole(message, optionalParams, 'green');
}
alert(message, ...optionalParams) {
this.printToConsole(message, optionalParams, 'orange');
}
}
const noop = () => undefined;
const logger = spawnOptions.logging
? new Logger()
: {
log: noop,
info: noop,
warn: noop,
error: noop,
success: noop,
alert: noop,
};
export default logger;