Skip to content

Commit 9acccde

Browse files
committed
feat(@clack/prompts): add tasks
like listr
1 parent a53da5c commit 9acccde

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

.changeset/curvy-lobsters-tell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clack/prompts': minor
3+
---
4+
5+
Add tasks function for executing tasks in spinners

packages/prompts/src/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,3 +759,33 @@ export const group = async <T>(
759759

760760
return results;
761761
};
762+
763+
export type Task = {
764+
/**
765+
* Task title
766+
*/
767+
title: string;
768+
/**
769+
* Task function
770+
*/
771+
task: (message: (string: string) => void) => string | Promise<string> | void | Promise<void>;
772+
773+
/**
774+
* If enabled === false the task will be skipped
775+
*/
776+
enabled?: boolean;
777+
};
778+
779+
/**
780+
* Define a group of tasks to be executed
781+
*/
782+
export const tasks = async (tasks: Task[]) => {
783+
for (const task of tasks) {
784+
if (task.enabled !== false) {
785+
const s = spinner();
786+
s.start(task.title);
787+
const result = await task.task(s.message);
788+
s.stop(result || task.title);
789+
}
790+
}
791+
};

0 commit comments

Comments
 (0)