|
| 1 | +import * as p from '@clack/prompts'; |
| 2 | + |
| 3 | +(async () => { |
| 4 | + const results = await p |
| 5 | + .builder() |
| 6 | + .add('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 | + .add('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 | + .add('type', ({ results }) => |
| 26 | + p.select({ |
| 27 | + message: `Pick a project type within "${results.path}"`, |
| 28 | + initialValue: 'ts', |
| 29 | + maxItems: 5, |
| 30 | + options: [ |
| 31 | + { value: 'ts', label: 'TypeScript' }, |
| 32 | + { value: 'js', label: 'JavaScript' }, |
| 33 | + { value: 'rust', label: 'Rust' }, |
| 34 | + { value: 'go', label: 'Go' }, |
| 35 | + { value: 'python', label: 'Python' }, |
| 36 | + { value: 'coffee', label: 'CoffeeScript', hint: 'oh no' }, |
| 37 | + ], |
| 38 | + }) |
| 39 | + ) |
| 40 | + .add('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 | + .add('install', ({ results }) => |
| 53 | + p.confirm({ |
| 54 | + message: 'Install dependencies?', |
| 55 | + initialValue: false, |
| 56 | + }) |
| 57 | + ) |
| 58 | + .run(); |
| 59 | +})(); |
0 commit comments