diff --git a/examples/workflow.ts b/examples/workflow.ts index b29afe05..b14d18c7 100644 --- a/examples/workflow.ts +++ b/examples/workflow.ts @@ -49,12 +49,38 @@ import * as p from '@clack/prompts'; ], }) ) - .step('install', ({ results }) => + .step('install', () => p.confirm({ message: 'Install dependencies?', initialValue: false, }) ) + .step('fork', ({ results }) => { + if (results.install === true) { + return p + .workflow() + .step('package', () => + p.select({ + message: 'Which package do you want to user?', + options: [ + { + label: 'npm', + value: 'npm', + }, + { + label: 'yarn', + value: 'yarn', + }, + { + label: 'pnpm', + value: 'pnpm', + }, + ], + }) + ) + .run(); + } + }) .run(); await p diff --git a/packages/prompts/README.md b/packages/prompts/README.md index 8f0482b1..b3c22fc3 100644 --- a/packages/prompts/README.md +++ b/packages/prompts/README.md @@ -166,22 +166,43 @@ import * as p from '@clack/prompts'; const results = await p .workflow() - .step('name', () => p.text({ message: 'What is your name?' })) - .step('age', () => p.text({ message: 'What is your age?' })) - .step('color', ({ results }) => - p.multiselect({ - message: `What is your favorite color ${results.name}?`, - options: [ - { value: 'red', label: 'Red' }, - { value: 'green', label: 'Green' }, - { value: 'blue', label: 'Blue' }, - ], + .step('name', () => p.text({ message: 'What is your package name?' })) + .step('install', () => + p.confirm({ + message: 'Install dependencies?', + initialValue: false, }) ) + .step('fork', ({ results }) => { + if (results.install === true) { + return p + .workflow() + .step('package', () => + p.select({ + message: 'Which package do you want to user?', + options: [ + { + label: 'npm', + value: 'npm', + }, + { + label: 'yarn', + value: 'yarn', + }, + { + label: 'pnpm', + value: 'pnpm', + }, + ], + }) + ) + .run(); + } + }) .onCancel(() => { p.cancel('Workflow canceled'); process.exit(0); }) .run(); -console.log(results.name, results.age, results.color); +console.log(results); ```