Minor refactor of cli tasks (core start, gui publishing)
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
import { Task } from '..';
|
||||
import { Task } from '../tasks/task';
|
||||
import chalk from 'chalk';
|
||||
|
||||
export const execTask = async <T>(taskName, options?: T) => {
|
||||
const task = await import(`${__dirname}/../tasks/${taskName}.ts`);
|
||||
return task.default(options) as Task<T>;
|
||||
export const execTask = <TOptions>(task: Task<TOptions>) => async (options: TOptions) => {
|
||||
console.log(chalk.yellow(`Running ${chalk.bold(task.name)} task`));
|
||||
task.setOptions(options);
|
||||
try {
|
||||
console.group();
|
||||
await task.exec();
|
||||
console.groupEnd();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import ora from 'ora';
|
||||
|
||||
export const startSpinner = (label: string) => {
|
||||
const spinner = new ora(label);
|
||||
spinner.start();
|
||||
return spinner;
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
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 = new ora(spinnerLabel);
|
||||
spinner.start();
|
||||
try {
|
||||
await fn(options);
|
||||
spinner.succeed();
|
||||
} catch (e) {
|
||||
spinner.fail();
|
||||
console.log(e);
|
||||
if (killProcess) {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user