servicemap 0.1.15 → 0.1.16
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/bin/servicemap.mjs +18 -5
- package/package.json +1 -1
package/bin/servicemap.mjs
CHANGED
|
@@ -475,7 +475,13 @@ function runSilent(command, args, options = {}) {
|
|
|
475
475
|
});
|
|
476
476
|
}
|
|
477
477
|
|
|
478
|
-
|
|
478
|
+
function wait(ms) {
|
|
479
|
+
return new Promise((resolvePromise) => {
|
|
480
|
+
setTimeout(resolvePromise, ms);
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
async function withSpinner(message, action, minimumMs = 900) {
|
|
479
485
|
if (!process.stdout.isTTY) {
|
|
480
486
|
return action();
|
|
481
487
|
}
|
|
@@ -483,15 +489,22 @@ async function withSpinner(message, action) {
|
|
|
483
489
|
const frames = ['◒', '◐', '◓', '◑'];
|
|
484
490
|
let frame = 0;
|
|
485
491
|
let dots = '';
|
|
486
|
-
|
|
487
|
-
const
|
|
492
|
+
const startedAt = Date.now();
|
|
493
|
+
const writeFrame = () => {
|
|
488
494
|
process.stdout.write(`\r\x1b[J${frames[frame]} ${message}${dots}`);
|
|
489
495
|
frame = (frame + 1) % frames.length;
|
|
490
496
|
if (frame === 0) dots = dots.length >= 5 ? '' : `${dots}.`;
|
|
491
|
-
}
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
process.stdout.write('\x1b[?25l');
|
|
500
|
+
writeFrame();
|
|
501
|
+
const interval = setInterval(writeFrame, 120);
|
|
492
502
|
|
|
493
503
|
try {
|
|
494
|
-
|
|
504
|
+
const result = await action();
|
|
505
|
+
const remainingMs = minimumMs - (Date.now() - startedAt);
|
|
506
|
+
if (remainingMs > 0) await wait(remainingMs);
|
|
507
|
+
return result;
|
|
495
508
|
} finally {
|
|
496
509
|
clearInterval(interval);
|
|
497
510
|
process.stdout.write('\r\x1b[J\x1b[?25h');
|