create-jinmankn-app 1.0.7 → 1.0.8
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/index.js +48 -88
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -4,92 +4,76 @@ const fs = require("fs");
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const readline = require("readline");
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
PKG_ROOT,
|
|
11
|
-
"templates"
|
|
7
|
+
const templatesDir = path.join(
|
|
8
|
+
__dirname,
|
|
9
|
+
"../templates"
|
|
12
10
|
);
|
|
13
11
|
|
|
14
|
-
const
|
|
15
|
-
|
|
12
|
+
const manifestPath = path.join(
|
|
13
|
+
templatesDir,
|
|
16
14
|
"projects.json"
|
|
17
15
|
);
|
|
18
16
|
|
|
19
|
-
// Question helper
|
|
20
17
|
function question(rl, prompt) {
|
|
21
18
|
return new Promise((resolve) =>
|
|
22
19
|
rl.question(prompt, resolve)
|
|
23
20
|
);
|
|
24
21
|
}
|
|
25
22
|
|
|
26
|
-
// Copy folder recursively
|
|
27
23
|
function copyTree(src, dest) {
|
|
28
24
|
|
|
29
25
|
fs.mkdirSync(dest, {
|
|
30
26
|
recursive: true
|
|
31
27
|
});
|
|
32
28
|
|
|
33
|
-
|
|
29
|
+
const entries = fs.readdirSync(src, {
|
|
34
30
|
withFileTypes: true
|
|
35
|
-
})
|
|
31
|
+
});
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
for (const entry of entries) {
|
|
38
34
|
|
|
39
|
-
const
|
|
35
|
+
const srcPath = path.join(
|
|
36
|
+
src,
|
|
37
|
+
entry.name
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const destPath = path.join(
|
|
41
|
+
dest,
|
|
42
|
+
entry.name
|
|
43
|
+
);
|
|
40
44
|
|
|
41
|
-
if (
|
|
45
|
+
if (entry.isDirectory()) {
|
|
42
46
|
|
|
43
|
-
// Ignore unnecessary folders
|
|
44
47
|
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
entry.name === "node_modules" ||
|
|
49
|
+
entry.name === ".git" ||
|
|
50
|
+
entry.name === "dist"
|
|
48
51
|
) {
|
|
49
52
|
continue;
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
copyTree(
|
|
55
|
+
copyTree(srcPath, destPath);
|
|
53
56
|
|
|
54
57
|
} else {
|
|
55
58
|
|
|
56
|
-
fs.copyFileSync(
|
|
59
|
+
fs.copyFileSync(srcPath, destPath);
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
function ensureEnvFromExample(projectRoot) {
|
|
64
|
+
async function main() {
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
projectRoot,
|
|
66
|
-
"backend"
|
|
67
|
-
);
|
|
66
|
+
if (!fs.existsSync(manifestPath)) {
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
const envFile = path.join(
|
|
75
|
-
backend,
|
|
76
|
-
".env"
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
fs.existsSync(example) &&
|
|
81
|
-
!fs.existsSync(envFile)
|
|
82
|
-
) {
|
|
68
|
+
console.log(
|
|
69
|
+
"projects.json not found"
|
|
70
|
+
);
|
|
83
71
|
|
|
84
|
-
|
|
72
|
+
process.exit(1);
|
|
85
73
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function main() {
|
|
89
74
|
|
|
90
|
-
// Read manifest
|
|
91
75
|
const manifest = JSON.parse(
|
|
92
|
-
fs.readFileSync(
|
|
76
|
+
fs.readFileSync(manifestPath, "utf8")
|
|
93
77
|
);
|
|
94
78
|
|
|
95
79
|
const projects = manifest.projects;
|
|
@@ -97,53 +81,45 @@ async function main() {
|
|
|
97
81
|
if (!projects.length) {
|
|
98
82
|
|
|
99
83
|
console.log(
|
|
100
|
-
"No templates found
|
|
84
|
+
"No templates found"
|
|
101
85
|
);
|
|
102
86
|
|
|
103
87
|
process.exit(1);
|
|
104
88
|
}
|
|
105
89
|
|
|
106
|
-
// Show projects
|
|
107
90
|
console.log("");
|
|
108
91
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const p = projects[i];
|
|
92
|
+
projects.forEach((project, index) => {
|
|
112
93
|
|
|
113
94
|
console.log(
|
|
114
|
-
`[${
|
|
95
|
+
`[${index + 1}] ${project.title}`
|
|
115
96
|
);
|
|
116
|
-
}
|
|
97
|
+
});
|
|
117
98
|
|
|
118
99
|
console.log("");
|
|
119
100
|
|
|
120
|
-
// CLI input
|
|
121
101
|
const rl = readline.createInterface({
|
|
122
102
|
input: process.stdin,
|
|
123
103
|
output: process.stdout
|
|
124
104
|
});
|
|
125
105
|
|
|
126
|
-
|
|
127
|
-
const ans = await question(
|
|
106
|
+
const answer = await question(
|
|
128
107
|
rl,
|
|
129
108
|
`Pick (1-${projects.length}): `
|
|
130
109
|
);
|
|
131
110
|
|
|
132
|
-
let choice = parseInt(
|
|
111
|
+
let choice = parseInt(answer);
|
|
133
112
|
|
|
134
113
|
if (
|
|
135
114
|
isNaN(choice) ||
|
|
136
115
|
choice < 1 ||
|
|
137
116
|
choice > projects.length
|
|
138
117
|
) {
|
|
139
|
-
|
|
140
118
|
choice = 1;
|
|
141
119
|
}
|
|
142
120
|
|
|
143
|
-
const selected =
|
|
144
|
-
projects[choice - 1];
|
|
121
|
+
const selected = projects[choice - 1];
|
|
145
122
|
|
|
146
|
-
// Ask project name
|
|
147
123
|
const projectName = await question(
|
|
148
124
|
rl,
|
|
149
125
|
"Project name: "
|
|
@@ -151,38 +127,29 @@ async function main() {
|
|
|
151
127
|
|
|
152
128
|
rl.close();
|
|
153
129
|
|
|
154
|
-
const
|
|
130
|
+
const templatePath = path.join(
|
|
131
|
+
templatesDir,
|
|
132
|
+
selected.templateDir
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const targetPath = path.join(
|
|
155
136
|
process.cwd(),
|
|
156
137
|
projectName
|
|
157
138
|
);
|
|
158
139
|
|
|
159
|
-
|
|
160
|
-
if (fs.existsSync(target)) {
|
|
140
|
+
if (fs.existsSync(targetPath)) {
|
|
161
141
|
|
|
162
|
-
console.log("");
|
|
163
142
|
console.log(
|
|
164
|
-
"Folder already exists
|
|
143
|
+
"Folder already exists"
|
|
165
144
|
);
|
|
166
145
|
|
|
167
146
|
process.exit(1);
|
|
168
147
|
}
|
|
169
148
|
|
|
170
|
-
// Template path
|
|
171
|
-
const templatePath = path.join(
|
|
172
|
-
TEMPLATES,
|
|
173
|
-
selected.templateDir
|
|
174
|
-
);
|
|
175
|
-
|
|
176
149
|
console.log("");
|
|
177
|
-
console.log(
|
|
178
|
-
"Creating project..."
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
// Copy files
|
|
182
|
-
copyTree(templatePath, target);
|
|
150
|
+
console.log("Creating project...");
|
|
183
151
|
|
|
184
|
-
|
|
185
|
-
ensureEnvFromExample(target);
|
|
152
|
+
copyTree(templatePath, targetPath);
|
|
186
153
|
|
|
187
154
|
console.log("");
|
|
188
155
|
console.log(
|
|
@@ -190,11 +157,9 @@ async function main() {
|
|
|
190
157
|
);
|
|
191
158
|
|
|
192
159
|
console.log("");
|
|
193
|
-
|
|
194
160
|
console.log(`cd ${projectName}`);
|
|
195
161
|
|
|
196
162
|
console.log("");
|
|
197
|
-
|
|
198
163
|
console.log(
|
|
199
164
|
"Frontend:"
|
|
200
165
|
);
|
|
@@ -214,9 +179,4 @@ async function main() {
|
|
|
214
179
|
);
|
|
215
180
|
}
|
|
216
181
|
|
|
217
|
-
main()
|
|
218
|
-
|
|
219
|
-
console.error(err);
|
|
220
|
-
|
|
221
|
-
process.exit(1);
|
|
222
|
-
});
|
|
182
|
+
main();
|