create-giggles-app 1.0.1 → 1.0.2
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/dist/index.js +31 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import * as p from "@clack/prompts";
|
|
5
|
-
import {
|
|
5
|
+
import { exec } from "child_process";
|
|
6
6
|
import fs from "fs";
|
|
7
7
|
import path from "path";
|
|
8
|
+
import { promisify } from "util";
|
|
9
|
+
var execAsync = promisify(exec);
|
|
8
10
|
function detectPackageManager() {
|
|
9
11
|
const userAgent = process.env.npm_config_user_agent ?? "";
|
|
10
12
|
if (userAgent.startsWith("yarn")) return "yarn";
|
|
@@ -30,38 +32,38 @@ async function main() {
|
|
|
30
32
|
const options = await p.group(
|
|
31
33
|
{
|
|
32
34
|
name: () => p.text({
|
|
33
|
-
message: "
|
|
35
|
+
message: "project name?",
|
|
34
36
|
placeholder: "my-tui",
|
|
35
37
|
initialValue: argName ?? "",
|
|
36
38
|
validate: (value) => {
|
|
37
|
-
if (!value.trim()) return "
|
|
38
|
-
if (/[^\w\-.]/.test(value)) return "
|
|
39
|
+
if (!value.trim()) return "project name is required.";
|
|
40
|
+
if (/[^\w\-.]/.test(value)) return "project name contains invalid characters.";
|
|
39
41
|
}
|
|
40
42
|
}),
|
|
41
43
|
location: ({ results }) => p.text({
|
|
42
|
-
message: "
|
|
44
|
+
message: "where should we create the project?",
|
|
43
45
|
placeholder: `./${results.name}`,
|
|
44
46
|
initialValue: `./${results.name}`
|
|
45
47
|
}),
|
|
46
48
|
language: () => p.select({
|
|
47
|
-
message: "
|
|
49
|
+
message: "language?",
|
|
48
50
|
options: [
|
|
49
|
-
{ value: "typescript", label: "
|
|
50
|
-
{ value: "javascript", label: "
|
|
51
|
+
{ value: "typescript", label: "typescript", hint: "recommended" },
|
|
52
|
+
{ value: "javascript", label: "javascript" }
|
|
51
53
|
]
|
|
52
54
|
}),
|
|
53
55
|
linting: () => p.confirm({
|
|
54
|
-
message: "
|
|
56
|
+
message: "add eslint + prettier?",
|
|
55
57
|
initialValue: true
|
|
56
58
|
}),
|
|
57
59
|
install: () => p.confirm({
|
|
58
|
-
message: "
|
|
60
|
+
message: "install dependencies?",
|
|
59
61
|
initialValue: true
|
|
60
62
|
})
|
|
61
63
|
},
|
|
62
64
|
{
|
|
63
65
|
onCancel: () => {
|
|
64
|
-
p.cancel("
|
|
66
|
+
p.cancel("cancelled.");
|
|
65
67
|
process.exit(0);
|
|
66
68
|
}
|
|
67
69
|
}
|
|
@@ -74,12 +76,12 @@ async function main() {
|
|
|
74
76
|
if (fs.existsSync(projectDir)) {
|
|
75
77
|
const files = fs.readdirSync(projectDir);
|
|
76
78
|
if (files.length > 0) {
|
|
77
|
-
p.cancel(`
|
|
79
|
+
p.cancel(`directory ${options.location} is not empty.`);
|
|
78
80
|
process.exit(1);
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
fs.mkdirSync(projectDir, { recursive: true });
|
|
82
|
-
s.start("
|
|
84
|
+
s.start("scaffolding project...");
|
|
83
85
|
copyDir(path.join(templatesDir, "base"), projectDir, {
|
|
84
86
|
_gitignore: ".gitignore"
|
|
85
87
|
});
|
|
@@ -128,19 +130,27 @@ async function main() {
|
|
|
128
130
|
devDependencies: devDeps
|
|
129
131
|
};
|
|
130
132
|
fs.writeFileSync(path.join(projectDir, "package.json"), JSON.stringify(pkg, null, 2) + "\n");
|
|
131
|
-
s.stop("
|
|
133
|
+
s.stop("project scaffolded.");
|
|
132
134
|
if (options.install) {
|
|
133
|
-
|
|
135
|
+
const messages = ["installing dependencies...", "giggling...", "hehehe...", "almost there...", "still giggling..."];
|
|
136
|
+
let i = 0;
|
|
137
|
+
s.start(messages[0]);
|
|
138
|
+
const interval = setInterval(() => {
|
|
139
|
+
i = (i + 1) % messages.length;
|
|
140
|
+
s.message(messages[i]);
|
|
141
|
+
}, 2e3);
|
|
134
142
|
try {
|
|
135
|
-
|
|
136
|
-
|
|
143
|
+
await execAsync(`${pm} install`, { cwd: projectDir });
|
|
144
|
+
clearInterval(interval);
|
|
145
|
+
s.stop("dependencies installed.");
|
|
137
146
|
} catch {
|
|
138
|
-
|
|
139
|
-
|
|
147
|
+
clearInterval(interval);
|
|
148
|
+
s.stop("failed to install dependencies.");
|
|
149
|
+
p.log.warning(`run \`${pm} install\` manually in the project directory.`);
|
|
140
150
|
}
|
|
141
151
|
}
|
|
142
152
|
const relative = path.relative(process.cwd(), projectDir);
|
|
143
|
-
p.note([`cd ${relative}`, `${pm} dev`].join("\n"), "
|
|
144
|
-
p.outro("
|
|
153
|
+
p.note([`cd ${relative}`, `${pm} dev`].join("\n"), "next steps");
|
|
154
|
+
p.outro("done! :p");
|
|
145
155
|
}
|
|
146
156
|
main().catch(console.error);
|