create-jinmankn-app 1.0.7 → 1.0.9
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 +67 -202
- package/package.json +21 -14
package/bin/index.js
CHANGED
|
@@ -1,222 +1,87 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import inquirer from "inquirer";
|
|
4
|
+
import fs from "fs-extra";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import ora from "ora";
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
import { fileURLToPath } from "url";
|
|
6
9
|
|
|
7
|
-
const
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
8
12
|
|
|
9
|
-
const
|
|
10
|
-
PKG_ROOT,
|
|
11
|
-
"templates"
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
const MANIFEST = path.join(
|
|
15
|
-
TEMPLATES,
|
|
16
|
-
"projects.json"
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
// Question helper
|
|
20
|
-
function question(rl, prompt) {
|
|
21
|
-
return new Promise((resolve) =>
|
|
22
|
-
rl.question(prompt, resolve)
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Copy folder recursively
|
|
27
|
-
function copyTree(src, dest) {
|
|
28
|
-
|
|
29
|
-
fs.mkdirSync(dest, {
|
|
30
|
-
recursive: true
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
for (const name of fs.readdirSync(src, {
|
|
34
|
-
withFileTypes: true
|
|
35
|
-
})) {
|
|
36
|
-
|
|
37
|
-
const s = path.join(src, name.name);
|
|
13
|
+
const templatesDir = path.join(__dirname, "../templates");
|
|
38
14
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// Ignore unnecessary folders
|
|
44
|
-
if (
|
|
45
|
-
name.name === "node_modules" ||
|
|
46
|
-
name.name === ".git" ||
|
|
47
|
-
name.name === "dist"
|
|
48
|
-
) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
copyTree(s, d);
|
|
53
|
-
|
|
54
|
-
} else {
|
|
55
|
-
|
|
56
|
-
fs.copyFileSync(s, d);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
15
|
+
// 🔒 Check templates folder exists
|
|
16
|
+
if (!fs.existsSync(templatesDir)) {
|
|
17
|
+
console.log(chalk.red("Templates folder not found!"));
|
|
18
|
+
process.exit(1);
|
|
59
19
|
}
|
|
60
20
|
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"backend"
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const example = path.join(
|
|
70
|
-
backend,
|
|
71
|
-
".env.example"
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
const envFile = path.join(
|
|
75
|
-
backend,
|
|
76
|
-
".env"
|
|
21
|
+
// 📦 Get templates (folders only)
|
|
22
|
+
const templates = fs
|
|
23
|
+
.readdirSync(templatesDir)
|
|
24
|
+
.filter((dir) =>
|
|
25
|
+
fs.lstatSync(path.join(templatesDir, dir)).isDirectory()
|
|
77
26
|
);
|
|
78
27
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
fs.copyFileSync(example, envFile);
|
|
85
|
-
}
|
|
28
|
+
// 🔒 No templates check
|
|
29
|
+
if (templates.length === 0) {
|
|
30
|
+
console.log(chalk.red("❌ No templates found!"));
|
|
31
|
+
process.exit(1);
|
|
86
32
|
}
|
|
87
33
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
process.exit(1);
|
|
34
|
+
// 🎯 Prompt user
|
|
35
|
+
const answers = await inquirer.prompt([
|
|
36
|
+
{
|
|
37
|
+
type: "input",
|
|
38
|
+
name: "projectName",
|
|
39
|
+
message: "Project name:"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: "list",
|
|
43
|
+
name: "template",
|
|
44
|
+
message: "Choose a template:",
|
|
45
|
+
choices: templates.map((t) => ({
|
|
46
|
+
name: `${t}`,
|
|
47
|
+
value: t
|
|
48
|
+
}))
|
|
104
49
|
}
|
|
50
|
+
]);
|
|
105
51
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const p = projects[i];
|
|
112
|
-
|
|
113
|
-
console.log(
|
|
114
|
-
`[${i + 1}] ${p.title}`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
console.log("");
|
|
119
|
-
|
|
120
|
-
// CLI input
|
|
121
|
-
const rl = readline.createInterface({
|
|
122
|
-
input: process.stdin,
|
|
123
|
-
output: process.stdout
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// Choose template
|
|
127
|
-
const ans = await question(
|
|
128
|
-
rl,
|
|
129
|
-
`Pick (1-${projects.length}): `
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
let choice = parseInt(ans);
|
|
133
|
-
|
|
134
|
-
if (
|
|
135
|
-
isNaN(choice) ||
|
|
136
|
-
choice < 1 ||
|
|
137
|
-
choice > projects.length
|
|
138
|
-
) {
|
|
139
|
-
|
|
140
|
-
choice = 1;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const selected =
|
|
144
|
-
projects[choice - 1];
|
|
145
|
-
|
|
146
|
-
// Ask project name
|
|
147
|
-
const projectName = await question(
|
|
148
|
-
rl,
|
|
149
|
-
"Project name: "
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
rl.close();
|
|
153
|
-
|
|
154
|
-
const target = path.resolve(
|
|
155
|
-
process.cwd(),
|
|
156
|
-
projectName
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
// Prevent overwrite
|
|
160
|
-
if (fs.existsSync(target)) {
|
|
161
|
-
|
|
162
|
-
console.log("");
|
|
163
|
-
console.log(
|
|
164
|
-
"Folder already exists."
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
process.exit(1);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Template path
|
|
171
|
-
const templatePath = path.join(
|
|
172
|
-
TEMPLATES,
|
|
173
|
-
selected.templateDir
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
console.log("");
|
|
177
|
-
console.log(
|
|
178
|
-
"Creating project..."
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
// Copy files
|
|
182
|
-
copyTree(templatePath, target);
|
|
183
|
-
|
|
184
|
-
// Create env
|
|
185
|
-
ensureEnvFromExample(target);
|
|
186
|
-
|
|
187
|
-
console.log("");
|
|
188
|
-
console.log(
|
|
189
|
-
"Project created successfully!"
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
console.log("");
|
|
193
|
-
|
|
194
|
-
console.log(`cd ${projectName}`);
|
|
195
|
-
|
|
196
|
-
console.log("");
|
|
52
|
+
const projectPath = path.join(
|
|
53
|
+
process.cwd(),
|
|
54
|
+
answers.projectName
|
|
55
|
+
);
|
|
197
56
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
57
|
+
const templatePath = path.join(
|
|
58
|
+
templatesDir,
|
|
59
|
+
answers.template
|
|
60
|
+
);
|
|
201
61
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
);
|
|
62
|
+
// 🔒 Prevent overwrite
|
|
63
|
+
if (fs.existsSync(projectPath)) {
|
|
64
|
+
console.log(chalk.red("Folder already exists!"));
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
205
67
|
|
|
206
|
-
|
|
68
|
+
// 🚀 Spinner
|
|
69
|
+
const spinner = ora("Creating project...").start();
|
|
207
70
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
);
|
|
71
|
+
try {
|
|
72
|
+
// 📂 Copy template into new folder
|
|
73
|
+
await fs.copy(templatePath, projectPath);
|
|
211
74
|
|
|
212
|
-
|
|
213
|
-
"
|
|
75
|
+
spinner.succeed(
|
|
76
|
+
chalk.green("Project created successfully!")
|
|
214
77
|
);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
main().catch((err) => {
|
|
218
78
|
|
|
219
|
-
console.
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
79
|
+
console.log("\n");
|
|
80
|
+
console.log(chalk.cyan("Next steps:"));
|
|
81
|
+
console.log(chalk.white(`cd ${answers.projectName}`));
|
|
82
|
+
console.log(chalk.white("npm install"));
|
|
83
|
+
console.log(chalk.white("npm run dev"));
|
|
84
|
+
} catch (err) {
|
|
85
|
+
spinner.fail(chalk.red("Failed to create project"));
|
|
86
|
+
console.log(err);
|
|
87
|
+
}
|
package/package.json
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-jinmankn-app",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"create-jinmankn-app": "./bin/index.js"
|
|
7
|
+
},"scripts": {
|
|
8
|
+
"pub": "npm version patch -m \"release: %s\" && npm publish --access public"
|
|
7
9
|
},
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"templates"
|
|
13
|
+
],
|
|
14
|
+
"description": "CLI tool to generate starter templates",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"cli",
|
|
17
|
+
"starter",
|
|
18
|
+
"template",
|
|
19
|
+
"node",
|
|
20
|
+
"react"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
16
23
|
"dependencies": {
|
|
17
|
-
"chalk": "^5.6.
|
|
18
|
-
"fs-extra": "^11.3.
|
|
19
|
-
"inquirer": "^
|
|
20
|
-
"ora": "^9.
|
|
24
|
+
"chalk": "^5.6.0",
|
|
25
|
+
"fs-extra": "^11.3.1",
|
|
26
|
+
"inquirer": "^12.9.4",
|
|
27
|
+
"ora": "^9.0.0"
|
|
21
28
|
}
|
|
22
29
|
}
|