UNPKG

3.92 kBJavaScriptView Raw
1"use strict";
2/* eslint-disable no-underscore-dangle, no-console */
3var __extends = (this && this.__extends) || (function () {
4 var extendStatics = function (d, b) {
5 extendStatics = Object.setPrototypeOf ||
6 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7 function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8 return extendStatics(d, b);
9 };
10 return function (d, b) {
11 if (typeof b !== "function" && b !== null)
12 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13 extendStatics(d, b);
14 function __() { this.constructor = d; }
15 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16 };
17})();
18var __importDefault = (this && this.__importDefault) || function (mod) {
19 return (mod && mod.__esModule) ? mod : { "default": mod };
20};
21Object.defineProperty(exports, "__esModule", { value: true });
22exports.wasReported = exports.log = void 0;
23var progress_1 = __importDefault(require("progress"));
24var assert_1 = __importDefault(require("assert"));
25var chalk_1 = __importDefault(require("chalk"));
26var Log = /** @class */ (function () {
27 function Log() {
28 this.debugMode = false;
29 }
30 Log.prototype.lines = function (lines) {
31 if (lines === undefined) {
32 return;
33 }
34 if (!Array.isArray(lines)) {
35 console.log(" " + lines);
36 return;
37 }
38 for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
39 var line = lines_1[_i];
40 console.log(" " + line);
41 }
42 };
43 Log.prototype.debug = function (text, lines) {
44 if (!this.debugMode) {
45 return;
46 }
47 console.log("> " + chalk_1.default.green('[debug]') + " " + text);
48 this.lines(lines);
49 };
50 Log.prototype.info = function (text, lines) {
51 console.log("> " + text);
52 this.lines(lines);
53 };
54 Log.prototype.warn = function (text, lines) {
55 console.log("> " + chalk_1.default.blue('Warning') + " " + text);
56 this.lines(lines);
57 };
58 Log.prototype.error = function (text, lines) {
59 var message = text instanceof Error ? text.stack : text;
60 console.log("> " + chalk_1.default.red('Error!') + " " + message);
61 this.lines(lines);
62 };
63 Log.prototype.enableProgress = function (text) {
64 assert_1.default(!this.bar);
65 text += ' '.repeat(35 - text.length);
66 this.bar = new progress_1.default(" " + text + " [:bar] :percent", {
67 stream: process.stdout,
68 width: 20,
69 complete: '=',
70 incomplete: ' ',
71 total: 100,
72 });
73 };
74 Log.prototype.showProgress = function (percentage) {
75 if (!this.bar) {
76 return;
77 }
78 this.bar.update(percentage / 100);
79 };
80 Log.prototype.disableProgress = function () {
81 if (!this.bar) {
82 return;
83 }
84 // avoid empty line
85 if (!this.bar.complete) {
86 this.bar.terminate();
87 }
88 delete this.bar;
89 };
90 return Log;
91}());
92exports.log = new Log();
93var ReportedError = /** @class */ (function (_super) {
94 __extends(ReportedError, _super);
95 function ReportedError() {
96 var _this = _super !== null && _super.apply(this, arguments) || this;
97 _this.name = 'ReportedError';
98 _this.wasReported = true;
99 return _this;
100 }
101 return ReportedError;
102}(Error));
103function wasReported(error, lines) {
104 var reportedError = new ReportedError('No message');
105 if (typeof error === 'string') {
106 exports.log.error(error, lines);
107 reportedError = new ReportedError(error);
108 }
109 return reportedError;
110}
111exports.wasReported = wasReported;
112//# sourceMappingURL=log.js.map
\No newline at end of file