-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'builder' of https://github.com/Mist3rBru/clack into bui…
…lder
- Loading branch information
Showing
6 changed files
with
277 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@clack/prompts': minor | ||
--- | ||
|
||
add prompt `workflow` builder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as p from '@clack/prompts'; | ||
|
||
(async () => { | ||
const results = await p | ||
.workflow() | ||
.step('name', () => p.text({ message: 'What is your package name?' })) | ||
.step('type', () => | ||
p.select({ | ||
message: 'Pick a project type:', | ||
initialValue: 'ts', | ||
maxItems: 5, | ||
options: [ | ||
{ value: 'ts', label: 'TypeScript' }, | ||
{ value: 'js', label: 'JavaScript' }, | ||
{ value: 'rust', label: 'Rust' }, | ||
{ value: 'go', label: 'Go' }, | ||
{ value: 'python', label: 'Python' }, | ||
{ value: 'coffee', label: 'CoffeeScript', hint: 'oh no' }, | ||
], | ||
}) | ||
) | ||
.step('install', () => | ||
p.confirm({ | ||
message: 'Install dependencies?', | ||
initialValue: false, | ||
}) | ||
) | ||
.forkStep( | ||
'fork', | ||
({ results }) => results.install, | ||
({ results }) => { | ||
return p.workflow().step('package', () => | ||
p.select({ | ||
message: 'Pick a package manager:', | ||
initialValue: 'pnpm', | ||
options: [ | ||
{ | ||
label: 'npm', | ||
value: 'npm', | ||
}, | ||
{ | ||
label: 'yarn', | ||
value: 'yarn', | ||
}, | ||
{ | ||
label: 'pnpm', | ||
value: 'pnpm', | ||
}, | ||
], | ||
}) | ||
); | ||
} | ||
) | ||
.run(); | ||
|
||
await p | ||
.workflow() | ||
.step('cancel', () => p.text({ message: 'Try cancel prompt (Ctrl + C):' })) | ||
.step('afterCancel', () => p.text({ message: 'This will not appear!' })) | ||
.onCancel(({ results }) => { | ||
p.cancel('Workflow canceled'); | ||
process.exit(0); | ||
}) | ||
.run(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.