-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.js
124 lines (117 loc) · 3.24 KB
/
bin.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env node
import chalk from "chalk";
import * as p from "@clack/prompts";
import fs from "node:fs";
import open from "open";
import path from "node:path";
import url from "node:url";
import { createECS } from "./CLI/newECS.js";
import { setupDemo1 } from "./CLI/demo1.js";
const { version } = JSON.parse(fs.readFileSync(new URL("package.json", import.meta.url), "utf-8"));
let newProjedtData;
const CWD = process.cwd();
p.intro(
chalk.blueBright(`
************************************
WELCOME TO SQUELETO INIT WIZARD
Version ${version}
************************************`)
);
const projectType = await p.select({
message: chalk.blueBright("Select your project option."),
options: [
{ value: "newECS", label: chalk.blueBright("Start New Squeleto ECS Project"), hint: "Blank ECS Projet" },
{ value: "d1", label: chalk.blueBright("Download RPG Tutorial"), hint: "Top Down RPG" },
{ value: "d4", label: chalk.blueBright("Open Docs"), hint: "Squeleto Documentation" },
],
});
if (p.isCancel(projectType)) {
console.log(
chalk.yellowBright(`
************************************
SQUELETO Setup cancelled.
************************************
`)
);
process.exit(0);
}
const otherDIR_NAME = path.dirname(url.fileURLToPath(import.meta.url));
switch (projectType) {
case "newECS":
await newProjectSurvey();
createECS(newProjedtData, otherDIR_NAME);
break;
case "d1":
setupDemo1(otherDIR_NAME);
break;
case "d4":
open("https://jyoung4242.github.io/Squeleto-Docs/#/");
break;
}
if (projectType == "d4") {
p.outro(
chalk.blueBright(`
OPENING DOCS - LEAVING SQUELETO
`)
);
} else {
p.outro(
chalk.blueBright(`
************************************
cd into your new directory
run \`npm install\`
run \`npm run dev\`
SETUP COMPLETE - LEAVING SQUELETO
************************************`)
);
}
async function newProjectSurvey() {
newProjedtData = await p.group(
{
author: () =>
p.text({
message: chalk.greenBright(`Enter your name: `),
initialValue: "Bobs YourUncle",
validate: value => {
if (value.length == 0) {
return "Value is required";
}
},
}),
cwd: () =>
p.text({
message: chalk.greenBright("Enter path to create project:"),
initialValue: CWD,
validate: value => {
if (value.length == 0) {
return "Value is required";
}
},
}),
gamename: () =>
p.text({
message: chalk.greenBright("Enter name of your project:"),
initialValue: "myProject",
validate: value => {
if (value.length == 0) {
return "Value is required";
}
},
}),
},
{
// On Cancel callback that wraps the group
// So if the user cancels one of the prompts in the group this function will be called
onCancel: ({ results }) => {
p.cancel(
chalk.yellowBright(`
************************************
SQUELETO Setup cancelled.
************************************
`)
);
process.exit(0);
},
}
);
}