-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathprogressBar.mjs
More file actions
31 lines (26 loc) · 892 Bytes
/
progressBar.mjs
File metadata and controls
31 lines (26 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';
import { PassThrough } from 'node:stream';
import { SingleBar, Presets } from 'cli-progress';
/**
* Creates a progress bar for the generation pipeline.
* Writes to stderr to avoid conflicts with the logger (stdout).
* When disabled or stderr is not a TTY (e.g. CI), output is sent
* to a PassThrough stream (silently discarded).
*
* @param {object} [options]
* @param {boolean} [options.enabled=true] Whether to render the progress bar
* @returns {SingleBar}
*/
const createProgressBar = ({ enabled = true } = {}) => {
const shouldEnable = enabled && process.stderr.isTTY;
return new SingleBar(
{
stream: shouldEnable ? process.stderr : new PassThrough(),
format: ' {phase} [{bar}] {percentage}% | {value}/{total}',
hideCursor: true,
clearOnComplete: false,
},
Presets.shades_grey
);
};
export default createProgressBar;