@playlyfe/babel-loader
Version:
babel module loader for webpack
102 lines (77 loc) • 2.37 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.info = info;
exports.default = void 0;
var _console = require("console");
var _chalk = _interopRequireDefault(require("chalk"));
var _ansiStyles = _interopRequireDefault(require("ansi-styles"));
var _ansiEscapes = require("ansi-escapes");
/* global stream$Writable, tty$WriteStream, $npm$chalk$StyleElement */
// $FlowIssue: console is node native module
function info(msg) {
return _ansiEscapes.eraseLine + (0, _ansiEscapes.cursorTo)(0) + _chalk.default.gray(msg);
}
class Log {
constructor(name, stream = process.stderr) {
this.console = void 0;
this.name = void 0;
this.stream = void 0;
this.colors = void 0;
this.name = name;
this.stream = stream;
this.console = new _console.Console(stream);
this.colors = {
info: _ansiStyles.default.gray,
error: _ansiStyles.default.red,
warn: _ansiStyles.default.yellow
};
}
_color(msg) {
return `${this.colors.info.open}${msg}${this.colors.info.close}`;
}
_msg(str, prependName = true) {
return prependName ? `${_chalk.default.bold(`[${this.name}]`)} ${str}` : str;
}
clearLine() {
this.stream.write(_ansiEscapes.eraseLine + (0, _ansiEscapes.cursorTo)(0));
}
info(msg, prependName) {
this.stream.write(this.colors.info.open);
this.console.log(this._msg(msg, prependName));
this.stream.write(this.colors.info.close);
}
warn(msg, prependName = true) {
this.stream.write(this.colors.warn.open);
if (prependName) {
this.write('', true);
}
this.console.warn(msg);
this.stream.write(this.colors.warn.close);
}
error(msg, prependName = true) {
this.stream.write(this.colors.error.open);
if (prependName) {
this.write('', true);
}
this.console.error(msg);
this.stream.write(this.colors.error.close);
}
write(msg, prependName) {
this.stream.write(this._msg(msg, prependName));
}
time(key) {
this.console.time(key);
}
timeEnd(key, prependName = true) {
this.stream.write(this.colors.info.open);
if (prependName) {
this.write('', true);
}
this.console.timeEnd(key);
this.stream.write(this.colors.info.close);
}
}
exports.default = Log;