create-jinmankn-app 1.0.6 → 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.
Files changed (2) hide show
  1. package/bin/index.js +132 -136
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -1,186 +1,182 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const inquirer = require("inquirer").default;
4
- const fs = require("fs-extra");
3
+ const fs = require("fs");
5
4
  const path = require("path");
6
- const ora = require("ora").default;
7
- const chalk = require("chalk");
8
- const { execSync } = require("child_process");
5
+ const readline = require("readline");
9
6
 
10
- const templatesDir = path.join(__dirname, "../templates");
7
+ const templatesDir = path.join(
8
+ __dirname,
9
+ "../templates"
10
+ );
11
+
12
+ const manifestPath = path.join(
13
+ templatesDir,
14
+ "projects.json"
15
+ );
11
16
 
12
- // Check templates folder exists
13
- if (!fs.existsSync(templatesDir)) {
14
- console.log(chalk.red("Templates folder not found!"));
15
- process.exit(1);
17
+ function question(rl, prompt) {
18
+ return new Promise((resolve) =>
19
+ rl.question(prompt, resolve)
20
+ );
16
21
  }
17
22
 
18
- // Template metadata
19
- const templateChoices = [
20
- {
21
- name: "🏥 Hospital Management System",
22
- value: "hospital-faisal"
23
- },
24
- {
25
- name: "🗳️ BLUEPRINT",
26
- value: "blueprint"
27
- },
28
- {
29
- name: "📦 Student Fee Management System",
30
- value: "chom"
31
- }
32
- ];
23
+ function copyTree(src, dest) {
33
24
 
34
- // Get actual template folders
35
- const templates = fs
36
- .readdirSync(templatesDir)
37
- .filter((dir) =>
38
- fs.lstatSync(path.join(templatesDir, dir)).isDirectory()
39
- );
25
+ fs.mkdirSync(dest, {
26
+ recursive: true
27
+ });
40
28
 
41
- // Filter only existing templates
42
- const availableTemplates = templateChoices.filter((template) =>
43
- templates.includes(template.value)
44
- );
29
+ const entries = fs.readdirSync(src, {
30
+ withFileTypes: true
31
+ });
45
32
 
46
- // No templates check
47
- if (availableTemplates.length === 0) {
48
- console.log(chalk.red("No templates found!"));
49
- process.exit(1);
50
- }
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 {
51
58
 
52
- async function createProject() {
53
-
54
- // Prompt user
55
- const answers = await inquirer.prompt([
56
- {
57
- type: "input",
58
- name: "projectName",
59
- message: "Project name:"
60
- },
61
- {
62
- type: "list",
63
- name: "templates",
64
- message: "Choose a template:",
65
- choices: availableTemplates
59
+ fs.copyFileSync(srcPath, destPath);
66
60
  }
67
- ]);
61
+ }
62
+ }
68
63
 
69
- const projectPath = path.join(
70
- process.cwd(),
71
- answers.projectName
72
- );
64
+ async function main() {
73
65
 
74
- const templatePath = path.join(
75
- templatesDir,
76
- answers.template
77
- );
66
+ if (!fs.existsSync(manifestPath)) {
78
67
 
79
- // Prevent overwrite
80
- if (fs.existsSync(projectPath)) {
81
68
  console.log(
82
- chalk.red("Folder already exists!")
69
+ "projects.json not found"
83
70
  );
84
71
 
85
72
  process.exit(1);
86
73
  }
87
74
 
88
- // Spinner
89
- const spinner = ora(
90
- "Creating project..."
91
- ).start();
75
+ const manifest = JSON.parse(
76
+ fs.readFileSync(manifestPath, "utf8")
77
+ );
92
78
 
93
- try {
79
+ const projects = manifest.projects;
94
80
 
95
- // Copy template
96
- await fs.copy(templatePath, projectPath);
81
+ if (!projects.length) {
97
82
 
98
- // Install frontend dependencies
99
- const frontendPath = path.join(
100
- projectPath,
101
- "frontend"
83
+ console.log(
84
+ "No templates found"
102
85
  );
103
86
 
104
- if (fs.existsSync(frontendPath)) {
87
+ process.exit(1);
88
+ }
105
89
 
106
- spinner.text =
107
- "Installing frontend dependencies...";
90
+ console.log("");
108
91
 
109
- execSync("npm install", {
110
- cwd: frontendPath,
111
- stdio: "inherit"
112
- });
113
- }
92
+ projects.forEach((project, index) => {
114
93
 
115
- // Install backend dependencies
116
- const backendPath = path.join(
117
- projectPath,
118
- "backend"
94
+ console.log(
95
+ `[${index + 1}] ${project.title}`
119
96
  );
97
+ });
120
98
 
121
- if (fs.existsSync(backendPath)) {
99
+ console.log("");
122
100
 
123
- spinner.text =
124
- "Installing backend dependencies...";
101
+ const rl = readline.createInterface({
102
+ input: process.stdin,
103
+ output: process.stdout
104
+ });
125
105
 
126
- execSync("npm install", {
127
- cwd: backendPath,
128
- stdio: "inherit"
129
- });
130
- }
106
+ const answer = await question(
107
+ rl,
108
+ `Pick (1-${projects.length}): `
109
+ );
131
110
 
132
- spinner.succeed(
133
- chalk.green(
134
- "Project created successfully!"
135
- )
136
- );
111
+ let choice = parseInt(answer);
137
112
 
138
- console.log("\n");
113
+ if (
114
+ isNaN(choice) ||
115
+ choice < 1 ||
116
+ choice > projects.length
117
+ ) {
118
+ choice = 1;
119
+ }
139
120
 
140
- console.log(
141
- chalk.cyan("Next steps:")
142
- );
121
+ const selected = projects[choice - 1];
143
122
 
144
- console.log(
145
- chalk.white(
146
- `cd ${answers.projectName}`
147
- )
148
- );
123
+ const projectName = await question(
124
+ rl,
125
+ "Project name: "
126
+ );
149
127
 
150
- console.log("");
128
+ rl.close();
151
129
 
152
- console.log(
153
- chalk.yellow("Frontend:")
154
- );
130
+ const templatePath = path.join(
131
+ templatesDir,
132
+ selected.templateDir
133
+ );
155
134
 
156
- console.log(
157
- chalk.white(
158
- "cd frontend && npm run dev"
159
- )
160
- );
135
+ const targetPath = path.join(
136
+ process.cwd(),
137
+ projectName
138
+ );
161
139
 
162
- console.log("");
140
+ if (fs.existsSync(targetPath)) {
163
141
 
164
142
  console.log(
165
- chalk.yellow("Backend:")
143
+ "Folder already exists"
166
144
  );
167
145
 
168
- console.log(
169
- chalk.white(
170
- "cd backend && npm run dev"
171
- )
172
- );
146
+ process.exit(1);
147
+ }
173
148
 
174
- } catch (err) {
149
+ console.log("");
150
+ console.log("Creating project...");
175
151
 
176
- spinner.fail(
177
- chalk.red(
178
- "Failed to create project"
179
- )
180
- );
152
+ copyTree(templatePath, targetPath);
181
153
 
182
- console.log(err);
183
- }
154
+ console.log("");
155
+ console.log(
156
+ "Project created successfully!"
157
+ );
158
+
159
+ console.log("");
160
+ console.log(`cd ${projectName}`);
161
+
162
+ console.log("");
163
+ console.log(
164
+ "Frontend:"
165
+ );
166
+
167
+ console.log(
168
+ "cd frontend && npm install && npm run dev"
169
+ );
170
+
171
+ console.log("");
172
+
173
+ console.log(
174
+ "Backend:"
175
+ );
176
+
177
+ console.log(
178
+ "cd backend && npm install && npm run dev"
179
+ );
184
180
  }
185
181
 
186
- createProject();
182
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-jinmankn-app",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "create-jinmankn-app": "./bin/index.js"