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.
- package/bin/index.js +132 -136
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -1,186 +1,182 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const fs = require("fs-extra");
|
|
3
|
+
const fs = require("fs");
|
|
5
4
|
const path = require("path");
|
|
6
|
-
const
|
|
7
|
-
const chalk = require("chalk");
|
|
8
|
-
const { execSync } = require("child_process");
|
|
5
|
+
const readline = require("readline");
|
|
9
6
|
|
|
10
|
-
const templatesDir = path.join(
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
function question(rl, prompt) {
|
|
18
|
+
return new Promise((resolve) =>
|
|
19
|
+
rl.question(prompt, resolve)
|
|
20
|
+
);
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.filter((dir) =>
|
|
38
|
-
fs.lstatSync(path.join(templatesDir, dir)).isDirectory()
|
|
39
|
-
);
|
|
25
|
+
fs.mkdirSync(dest, {
|
|
26
|
+
recursive: true
|
|
27
|
+
});
|
|
40
28
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
);
|
|
29
|
+
const entries = fs.readdirSync(src, {
|
|
30
|
+
withFileTypes: true
|
|
31
|
+
});
|
|
45
32
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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
|
-
|
|
70
|
-
process.cwd(),
|
|
71
|
-
answers.projectName
|
|
72
|
-
);
|
|
64
|
+
async function main() {
|
|
73
65
|
|
|
74
|
-
|
|
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
|
-
|
|
69
|
+
"projects.json not found"
|
|
83
70
|
);
|
|
84
71
|
|
|
85
72
|
process.exit(1);
|
|
86
73
|
}
|
|
87
74
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
).start();
|
|
75
|
+
const manifest = JSON.parse(
|
|
76
|
+
fs.readFileSync(manifestPath, "utf8")
|
|
77
|
+
);
|
|
92
78
|
|
|
93
|
-
|
|
79
|
+
const projects = manifest.projects;
|
|
94
80
|
|
|
95
|
-
|
|
96
|
-
await fs.copy(templatePath, projectPath);
|
|
81
|
+
if (!projects.length) {
|
|
97
82
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
projectPath,
|
|
101
|
-
"frontend"
|
|
83
|
+
console.log(
|
|
84
|
+
"No templates found"
|
|
102
85
|
);
|
|
103
86
|
|
|
104
|
-
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
105
89
|
|
|
106
|
-
|
|
107
|
-
"Installing frontend dependencies...";
|
|
90
|
+
console.log("");
|
|
108
91
|
|
|
109
|
-
|
|
110
|
-
cwd: frontendPath,
|
|
111
|
-
stdio: "inherit"
|
|
112
|
-
});
|
|
113
|
-
}
|
|
92
|
+
projects.forEach((project, index) => {
|
|
114
93
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
projectPath,
|
|
118
|
-
"backend"
|
|
94
|
+
console.log(
|
|
95
|
+
`[${index + 1}] ${project.title}`
|
|
119
96
|
);
|
|
97
|
+
});
|
|
120
98
|
|
|
121
|
-
|
|
99
|
+
console.log("");
|
|
122
100
|
|
|
123
|
-
|
|
124
|
-
|
|
101
|
+
const rl = readline.createInterface({
|
|
102
|
+
input: process.stdin,
|
|
103
|
+
output: process.stdout
|
|
104
|
+
});
|
|
125
105
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
106
|
+
const answer = await question(
|
|
107
|
+
rl,
|
|
108
|
+
`Pick (1-${projects.length}): `
|
|
109
|
+
);
|
|
131
110
|
|
|
132
|
-
|
|
133
|
-
chalk.green(
|
|
134
|
-
"Project created successfully!"
|
|
135
|
-
)
|
|
136
|
-
);
|
|
111
|
+
let choice = parseInt(answer);
|
|
137
112
|
|
|
138
|
-
|
|
113
|
+
if (
|
|
114
|
+
isNaN(choice) ||
|
|
115
|
+
choice < 1 ||
|
|
116
|
+
choice > projects.length
|
|
117
|
+
) {
|
|
118
|
+
choice = 1;
|
|
119
|
+
}
|
|
139
120
|
|
|
140
|
-
|
|
141
|
-
chalk.cyan("Next steps:")
|
|
142
|
-
);
|
|
121
|
+
const selected = projects[choice - 1];
|
|
143
122
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
);
|
|
123
|
+
const projectName = await question(
|
|
124
|
+
rl,
|
|
125
|
+
"Project name: "
|
|
126
|
+
);
|
|
149
127
|
|
|
150
|
-
|
|
128
|
+
rl.close();
|
|
151
129
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
130
|
+
const templatePath = path.join(
|
|
131
|
+
templatesDir,
|
|
132
|
+
selected.templateDir
|
|
133
|
+
);
|
|
155
134
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
);
|
|
135
|
+
const targetPath = path.join(
|
|
136
|
+
process.cwd(),
|
|
137
|
+
projectName
|
|
138
|
+
);
|
|
161
139
|
|
|
162
|
-
|
|
140
|
+
if (fs.existsSync(targetPath)) {
|
|
163
141
|
|
|
164
142
|
console.log(
|
|
165
|
-
|
|
143
|
+
"Folder already exists"
|
|
166
144
|
);
|
|
167
145
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
"cd backend && npm run dev"
|
|
171
|
-
)
|
|
172
|
-
);
|
|
146
|
+
process.exit(1);
|
|
147
|
+
}
|
|
173
148
|
|
|
174
|
-
|
|
149
|
+
console.log("");
|
|
150
|
+
console.log("Creating project...");
|
|
175
151
|
|
|
176
|
-
|
|
177
|
-
chalk.red(
|
|
178
|
-
"Failed to create project"
|
|
179
|
-
)
|
|
180
|
-
);
|
|
152
|
+
copyTree(templatePath, targetPath);
|
|
181
153
|
|
|
182
|
-
|
|
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
|
-
|
|
182
|
+
main();
|