grafana/scripts/cli/utils/useSpinner.ts
Oleg Gaidarenko 2b9cf1132f Use ora#fail instead of console.log
Since with ora#fail you can stderr it instead of using the stdout,
and it's a bit nicer since it will show that cross sign :)
2019-03-18 13:45:58 +01:00

20 lines
435 B
TypeScript

import ora from 'ora';
type FnToSpin<T> = (options: T) => Promise<void>;
export const useSpinner = <T>(spinnerLabel: string, fn: FnToSpin<T>, killProcess = true) => {
return async (options: T) => {
const spinner = ora(spinnerLabel);
spinner.start();
try {
await fn(options);
spinner.succeed();
} catch (e) {
spinner.fail(e);
if (killProcess) {
process.exit(1);
}
}
};
};