[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.

chore: rename builder to workflow

Bruno Rocha (Aug 11, 2023, 1:47 PM -0300) 232c31d0 3742b91f

+29 -29
+1 -1
.changeset/red-walls-greet.md
··· 2 2 '@clack/prompts': minor 3 3 --- 4 4 5 - add prompt `builder` 5 + add prompt `workflow` builder
+10 -10
examples/builder.ts examples/workflow.ts
··· 2 2 3 3 (async () => { 4 4 const results = await p 5 - .builder() 6 - .add('path', () => 5 + .workflow() 6 + .step('path', () => 7 7 p.text({ 8 8 message: 'Where should we create your project?', 9 9 placeholder: './sparkling-solid', ··· 13 13 }, 14 14 }) 15 15 ) 16 - .add('password', () => 16 + .step('password', () => 17 17 p.password({ 18 18 message: 'Provide a password', 19 19 validate: (value) => { ··· 22 22 }, 23 23 }) 24 24 ) 25 - .add('type', ({ results }) => 25 + .step('type', ({ results }) => 26 26 p.select({ 27 27 message: `Pick a project type within "${results.path}"`, 28 28 initialValue: 'ts', ··· 37 37 ], 38 38 }) 39 39 ) 40 - .add('tools', () => 40 + .step('tools', () => 41 41 p.multiselect({ 42 42 message: 'Select additional tools.', 43 43 initialValues: ['prettier', 'eslint'], ··· 49 49 ], 50 50 }) 51 51 ) 52 - .add('install', ({ results }) => 52 + .step('install', ({ results }) => 53 53 p.confirm({ 54 54 message: 'Install dependencies?', 55 55 initialValue: false, ··· 58 58 .run(); 59 59 60 60 await p 61 - .builder() 62 - .add('cancel', () => p.text({ message: 'Try cancel prompt (Ctrl + C):' })) 63 - .add('afterCancel', () => p.text({ message: 'This will not appear!' })) 61 + .workflow() 62 + .step('cancel', () => p.text({ message: 'Try cancel prompt (Ctrl + C):' })) 63 + .step('afterCancel', () => p.text({ message: 'This will not appear!' })) 64 64 .onCancel(({ results }) => { 65 - p.cancel('Builder canceled'); 65 + p.cancel('Workflow canceled'); 66 66 process.exit(0); 67 67 }) 68 68 .run();
+1 -1
examples/package.json
··· 12 12 "basic": "jiti ./basic.ts", 13 13 "spinner": "jiti ./spinner.ts", 14 14 "changesets": "jiti ./changesets.ts", 15 - "builder": "jiti ./builder.ts" 15 + "workflow": "jiti ./workflow.ts" 16 16 }, 17 17 "devDependencies": { 18 18 "jiti": "^1.17.0"
+8 -8
packages/prompts/README.md
··· 123 123 124 124 ## Utilities 125 125 126 - ### Grouping 126 + ### Group 127 127 128 128 Grouping prompts together is a great way to keep your code organized. This accepts a JSON object with a name that can be used to reference the group later. The second argument is an optional but has a `onCancel` callback that will be called if the user cancels one of the prompts in the group. 129 129 ··· 157 157 console.log(group.name, group.age, group.color); 158 158 ``` 159 159 160 - ### Building 160 + ### Workflow 161 161 162 - Just like `group`, but on `builder` way, so you can choose which one fits better. 162 + Just like `group`, but on builder way, so you can choose which one fits better. 163 163 164 164 ```js 165 165 import * as p from '@clack/prompts'; 166 166 167 167 const results = await p 168 - .builder() 169 - .add('name', () => p.text({ message: 'What is your name?' })) 170 - .add('age', () => p.text({ message: 'What is your age?' })) 171 - .add('color', ({ results }) => 168 + .workflow() 169 + .step('name', () => p.text({ message: 'What is your name?' })) 170 + .step('age', () => p.text({ message: 'What is your age?' })) 171 + .step('color', ({ results }) => 172 172 p.multiselect({ 173 173 message: `What is your favorite color ${results.name}?`, 174 174 options: [ ··· 179 179 }) 180 180 ) 181 181 .onCancel(() => { 182 - p.cancel('Builder canceled'); 182 + p.cancel('Workflow canceled'); 183 183 process.exit(0); 184 184 }) 185 185 .run();
+9 -9
packages/prompts/src/index.ts
··· 770 770 return results; 771 771 }; 772 772 773 - type NextPromptBuilder< 773 + type NextWorkflowBuilder< 774 774 TResults extends Record<string, unknown>, 775 775 TKey extends string, 776 776 TResult 777 - > = PromptBuilder< 777 + > = WorkflowBuilder< 778 778 { 779 779 [Key in keyof TResults]: Key extends TKey ? TResult : TResults[Key]; 780 780 } & { ··· 782 782 } 783 783 >; 784 784 785 - class PromptBuilder<TResults extends Record<string, unknown> = {}> { 785 + class WorkflowBuilder<TResults extends Record<string, unknown> = {}> { 786 786 private results: TResults = {} as TResults; 787 787 private prompts: Record<string, PromptWithOptions<TResults, unknown>> = {}; 788 788 private cancelCallback: PromptWithOptions<Partial<TResults>, void> | undefined; 789 789 790 - public add<TKey extends string, TResult>( 790 + public step<TKey extends string, TResult>( 791 791 key: TKey extends keyof TResults ? never : TKey, 792 792 prompt: PromptWithOptions<TResults, TResult> 793 - ): NextPromptBuilder<TResults, TKey, TResult> { 793 + ): NextWorkflowBuilder<TResults, TKey, TResult> { 794 794 this.prompts[key] = prompt; 795 - return this as NextPromptBuilder<TResults, TKey, TResult>; 795 + return this as NextWorkflowBuilder<TResults, TKey, TResult>; 796 796 } 797 797 798 - public onCancel(cb: PromptWithOptions<Partial<TResults>, void>): PromptBuilder<TResults> { 798 + public onCancel(cb: PromptWithOptions<Partial<TResults>, void>): WorkflowBuilder<TResults> { 799 799 this.cancelCallback = cb; 800 800 return this; 801 801 } ··· 814 814 } 815 815 } 816 816 817 - export const builder = () => { 818 - return new PromptBuilder(); 817 + export const workflow = () => { 818 + return new WorkflowBuilder(); 819 819 };