create-jinmankn-app 1.0.8 → 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 +71 -166
  2. package/package.json +21 -14
package/bin/index.js CHANGED
@@ -1,182 +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");
6
-
7
- const templatesDir = path.join(
8
- __dirname,
9
- "../templates"
10
- );
11
-
12
- const manifestPath = path.join(
13
- templatesDir,
14
- "projects.json"
15
- );
16
-
17
- function question(rl, prompt) {
18
- return new Promise((resolve) =>
19
- rl.question(prompt, resolve)
20
- );
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";
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
12
+
13
+ const templatesDir = path.join(__dirname, "../templates");
14
+
15
+ // 🔒 Check templates folder exists
16
+ if (!fs.existsSync(templatesDir)) {
17
+ console.log(chalk.red("Templates folder not found!"));
18
+ process.exit(1);
21
19
  }
22
20
 
23
- function copyTree(src, dest) {
24
-
25
- fs.mkdirSync(dest, {
26
- recursive: true
27
- });
28
-
29
- const entries = fs.readdirSync(src, {
30
- withFileTypes: true
31
- });
32
-
33
- for (const entry of entries) {
34
-
35
- const srcPath = path.join(
36
- src,
37
- entry.name
38
- );
39
-
40
- const destPath = path.join(
41
- dest,
42
- entry.name
43
- );
44
-
45
- if (entry.isDirectory()) {
46
-
47
- if (
48
- entry.name === "node_modules" ||
49
- entry.name === ".git" ||
50
- entry.name === "dist"
51
- ) {
52
- continue;
53
- }
54
-
55
- copyTree(srcPath, destPath);
56
-
57
- } else {
58
-
59
- fs.copyFileSync(srcPath, destPath);
60
- }
61
- }
62
- }
63
-
64
- async function main() {
65
-
66
- if (!fs.existsSync(manifestPath)) {
67
-
68
- console.log(
69
- "projects.json not found"
70
- );
71
-
72
- process.exit(1);
73
- }
74
-
75
- const manifest = JSON.parse(
76
- fs.readFileSync(manifestPath, "utf8")
77
- );
78
-
79
- const projects = manifest.projects;
80
-
81
- if (!projects.length) {
82
-
83
- console.log(
84
- "No templates found"
85
- );
86
-
87
- process.exit(1);
88
- }
89
-
90
- console.log("");
91
-
92
- projects.forEach((project, index) => {
93
-
94
- console.log(
95
- `[${index + 1}] ${project.title}`
96
- );
97
- });
98
-
99
- console.log("");
100
-
101
- const rl = readline.createInterface({
102
- input: process.stdin,
103
- output: process.stdout
104
- });
105
-
106
- const answer = await question(
107
- rl,
108
- `Pick (1-${projects.length}): `
109
- );
110
-
111
- let choice = parseInt(answer);
112
-
113
- if (
114
- isNaN(choice) ||
115
- choice < 1 ||
116
- choice > projects.length
117
- ) {
118
- choice = 1;
119
- }
120
-
121
- const selected = projects[choice - 1];
122
-
123
- const projectName = await question(
124
- rl,
125
- "Project name: "
21
+ // 📦 Get templates (folders only)
22
+ const templates = fs
23
+ .readdirSync(templatesDir)
24
+ .filter((dir) =>
25
+ fs.lstatSync(path.join(templatesDir, dir)).isDirectory()
126
26
  );
127
27
 
128
- rl.close();
129
-
130
- const templatePath = path.join(
131
- templatesDir,
132
- selected.templateDir
133
- );
134
-
135
- const targetPath = path.join(
136
- process.cwd(),
137
- projectName
138
- );
139
-
140
- if (fs.existsSync(targetPath)) {
141
-
142
- console.log(
143
- "Folder already exists"
144
- );
28
+ // 🔒 No templates check
29
+ if (templates.length === 0) {
30
+ console.log(chalk.red("❌ No templates found!"));
31
+ process.exit(1);
32
+ }
145
33
 
146
- 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
+ }))
147
49
  }
50
+ ]);
148
51
 
149
- console.log("");
150
- console.log("Creating project...");
151
-
152
- copyTree(templatePath, targetPath);
153
-
154
- console.log("");
155
- console.log(
156
- "Project created successfully!"
157
- );
158
-
159
- console.log("");
160
- console.log(`cd ${projectName}`);
52
+ const projectPath = path.join(
53
+ process.cwd(),
54
+ answers.projectName
55
+ );
161
56
 
162
- console.log("");
163
- console.log(
164
- "Frontend:"
165
- );
57
+ const templatePath = path.join(
58
+ templatesDir,
59
+ answers.template
60
+ );
166
61
 
167
- console.log(
168
- "cd frontend && npm install && npm run dev"
169
- );
62
+ // 🔒 Prevent overwrite
63
+ if (fs.existsSync(projectPath)) {
64
+ console.log(chalk.red("Folder already exists!"));
65
+ process.exit(1);
66
+ }
170
67
 
171
- console.log("");
68
+ // 🚀 Spinner
69
+ const spinner = ora("Creating project...").start();
172
70
 
173
- console.log(
174
- "Backend:"
175
- );
71
+ try {
72
+ // 📂 Copy template into new folder
73
+ await fs.copy(templatePath, projectPath);
176
74
 
177
- console.log(
178
- "cd backend && npm install && npm run dev"
75
+ spinner.succeed(
76
+ chalk.green("Project created successfully!")
179
77
  );
180
- }
181
78
 
182
- main();
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.8",
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
  }