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_table_1 = __importDefault(require("cli-table"));
|
7 | const prettyjson_1 = __importDefault(require("prettyjson"));
|
8 | const pretty_error_1 = __importDefault(require("pretty-error"));
|
9 | const chalk_1 = __importDefault(require("chalk"));
|
10 | class Output {
|
11 | constructor() {
|
12 | this.exitCode = 0;
|
13 | this.data = [];
|
14 | this.prettyError = new pretty_error_1.default();
|
15 | }
|
16 | static create() {
|
17 | return new this();
|
18 | }
|
19 | static errorOutput(error, exitCode) {
|
20 | const output = new this();
|
21 | output.error(error, exitCode);
|
22 | return output;
|
23 | }
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | setExitCode(exitCode) {
|
47 | this.exitCode = exitCode;
|
48 | return this;
|
49 | }
|
50 | addData(...data) {
|
51 | data.forEach(item => {
|
52 | if (item === undefined) {
|
53 | return;
|
54 | }
|
55 | if (item.constructor === Object) {
|
56 | return this.addData(prettyjson_1.default.render(item));
|
57 | }
|
58 | this.data.push(item);
|
59 | });
|
60 | return this;
|
61 | }
|
62 | success(message, data) {
|
63 | this.addData(chalk_1.default `\n {green {bold Success!}} ${message}\n`, data);
|
64 | }
|
65 | resetData() {
|
66 | this.data = [];
|
67 | return this;
|
68 | }
|
69 | addHorizontalTable(head, data, options = {}) {
|
70 | const table = new cli_table_1.default(Object.assign({ head }, options));
|
71 | table.push(...data);
|
72 | this.addData(table.toString());
|
73 | return this;
|
74 | }
|
75 | addVerticalTable(data, options) {
|
76 | const table = new cli_table_1.default(options);
|
77 | table.push(...data);
|
78 | this.addData(table.toString());
|
79 | return this;
|
80 | }
|
81 | addCrossTable(head, data, options = {}) {
|
82 | const table = new cli_table_1.default(options);
|
83 | table.push(...data);
|
84 | this.addData(table.toString());
|
85 | return this;
|
86 | }
|
87 | |
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | error(error = 'Unknown error', exitCode = 1, clear = false) {
|
97 | if (!this.prettyError) {
|
98 | this.prettyError = new pretty_error_1.default();
|
99 | }
|
100 | if (exitCode) {
|
101 | this.setExitCode(exitCode);
|
102 | }
|
103 | if (clear) {
|
104 | this.resetData();
|
105 | }
|
106 | this.addData(this.prettyError.render(error));
|
107 | return this;
|
108 | }
|
109 | |
110 |
|
111 |
|
112 | flush() {
|
113 | this.data.forEach((piece) => console.log(piece));
|
114 | }
|
115 | send() {
|
116 | this.flush();
|
117 | process.exit(this.exitCode);
|
118 | }
|
119 | }
|
120 | exports.Output = Output;
|
121 |
|
\ | No newline at end of file |