@brunoluizdesiqueira/bbuilder-cli 1.0.11 → 1.0.13

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.
@@ -55,7 +55,7 @@ async function executeBuild(opts) {
55
55
  await (0, output_1.withProgress)(3, totalStages, 'Sincronizando recurso final no projeto', () => {
56
56
  fs.copyFileSync(resFile, path.win32.join(workspaceDir, `${projectName}.res`));
57
57
  });
58
- await (0, output_1.withProgress)(4, totalStages, `Compilando projeto Delphi (${opts.type})`, () => (0, compiler_1.runDcc64)(opts, projectName, workspaceDir));
58
+ await (0, output_1.withProgress)(4, totalStages, `Compilando projeto Delphi (${opts.type})`, () => (0, compiler_1.runDcc64)(opts, projectName, workspaceDir), { streamingOutput: true });
59
59
  (0, output_1.printSuccess)(opts.type);
60
60
  const { runAfter } = (0, compiler_1.buildCompilerFlags)(opts.type);
61
61
  if (runAfter) {
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,36 +114,91 @@ 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
- return ` ${chalk_1.default.cyan(`[${stage}/${total}]`)} ${chalk_1.default.yellow(spinner)} ${chalk_1.default.white(label)} ${chalk_1.default.blue(`[${bar}]`)} ${chalk_1.default.gray(elapsed)}`;
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
- async function withProgress(stage, total, label, task) {
145
+ async function withProgress(stage, total, label, task, options) {
90
146
  const startTime = Date.now();
147
+ const streamingOutput = options?.streamingOutput ?? false;
91
148
  if (!process.stdout.isTTY) {
92
149
  step(`[${stage}/${total}] ${label}`);
93
150
  const result = await task();
94
151
  console.log(` ${chalk_1.default.green('OK')} ${chalk_1.default.white(label)} ${chalk_1.default.gray(`(${formatElapsed(startTime)})`)}`);
95
152
  return result;
96
153
  }
154
+ if (streamingOutput) {
155
+ step(`[${stage}/${total}] ${label}`);
156
+ try {
157
+ const result = await task();
158
+ console.log(` ${chalk_1.default.green('OK')} ${chalk_1.default.white(label)} ${chalk_1.default.gray(`(${formatElapsed(startTime)})`)}`);
159
+ return result;
160
+ }
161
+ catch (error) {
162
+ console.log(` ${chalk_1.default.red('FAIL')} ${chalk_1.default.white(label)} ${chalk_1.default.gray(`(${formatElapsed(startTime)})`)}`);
163
+ throw error;
164
+ }
165
+ }
97
166
  let frameIndex = 0;
98
- process.stdout.write(`${renderProgressLine(stage, total, label, startTime, frameIndex)}`);
99
- const timer = setInterval(() => {
100
- frameIndex += 1;
101
- process.stdout.write(`\r${renderProgressLine(stage, total, label, startTime, frameIndex)}`);
102
- }, 120);
167
+ let rendered = false;
168
+ let timer;
169
+ const render = () => {
170
+ clearProgressLine();
171
+ drawProgressLine(renderProgressLine(stage, total, label, startTime, frameIndex));
172
+ rendered = true;
173
+ };
174
+ const startTimer = () => {
175
+ if (timer)
176
+ return;
177
+ timer = setInterval(() => {
178
+ frameIndex += 1;
179
+ render();
180
+ }, 120);
181
+ };
182
+ const initialDelay = setTimeout(() => {
183
+ render();
184
+ startTimer();
185
+ }, 180);
103
186
  try {
104
187
  const result = await task();
105
- clearInterval(timer);
106
- process.stdout.write(`\r${' '.repeat(120)}\r`);
188
+ clearTimeout(initialDelay);
189
+ if (timer)
190
+ clearInterval(timer);
191
+ if (rendered)
192
+ clearProgressLine();
107
193
  console.log(` ${chalk_1.default.green('OK')} ${chalk_1.default.white(label)} ${chalk_1.default.gray(`(${formatElapsed(startTime)})`)}`);
108
194
  return result;
109
195
  }
110
196
  catch (error) {
111
- clearInterval(timer);
112
- process.stdout.write(`\r${' '.repeat(120)}\r`);
197
+ clearTimeout(initialDelay);
198
+ if (timer)
199
+ clearInterval(timer);
200
+ if (rendered)
201
+ clearProgressLine();
113
202
  console.log(` ${chalk_1.default.red('FAIL')} ${chalk_1.default.white(label)} ${chalk_1.default.gray(`(${formatElapsed(startTime)})`)}`);
114
203
  throw error;
115
204
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brunoluizdesiqueira/bbuilder-cli",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "CLI de build local para projetos Delphi do Bimer",
5
5
  "license": "ISC",
6
6
  "repository": {