-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (76 loc) · 2.35 KB
/
index.js
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
import * as p from "@clack/prompts";
import { setTimeout } from "node:timers/promises";
import color from "picocolors";
async function main() {
console.clear();
await setTimeout(1000);
p.intro(`${color.bgCyan(color.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",
options: [
{ value: "ts", label: "TypeScript" },
{ value: "js", label: "JavaScript" },
{ 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(5000);
s.stop("Installed via pnpm");
}
let nextSteps = `cd ${project.path} \n${
project.install ? "" : "pnpm install\n"
}pnpm dev`;
p.note(nextSteps, "Next steps.");
p.outro(
`Problems? ${color.underline(color.cyan("https://example.com/issues"))}`
);
}
main().catch(console.error);