-
-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathdefault-value.ts
More file actions
30 lines (25 loc) · 699 Bytes
/
default-value.ts
File metadata and controls
30 lines (25 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import * as p from '@clack/prompts';
import { styleText } from 'node:util';
async function main() {
const defaultPath = 'my-project';
const result = await p.text({
message: 'Enter the directory to bootstrap the project',
placeholder: ` (hit Enter to use '${defaultPath}')`,
defaultValue: defaultPath,
validate: (value) => {
if (!value) {
return 'Directory is required';
}
if (value.includes(' ')) {
return 'Directory cannot contain spaces';
}
return undefined;
},
});
if (p.isCancel(result)) {
p.cancel('Operation cancelled.');
process.exit(0);
}
p.outro(`Let's bootstrap the project in ${styleText('cyan', result)}`);
}
main().catch(console.error);