-
-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathindex.ts
More file actions
93 lines (83 loc) · 2.35 KB
/
index.ts
File metadata and controls
93 lines (83 loc) · 2.35 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { setTimeout } from 'node:timers/promises';
import * as p from '@clack/prompts';
import { styleText } from 'node:util';
async function main() {
console.clear();
await setTimeout(1000);
p.updateSettings({
aliases: {
w: 'up',
s: 'down',
a: 'left',
d: 'right',
},
});
p.intro(`${styleText('bgCyan', styleText('black', ' create-app '))}`);
const project = await p.group(
{
path: () =>
p.text({
message: 'Where should we create your project?',
placeholder: './sparkling-solid',
validate: (value) => {
if (!value) return 'Please enter a path.';
if (value[0] !== '.') return 'Please enter a relative path.';
},
}),
password: () =>
p.password({
message: 'Provide a password',
validate: (value) => {
if (!value) return 'Please enter a password.';
if (value.length < 5) return 'Password should have at least 5 characters.';
},
}),
type: ({ results }) =>
p.select({
message: `Pick a project type within "${results.path}"`,
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' },
],
}),
tools: () =>
p.multiselect({
message: 'Select additional tools.',
initialValues: ['prettier', 'eslint'],
options: [
{ value: 'prettier', label: 'Prettier', hint: 'recommended' },
{ value: 'eslint', label: 'ESLint', hint: 'recommended' },
{ value: 'stylelint', label: 'Stylelint' },
{ value: 'gh-action', label: 'GitHub Action' },
],
}),
install: () =>
p.confirm({
message: 'Install dependencies?',
initialValue: false,
}),
},
{
onCancel: () => {
p.cancel('Operation cancelled.');
process.exit(0);
},
}
);
if (project.install) {
const s = p.spinner();
s.start('Installing via pnpm');
await setTimeout(2500);
s.stop('Installed via pnpm');
}
const nextSteps = `cd ${project.path} \n${project.install ? '' : 'pnpm install\n'}pnpm dev`;
p.note(nextSteps, 'Next steps.');
p.outro(`Problems? ${styleText('underline', styleText('cyan', 'https://example.com/issues'))}`);
}
main().catch(console.error);