Skip to content

Commit

Permalink
docs: update workflow with fork example
Browse files Browse the repository at this point in the history
  • Loading branch information
orochaa committed Aug 13, 2023
1 parent bbe2c6f commit f6e6633
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 12 deletions.
28 changes: 27 additions & 1 deletion examples/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 32 additions & 11 deletions packages/prompts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```

0 comments on commit f6e6633

Please sign in to comment.