File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed
Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @clack/prompts ' : minor
3+ ---
4+
5+ Add tasks function for executing tasks in spinners
Original file line number Diff line number Diff line change @@ -156,3 +156,19 @@ const group = await p.group(
156156
157157console .log (group .name , group .age , group .color );
158158```
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+ ```
Original file line number Diff line number Diff line change @@ -774,3 +774,33 @@ export const group = async <T>(
774774
775775 return results ;
776776} ;
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+ } ;
You can’t perform that action at this time.
0 commit comments