@brunoluizdesiqueira/bbuilder-cli 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ui/output.js +61 -5
- package/package.json +1 -1
package/dist/ui/output.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -10,6 +43,7 @@ exports.step = step;
|
|
|
10
43
|
exports.withProgress = withProgress;
|
|
11
44
|
exports.fatal = fatal;
|
|
12
45
|
const chalk_1 = __importDefault(require("chalk"));
|
|
46
|
+
const readline = __importStar(require("readline"));
|
|
13
47
|
const SPINNER_FRAMES = ['|', '/', '-', '\\'];
|
|
14
48
|
const BAR_WIDTH = 18;
|
|
15
49
|
const BAR_SEGMENT = 6;
|
|
@@ -80,11 +114,33 @@ function buildIndeterminateBar(frameIndex) {
|
|
|
80
114
|
}
|
|
81
115
|
return chars.join('');
|
|
82
116
|
}
|
|
117
|
+
function truncateLabel(label, maxLength) {
|
|
118
|
+
if (maxLength <= 0)
|
|
119
|
+
return '';
|
|
120
|
+
if (label.length <= maxLength)
|
|
121
|
+
return label;
|
|
122
|
+
if (maxLength <= 1)
|
|
123
|
+
return label.slice(0, maxLength);
|
|
124
|
+
return `${label.slice(0, maxLength - 1)}…`;
|
|
125
|
+
}
|
|
83
126
|
function renderProgressLine(stage, total, label, startTime, frameIndex) {
|
|
84
127
|
const spinner = SPINNER_FRAMES[frameIndex % SPINNER_FRAMES.length];
|
|
85
128
|
const bar = buildIndeterminateBar(frameIndex);
|
|
86
129
|
const elapsed = formatElapsed(startTime);
|
|
87
|
-
|
|
130
|
+
const columns = process.stdout.columns || 100;
|
|
131
|
+
const reservedLength = 2 + `[${stage}/${total}]`.length + 1 + 1 + 1 + 1 + 1 + (BAR_WIDTH + 2) + 1 + elapsed.length;
|
|
132
|
+
const maxLabelLength = Math.max(12, columns - reservedLength);
|
|
133
|
+
const safeLabel = truncateLabel(label, maxLabelLength);
|
|
134
|
+
return ` ${chalk_1.default.cyan(`[${stage}/${total}]`)} ${chalk_1.default.yellow(spinner)} ${chalk_1.default.white(safeLabel)} ${chalk_1.default.blue(`[${bar}]`)} ${chalk_1.default.gray(elapsed)}`;
|
|
135
|
+
}
|
|
136
|
+
function drawProgressLine(line) {
|
|
137
|
+
readline.clearLine(process.stdout, 0);
|
|
138
|
+
readline.cursorTo(process.stdout, 0);
|
|
139
|
+
process.stdout.write(line);
|
|
140
|
+
}
|
|
141
|
+
function clearProgressLine() {
|
|
142
|
+
readline.clearLine(process.stdout, 0);
|
|
143
|
+
readline.cursorTo(process.stdout, 0);
|
|
88
144
|
}
|
|
89
145
|
async function withProgress(stage, total, label, task) {
|
|
90
146
|
const startTime = Date.now();
|
|
@@ -95,21 +151,21 @@ async function withProgress(stage, total, label, task) {
|
|
|
95
151
|
return result;
|
|
96
152
|
}
|
|
97
153
|
let frameIndex = 0;
|
|
98
|
-
|
|
154
|
+
drawProgressLine(renderProgressLine(stage, total, label, startTime, frameIndex));
|
|
99
155
|
const timer = setInterval(() => {
|
|
100
156
|
frameIndex += 1;
|
|
101
|
-
|
|
157
|
+
drawProgressLine(renderProgressLine(stage, total, label, startTime, frameIndex));
|
|
102
158
|
}, 120);
|
|
103
159
|
try {
|
|
104
160
|
const result = await task();
|
|
105
161
|
clearInterval(timer);
|
|
106
|
-
|
|
162
|
+
clearProgressLine();
|
|
107
163
|
console.log(` ${chalk_1.default.green('OK')} ${chalk_1.default.white(label)} ${chalk_1.default.gray(`(${formatElapsed(startTime)})`)}`);
|
|
108
164
|
return result;
|
|
109
165
|
}
|
|
110
166
|
catch (error) {
|
|
111
167
|
clearInterval(timer);
|
|
112
|
-
|
|
168
|
+
clearProgressLine();
|
|
113
169
|
console.log(` ${chalk_1.default.red('FAIL')} ${chalk_1.default.white(label)} ${chalk_1.default.gray(`(${formatElapsed(startTime)})`)}`);
|
|
114
170
|
throw error;
|
|
115
171
|
}
|