File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-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 @@ -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+ } ;
You can’t perform that action at this time.
0 commit comments