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.
Files changed (2) hide show
  1. package/bin/index.js +67 -202
  2. package/package.json +21 -14
package/bin/index.js CHANGED
@@ -1,222 +1,87 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const fs = require("fs");
4
- const path = require("path");
5
- const readline = require("readline");
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 PKG_ROOT = path.join(__dirname, "..");
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
8
12
 
9
- const TEMPLATES = path.join(
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
- const d = path.join(dest, name.name);
40
-
41
- if (name.isDirectory()) {
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
- // Create .env from example
62
- function ensureEnvFromExample(projectRoot) {
63
-
64
- const backend = path.join(
65
- projectRoot,
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
- if (
80
- fs.existsSync(example) &&
81
- !fs.existsSync(envFile)
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
- async function main() {
89
-
90
- // Read manifest
91
- const manifest = JSON.parse(
92
- fs.readFileSync(MANIFEST, "utf8")
93
- );
94
-
95
- const projects = manifest.projects;
96
-
97
- if (!projects.length) {
98
-
99
- console.log(
100
- "No templates found."
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
- // Show projects
107
- console.log("");
108
-
109
- for (let i = 0; i < projects.length; i++) {
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
- console.log(
199
- "Frontend:"
200
- );
57
+ const templatePath = path.join(
58
+ templatesDir,
59
+ answers.template
60
+ );
201
61
 
202
- console.log(
203
- "cd frontend && npm install && npm run dev"
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
- console.log("");
68
+ // 🚀 Spinner
69
+ const spinner = ora("Creating project...").start();
207
70
 
208
- console.log(
209
- "Backend:"
210
- );
71
+ try {
72
+ // 📂 Copy template into new folder
73
+ await fs.copy(templatePath, projectPath);
211
74
 
212
- console.log(
213
- "cd backend && npm install && npm run dev"
75
+ spinner.succeed(
76
+ chalk.green("Project created successfully!")
214
77
  );
215
- }
216
-
217
- main().catch((err) => {
218
78
 
219
- console.error(err);
220
-
221
- process.exit(1);
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.7",
4
- "description": "",
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
- "main": "index.js",
9
- "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
11
- },
12
- "keywords": [],
13
- "author": "",
14
- "license": "ISC",
15
- "type": "commonjs",
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.2",
18
- "fs-extra": "^11.3.5",
19
- "inquirer": "^13.4.3",
20
- "ora": "^9.4.0"
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
  }