create-spud 0.1.3 → 0.1.4
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/index.ts +14 -11
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { mkdir, readdir } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { intro,
|
|
5
|
+
import { intro, note, cancel, text, confirm, tasks, group, multiselect } from "@clack/prompts";
|
|
6
6
|
import kebabcase from "lodash.kebabcase";
|
|
7
7
|
|
|
8
8
|
intro("It's spud time.");
|
|
@@ -20,14 +20,16 @@ const { rawGameName, features, shouldContinue } = await group(
|
|
|
20
20
|
rawGameName: () =>
|
|
21
21
|
text({
|
|
22
22
|
message: "Game name",
|
|
23
|
-
placeholder: "
|
|
23
|
+
placeholder: "e.g. Space Invaders",
|
|
24
24
|
validate(value) {
|
|
25
|
-
|
|
25
|
+
const trimmed = value?.trim();
|
|
26
|
+
if (!trimmed) return "Game name is required. Esc to cancel.";
|
|
27
|
+
if (!kebabcase(trimmed)) return "Game name must include letters or numbers.";
|
|
26
28
|
},
|
|
27
29
|
}),
|
|
28
30
|
features: () =>
|
|
29
31
|
multiselect({
|
|
30
|
-
message: "
|
|
32
|
+
message: "Select features",
|
|
31
33
|
initialValues: [],
|
|
32
34
|
required: false,
|
|
33
35
|
options: [
|
|
@@ -38,7 +40,7 @@ const { rawGameName, features, shouldContinue } = await group(
|
|
|
38
40
|
}),
|
|
39
41
|
shouldContinue: ({ results }) =>
|
|
40
42
|
confirm({
|
|
41
|
-
message: `
|
|
43
|
+
message: `Create a folder for "${kebabcase((results.rawGameName ?? "").trim())}" in the current directory?`,
|
|
42
44
|
}),
|
|
43
45
|
},
|
|
44
46
|
{
|
|
@@ -50,7 +52,7 @@ const { rawGameName, features, shouldContinue } = await group(
|
|
|
50
52
|
);
|
|
51
53
|
|
|
52
54
|
if (!shouldContinue) {
|
|
53
|
-
cancel("
|
|
55
|
+
cancel("Cancelled.");
|
|
54
56
|
process.exit(0);
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -71,16 +73,17 @@ await tasks([
|
|
|
71
73
|
{
|
|
72
74
|
title: "Installing dependencies with Bun",
|
|
73
75
|
async task() {
|
|
74
|
-
const proc = Bun.spawn(["bun", "install"], {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
const proc = Bun.spawn(["bun", "install"], { cwd: targetDir });
|
|
77
|
+
const exitCode = await proc.exited;
|
|
78
|
+
if (exitCode !== 0) {
|
|
79
|
+
throw new Error(`bun install failed with exit code ${exitCode}`);
|
|
80
|
+
}
|
|
78
81
|
return "Installed via bun";
|
|
79
82
|
},
|
|
80
83
|
},
|
|
81
84
|
]);
|
|
82
85
|
|
|
83
|
-
|
|
86
|
+
note(`cd ${slug}\nbun dev`, "Next steps");
|
|
84
87
|
|
|
85
88
|
async function copyDir(
|
|
86
89
|
sourceDir: string,
|