jetup
Version:
Jetup: JavaScript Project Setup! Jetting-up your next JS project in seconds with one command, using fully modular, customizable presets, instantly ready to code!.
80 lines • 2.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LoggerModule = void 0;
const winston = require("winston");
const nanospinner_1 = require("nanospinner");
const named_1 = require("../base/named");
const config_1 = require("../config");
class LoggerModule extends named_1.BaseNamedModule {
constructor() {
super(...arguments);
this.registry = LoggerModule;
this.verbose = false;
}
setRegistry(registry) {
super.setRegistry(registry);
const configModule = registry.get(config_1.ConfigModule);
const config = configModule.get(this.name);
this.verbose = config.verbose;
if (this.verbose) {
this._logger = winston.createLogger({
level: 'debug',
format: winston.format.combine(winston.format.colorize({ message: true }), winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston.format.printf(({ level, message, timestamp }) => {
return `${timestamp} [${level.slice(0, 4).toUpperCase()}]: ${message}`;
})),
transports: [new winston.transports.Console()],
});
}
else {
this._logger = console;
}
}
info(...messages) {
this._getLogger().info(messages.map(String).join(' '));
}
warn(...messages) {
this._getLogger().warn(messages.map(String).join(' '));
}
error(...messages) {
this._getLogger().error(messages.map(String).join(' '));
}
debug(...messages) {
this._getLogger().debug(messages.map(String).join(' '));
}
start(text) {
if (!this.verbose) {
this._spinner = (0, nanospinner_1.createSpinner)(text);
this._spinner.info = this._spinner.update;
this._spinner.warn = this._spinner.update;
this._spinner.debug = this._spinner.update;
this._spinner.start();
}
else {
this.info(text);
}
}
stop() {
if (!this.verbose && this._spinner) {
this._spinner.stop();
}
}
end(text) {
if (!this.verbose && this._spinner) {
this._spinner.success({ text });
this._spinner = undefined;
}
else {
this.info(text);
}
}
_getLogger() {
if (!this.verbose && this._spinner) {
return this._spinner;
}
else {
return this._logger;
}
}
}
exports.LoggerModule = LoggerModule;
//# sourceMappingURL=index.js.map