fixclosure
Version:
JavaScript dependency checker/fixer for Closure Library based on ECMAScript AST
60 lines (59 loc) • 1.64 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const cli_color_1 = __importDefault(require("cli-color"));
class Logger {
constructor(enableColor, stdout, stderr) {
this.color_ = !!enableColor;
this.messages_ = [];
this.stdout = stdout;
this.stderr = stderr;
}
raw(msg, opt_color) {
this.messages_.push(this.color_ && opt_color ? opt_color(msg) : msg);
}
info(msg) {
this.raw(msg);
}
warn(msg) {
this.raw(msg, cli_color_1.default.yellow);
}
error(msg) {
this.raw(msg, cli_color_1.default.red);
}
success(msg) {
this.raw(msg, cli_color_1.default.green);
}
/**
* Log items with black bright.
*/
items(items) {
if (items.length === 0) {
items = ["(none)"];
}
this.messages_ = this.messages_.concat(items.map((item) => {
item = `- ${item}`;
return this.color_ ? cli_color_1.default.blackBright(item) : item;
}, this));
}
/**
* Flush out all stored messages.
* @param success If true, flush to stdout. Otherwise to stderr.
*/
flush(success) {
const out = success ? this.stdout : this.stderr;
this.messages_.forEach((msg) => {
out.write(`${msg}\n`);
});
this.empty();
}
/**
* Clear all stored messages.
*/
empty() {
this.messages_ = [];
}
}
exports.default = Logger;