project-startup 1.2.0 → 1.2.1
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/cli.js +60 -10
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -1,30 +1,80 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const path = require("path")
|
|
4
|
-
const prompts = require(
|
|
5
|
-
const fs = require(
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const prompts = require("prompts");
|
|
5
|
+
const fs = require("fs-extra");
|
|
6
6
|
|
|
7
7
|
async function main() {
|
|
8
|
-
const response = await prompts(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
const response = await prompts([
|
|
9
|
+
{
|
|
10
|
+
type: "text",
|
|
11
|
+
name: "projectName",
|
|
12
|
+
message: "Project name",
|
|
13
|
+
initial: "project-startup"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
type: "multiselect",
|
|
17
|
+
name: "logics",
|
|
18
|
+
message: "Which logic folders do you want to install?",
|
|
19
|
+
choices: [
|
|
20
|
+
{ title: "Booking", value: "Booking" },
|
|
21
|
+
{ title: "RBAC", value: "rbac" },
|
|
22
|
+
{ title: "Stocks", value: "Stocks" },
|
|
23
|
+
{ title: "All", value: "all" }
|
|
24
|
+
],
|
|
25
|
+
hint: "Use space to select, enter to confirm"
|
|
26
|
+
}
|
|
27
|
+
]);
|
|
14
28
|
|
|
15
29
|
const projectName = response.projectName?.trim();
|
|
16
30
|
if (!projectName) process.exit(1);
|
|
17
31
|
|
|
18
32
|
const targetDir = path.resolve(process.cwd(), projectName);
|
|
19
33
|
const templateDir = path.resolve(__dirname, "../template");
|
|
34
|
+
const logicsDir = path.join(templateDir, "Logics");
|
|
20
35
|
|
|
21
36
|
if (await fs.pathExists(targetDir)) {
|
|
22
37
|
console.error(`Folder already exists: ${projectName}`);
|
|
23
38
|
process.exit(1);
|
|
24
39
|
}
|
|
25
40
|
|
|
26
|
-
await fs.copy(templateDir, targetDir
|
|
41
|
+
await fs.copy(templateDir, targetDir, {
|
|
42
|
+
filter: (src) => {
|
|
43
|
+
const rel = path.relative(templateDir, src);
|
|
44
|
+
if (!rel) return true;
|
|
45
|
+
|
|
46
|
+
if (!response.logics || response.logics.length === 0) return !rel.startsWith("Logics");
|
|
47
|
+
|
|
48
|
+
if (response.logics.includes("all")) return true;
|
|
49
|
+
|
|
50
|
+
if (rel.startsWith("Logics")) {
|
|
51
|
+
const parts = rel.split(path.sep);
|
|
52
|
+
if (parts.length >= 2) {
|
|
53
|
+
const folder = parts[1];
|
|
54
|
+
return response.logics.includes(folder);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (!response.logics.includes("all")) {
|
|
63
|
+
const selected = response.logics || [];
|
|
64
|
+
for (const item of ["Booking", "rbac", "Stocks"]) {
|
|
65
|
+
if (!selected.includes(item)) {
|
|
66
|
+
await fs.remove(path.join(targetDir, "Logics", item));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const logicPath = path.join(targetDir, "Logics");
|
|
70
|
+
const remaining = await fs.readdir(logicPath);
|
|
71
|
+
if (remaining.length === 0) {
|
|
72
|
+
await fs.remove(logicPath);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
27
76
|
console.log(`Created ${projectName}`);
|
|
77
|
+
console.log(`Selected logics: ${response.logics?.join(", ") || "none"}`);
|
|
28
78
|
console.log(`Next: cd ${projectName} && npm install && npm run dev`);
|
|
29
79
|
}
|
|
30
80
|
|