File size: 602 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import { spinner } from "@clack/prompts"
type MaybePromise<T> = T | Promise<T>
type MessageFn = (message: string) => void
interface Task {
title: string
task: (message: MessageFn) => MaybePromise<string | void>
enabled?: boolean
}
export const tasks = async (tasks: Task[]) => {
for (const task of tasks) {
if (task.enabled === false) continue
const s = spinner()
s.start(task.title)
try {
const result = await task.task(s.message)
s.stop(result || task.title)
} catch (error) {
s.stop(`${task.title}\n` + String(error))
throw error
}
}
}
|