Skip to content

Commit 1296aab

Browse files
committed
docs: add workflow fork example
1 parent 14a4e4f commit 1296aab

File tree

2 files changed

+69
-43
lines changed

2 files changed

+69
-43
lines changed

examples/workflow.ts

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,10 @@ import * as p from '@clack/prompts';
33
(async () => {
44
const results = await p
55
.workflow()
6-
.step('path', () =>
7-
p.text({
8-
message: 'Where should we create your project?',
9-
placeholder: './sparkling-solid',
10-
validate: (value) => {
11-
if (!value) return 'Please enter a path.';
12-
if (value[0] !== '.') return 'Please enter a relative path.';
13-
},
14-
})
15-
)
16-
.step('password', () =>
17-
p.password({
18-
message: 'Provide a password',
19-
validate: (value) => {
20-
if (!value) return 'Please enter a password.';
21-
if (value.length < 5) return 'Password should have at least 5 characters.';
22-
},
23-
})
24-
)
25-
.step('type', ({ results }) =>
6+
.step('name', () => p.text({ message: 'What is your package name?' }))
7+
.step('type', () =>
268
p.select({
27-
message: `Pick a project type within "${results.path}"`,
9+
message: `Pick a project type:`,
2810
initialValue: 'ts',
2911
maxItems: 5,
3012
options: [
@@ -37,24 +19,35 @@ import * as p from '@clack/prompts';
3719
],
3820
})
3921
)
40-
.step('tools', () =>
41-
p.multiselect({
42-
message: 'Select additional tools.',
43-
initialValues: ['prettier', 'eslint'],
44-
options: [
45-
{ value: 'prettier', label: 'Prettier', hint: 'recommended' },
46-
{ value: 'eslint', label: 'ESLint', hint: 'recommended' },
47-
{ value: 'stylelint', label: 'Stylelint' },
48-
{ value: 'gh-action', label: 'GitHub Action' },
49-
],
50-
})
51-
)
52-
.step('install', ({ results }) =>
22+
.step('install', () =>
5323
p.confirm({
5424
message: 'Install dependencies?',
5525
initialValue: false,
5626
})
5727
)
28+
.step('fork', ({ results }) => {
29+
if (results.install === true) {
30+
return p.workflow().step('package', () =>
31+
p.select({
32+
message: 'Pick a project manager:',
33+
options: [
34+
{
35+
label: 'npm',
36+
value: 'npm',
37+
},
38+
{
39+
label: 'yarn',
40+
value: 'yarn',
41+
},
42+
{
43+
label: 'pnpm',
44+
value: 'pnpm',
45+
},
46+
],
47+
})
48+
).run();
49+
}
50+
})
5851
.run();
5952

6053
await p

packages/prompts/README.md

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,55 @@ import * as p from '@clack/prompts';
199199

200200
const results = await p
201201
.workflow()
202-
.step('name', () => p.text({ message: 'What is your name?' }))
203-
.step('age', () => p.text({ message: 'What is your age?' }))
204-
.step('color', ({ results }) =>
205-
p.multiselect({
206-
message: `What is your favorite color ${results.name}?`,
202+
.step('name', () => p.text({ message: 'What is your package name?' }))
203+
.step('type', () =>
204+
p.select({
205+
message: `Pick a project type:`,
206+
initialValue: 'ts',
207+
maxItems: 5,
207208
options: [
208-
{ value: 'red', label: 'Red' },
209-
{ value: 'green', label: 'Green' },
210-
{ value: 'blue', label: 'Blue' },
209+
{ value: 'ts', label: 'TypeScript' },
210+
{ value: 'js', label: 'JavaScript' },
211+
{ value: 'rust', label: 'Rust' },
212+
{ value: 'go', label: 'Go' },
213+
{ value: 'python', label: 'Python' },
214+
{ value: 'coffee', label: 'CoffeeScript', hint: 'oh no' },
211215
],
212216
})
213217
)
218+
.step('install', () =>
219+
p.confirm({
220+
message: 'Install dependencies?',
221+
initialValue: false,
222+
})
223+
)
224+
.step('fork', ({ results }) => {
225+
if (results.install === true) {
226+
return p.workflow().step('package', () =>
227+
p.select({
228+
message: 'Pick a project manager:',
229+
options: [
230+
{
231+
label: 'npm',
232+
value: 'npm',
233+
},
234+
{
235+
label: 'yarn',
236+
value: 'yarn',
237+
},
238+
{
239+
label: 'pnpm',
240+
value: 'pnpm',
241+
},
242+
],
243+
})
244+
).run();
245+
}
246+
})
214247
.onCancel(() => {
215248
p.cancel('Workflow canceled');
216249
process.exit(0);
217250
})
218251
.run();
219-
console.log(results.name, results.age, results.color);
252+
console.log(results);
220253
```

0 commit comments

Comments
 (0)