@vendure/core
Version:
A modern, headless ecommerce framework
65 lines (64 loc) • 2.6 kB
TypeScript
/**
* Minimal vendored replacement for the `progress` npm package. Trimmed to the
* exact surface used by the Importer (and by the dev-server load-testing
* benchmark scripts).
*
* Supports the format tokens Vendure templates use:
*
* `:bar` width-aware progress bar (capped to terminal columns)
* `:current` current tick count
* `:total` total tick count
* `:percent` completion percentage (e.g. "42%")
* `:etas` estimated seconds remaining (e.g. "12s")
*
* Plus arbitrary custom tokens supplied via `tick({ tokenName: value })`.
*
* Renders are throttled (default 16ms between draws) to avoid hammering the
* terminal. The bar redraws in-place using `\r` and clears the trailing line
* with `\x1B[2K`. Output goes to `process.stderr` by default to match the
* upstream `progress` package's behaviour.
*
* Deliberately omitted from the upstream surface (none of which the Importer
* uses): the `head` character on the leading edge of the bar, the `clear`
* option that wipes the bar on completion, the `:elapsed` and `:rate` tokens,
* and the `update()` method.
*
* Non-TTY behaviour (CI logs, piped output): like upstream `progress`, output
* is suppressed entirely so log files don't get peppered with `\r\x1B[2K`
* escape sequences.
*/
export interface ProgressBarOptions {
/** Total number of ticks needed to reach 100%. */
total: number;
/** Visible width of the `:bar` token, in characters. Defaults to 40. */
width?: number;
/** Character drawn for completed portion of the bar. Default `=`. */
complete?: string;
/** Character drawn for incomplete portion of the bar. Default `-`. */
incomplete?: string;
/** Minimum time between redraws, in milliseconds. Default 16. */
renderThrottle?: number;
/** Output stream. Defaults to `process.stderr`. */
stream?: NodeJS.WritableStream;
}
export declare class ProgressBar {
private readonly fmt;
private readonly total;
private readonly width;
private readonly complete;
private readonly incomplete;
private readonly renderThrottle;
private readonly stream;
private current;
private startTime;
private lastRender;
private finished;
constructor(fmt: string, options: ProgressBarOptions);
/**
* Advance by 1 (or by the supplied delta if a number is passed). When an
* object is passed, advance by 1 and substitute each entry as a custom
* format token (e.g. `:prodName`).
*/
tick(deltaOrTokens?: number | Record<string, string | number>): void;
private render;
}