@presencenet/create-pnet-stack 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/create-pnet-stack.js +40 -12
- package/package.json +1 -1
package/bin/create-pnet-stack.js
CHANGED
|
@@ -21,6 +21,12 @@ const templateNames = {
|
|
|
21
21
|
tauri: "Tauri",
|
|
22
22
|
};
|
|
23
23
|
const cliDir = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
24
|
+
const color = stdout.isTTY && !process.env.NO_COLOR;
|
|
25
|
+
const paint = (code, value) =>
|
|
26
|
+
color ? `\u001b[${code}m${value}\u001b[0m` : value;
|
|
27
|
+
const cyan = (value) => paint("36", value);
|
|
28
|
+
const dim = (value) => paint("2", value);
|
|
29
|
+
const green = (value) => paint("32", value);
|
|
24
30
|
|
|
25
31
|
async function main() {
|
|
26
32
|
const args = process.argv.slice(2);
|
|
@@ -37,18 +43,36 @@ async function main() {
|
|
|
37
43
|
if (!template && args.includes("--template"))
|
|
38
44
|
template = args[args.indexOf("--template") + 1];
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
if (!projectName) projectName = (await rl.question("Project name: ")).trim();
|
|
42
|
-
while (!templates.includes(template)) {
|
|
46
|
+
if (!projectName || !templates.includes(template)) {
|
|
43
47
|
stdout.write(
|
|
44
|
-
`\
|
|
48
|
+
`\n${cyan("◆")} ${paint("1", "create-pnet-stack")} ${dim("·")} Create a new project\n\n`,
|
|
45
49
|
);
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
const rl = createInterface({ input: stdin, output: stdout });
|
|
51
|
+
if (!projectName)
|
|
52
|
+
projectName = (
|
|
53
|
+
await rl.question(`${dim("Project name")} ${dim("›")} `)
|
|
54
|
+
).trim();
|
|
55
|
+
if (!templates.includes(template)) {
|
|
56
|
+
stdout.write(`\n${dim("Choose a starter")}\n`);
|
|
57
|
+
templates.forEach((item, i) => {
|
|
58
|
+
stdout.write(
|
|
59
|
+
` ${dim(`${i + 1}`)} ${templateNames[item]}${i === 0 ? dim(" recommended") : ""}\n`,
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
while (!templates.includes(template)) {
|
|
63
|
+
const answer =
|
|
64
|
+
(
|
|
65
|
+
await rl.question(`\n${dim("Starter")} ${dim("[1]")} ${dim("›")} `)
|
|
66
|
+
).trim() || "1";
|
|
67
|
+
template = templates[Number(answer) - 1] ?? answer;
|
|
68
|
+
if (!templates.includes(template))
|
|
69
|
+
stdout.write(
|
|
70
|
+
`${paint("31", "×")} Choose 1–4, or enter web, mobile, electron, or tauri.\n`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
rl.close();
|
|
50
75
|
}
|
|
51
|
-
rl.close();
|
|
52
76
|
|
|
53
77
|
if (!projectName || !/^[a-z0-9][a-z0-9-]*$/.test(projectName))
|
|
54
78
|
throw new Error(
|
|
@@ -76,9 +100,13 @@ async function main() {
|
|
|
76
100
|
'"root": false': '"root": true',
|
|
77
101
|
});
|
|
78
102
|
execFileSync("git", ["init"], { cwd: target, stdio: "ignore" });
|
|
79
|
-
stdout.write(
|
|
80
|
-
|
|
81
|
-
|
|
103
|
+
stdout.write(
|
|
104
|
+
`\n${green("✓")} Created ${paint("1", projectName)} ${dim(`(${templateNames[template]})`)}\n`,
|
|
105
|
+
);
|
|
106
|
+
stdout.write(`${green("✓")} Initialized Git repository\n`);
|
|
107
|
+
stdout.write(
|
|
108
|
+
`\n${dim("Next steps")}\n ${cyan(`cd ${projectName}`)}\n ${cyan("bun install")}\n ${cyan("bun run dev")}\n`,
|
|
109
|
+
);
|
|
82
110
|
if (template === "tauri")
|
|
83
111
|
stdout.write(
|
|
84
112
|
"\nTauri also requires the platform prerequisites: https://tauri.app/start/prerequisites/\n",
|