[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

feat(@clack/prompts): add tasks (#154)

authored by

Christian Preston and committed by
GitHub
(Aug 29, 2023, 8:39 AM EDT) 65dfd4f9 9d0e0dc1

+51
+5
.changeset/curvy-lobsters-tell.md
··· 1 + --- 2 + '@clack/prompts': minor 3 + --- 4 + 5 + Add tasks function for executing tasks in spinners
+16
packages/prompts/README.md
··· 156 156 157 157 console.log(group.name, group.age, group.color); 158 158 ``` 159 + 160 + ### Tasks 161 + 162 + Execute multiple tasks in spinners. 163 + 164 + ```js 165 + await p.tasks([ 166 + { 167 + title: 'Installing via npm', 168 + task: async (message) => { 169 + // Do installation here 170 + return 'Installed via npm'; 171 + }, 172 + }, 173 + ]); 174 + ```
+30
packages/prompts/src/index.ts
··· 774 774 775 775 return results; 776 776 }; 777 + 778 + export type Task = { 779 + /** 780 + * Task title 781 + */ 782 + title: string; 783 + /** 784 + * Task function 785 + */ 786 + task: (message: (string: string) => void) => string | Promise<string> | void | Promise<void>; 787 + 788 + /** 789 + * If enabled === false the task will be skipped 790 + */ 791 + enabled?: boolean; 792 + }; 793 + 794 + /** 795 + * Define a group of tasks to be executed 796 + */ 797 + export const tasks = async (tasks: Task[]) => { 798 + for (const task of tasks) { 799 + if (task.enabled === false) continue; 800 + 801 + const s = spinner(); 802 + s.start(task.title); 803 + const result = await task.task(s.message); 804 + s.stop(result || task.title); 805 + } 806 + };