frontend/.pnpm-store/v3/files/70/f485faf1a80c12e35bde6d123a70645b31d9cd49bc1f6d3f204c83167a81e9fd4d07dd64555e21159982550897c4484ebabfb2283ecc268b27dbc719ee1e3f

30 lines
803 B
Plaintext

import { oraPromise } from 'ora';
import { format } from './util.js';
const noop = Promise.resolve();
class Spinner {
constructor({ container = {} } = {}) {
this.config = container.config;
this.ora = container.ora || oraPromise;
}
show({ enabled = true, task, label, external = false, context }) {
if (!enabled) return noop;
const { config } = this;
this.isSpinnerDisabled = !config.isCI || config.isVerbose || config.isDryRun || config.isDebug;
this.canForce = !config.isCI && !config.isVerbose && !config.isDryRun && !config.isDebug;
const awaitTask = task();
if (!this.isSpinnerDisabled || (external && this.canForce)) {
const text = format(label, context);
this.ora(awaitTask, text);
}
return awaitTask;
}
}
export default Spinner;