frontend/.pnpm-store/v3/files/5e/bb9cfb864e6cbe66e9e0656b841904adf96be907c501d5a29a47016f4e63d1f7d1c8c2f8b14bcdd6978a69ab913bc45fe1b299161e7b27732ed34eabf6e137

29 lines
801 B
Plaintext

const ora = require('ora');
const { format } = require('./util');
const noop = Promise.resolve();
class Spinner {
constructor({ container = {} } = {}) {
this.config = container.config;
this.ora = container.ora || ora;
}
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.promise(awaitTask, text);
}
return awaitTask;
}
}
module.exports = Spinner;