1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const cli_color_1 = __importDefault(require("cli-color"));
|
7 | class Logger {
|
8 | constructor(enableColor, stdout, stderr) {
|
9 | this.color_ = !!enableColor;
|
10 | this.messages_ = [];
|
11 | this.stdout = stdout;
|
12 | this.stderr = stderr;
|
13 | }
|
14 | raw(msg, opt_color) {
|
15 | this.messages_.push(this.color_ && opt_color ? opt_color(msg) : msg);
|
16 | }
|
17 | info(msg) {
|
18 | this.raw(msg);
|
19 | }
|
20 | warn(msg) {
|
21 | this.raw(msg, cli_color_1.default.yellow);
|
22 | }
|
23 | error(msg) {
|
24 | this.raw(msg, cli_color_1.default.red);
|
25 | }
|
26 | success(msg) {
|
27 | this.raw(msg, cli_color_1.default.green);
|
28 | }
|
29 | |
30 |
|
31 |
|
32 | items(items) {
|
33 | if (items.length === 0) {
|
34 | items = ["(none)"];
|
35 | }
|
36 | this.messages_ = this.messages_.concat(items.map((item) => {
|
37 | item = `- ${item}`;
|
38 | return this.color_ ? cli_color_1.default.blackBright(item) : item;
|
39 | }, this));
|
40 | }
|
41 | |
42 |
|
43 |
|
44 |
|
45 | flush(success) {
|
46 | const out = success ? this.stdout : this.stderr;
|
47 | this.messages_.forEach((msg) => {
|
48 | out.write(`${msg}\n`);
|
49 | });
|
50 | this.empty();
|
51 | }
|
52 | |
53 |
|
54 |
|
55 | empty() {
|
56 | this.messages_ = [];
|
57 | }
|
58 | }
|
59 | exports.default = Logger;
|