create-jinmankn-app 1.0.1 → 1.0.3
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 +101 -51
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -1,76 +1,126 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
3
|
+
const inquirer = require("inquirer").default;
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const ora = require("ora").default;
|
|
7
|
+
const chalk = require("chalk");
|
|
8
|
+
const { execSync } = require("child_process");
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
const projectName = process.argv[2];
|
|
10
|
+
const templatesDir = path.join(__dirname, "../templates");
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
// Check templates folder exists
|
|
13
|
+
if (!fs.existsSync(templatesDir)) {
|
|
14
|
+
console.log(chalk.red("Templates folder not found!"));
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Get templates automatically
|
|
19
|
+
const templates = fs
|
|
20
|
+
.readdirSync(templatesDir)
|
|
21
|
+
.filter((dir) =>
|
|
22
|
+
fs.lstatSync(path.join(templatesDir, dir)).isDirectory()
|
|
23
|
+
);
|
|
16
24
|
|
|
25
|
+
// No templates check
|
|
26
|
+
if (templates.length === 0) {
|
|
27
|
+
console.log(chalk.red("No templates found!"));
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function createProject() {
|
|
32
|
+
// Prompt user
|
|
17
33
|
const answers = await inquirer.prompt([
|
|
18
34
|
{
|
|
19
|
-
type:
|
|
20
|
-
name:
|
|
21
|
-
message:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
type: "input",
|
|
36
|
+
name: "projectName",
|
|
37
|
+
message: "Project name:"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: "list",
|
|
41
|
+
name: "template",
|
|
42
|
+
message: "Choose a template:",
|
|
43
|
+
choices: templates.map((t) => ({
|
|
44
|
+
name: t,
|
|
45
|
+
value: t
|
|
46
|
+
}))
|
|
27
47
|
}
|
|
28
48
|
]);
|
|
29
49
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
50
|
+
const projectPath = path.join(
|
|
51
|
+
process.cwd(),
|
|
52
|
+
answers.projectName
|
|
53
|
+
);
|
|
34
54
|
|
|
35
55
|
const templatePath = path.join(
|
|
36
|
-
|
|
37
|
-
|
|
56
|
+
templatesDir,
|
|
57
|
+
answers.template
|
|
38
58
|
);
|
|
39
59
|
|
|
40
|
-
|
|
41
|
-
|
|
60
|
+
// Prevent overwrite
|
|
61
|
+
if (fs.existsSync(projectPath)) {
|
|
62
|
+
console.log(chalk.red("Folder already exists!"));
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Spinner
|
|
67
|
+
const spinner = ora("Creating project...").start();
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
// Copy template
|
|
71
|
+
await fs.copy(templatePath, projectPath);
|
|
72
|
+
|
|
73
|
+
// Install frontend dependencies
|
|
74
|
+
const frontendPath = path.join(projectPath, "frontend");
|
|
75
|
+
|
|
76
|
+
if (fs.existsSync(frontendPath)) {
|
|
77
|
+
spinner.text = "Installing frontend dependencies...";
|
|
42
78
|
|
|
43
|
-
|
|
79
|
+
execSync("npm install", {
|
|
80
|
+
cwd: frontendPath,
|
|
81
|
+
stdio: "inherit"
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Install backend dependencies
|
|
86
|
+
const backendPath = path.join(projectPath, "backend");
|
|
87
|
+
|
|
88
|
+
if (fs.existsSync(backendPath)) {
|
|
89
|
+
spinner.text = "Installing backend dependencies...";
|
|
44
90
|
|
|
45
|
-
|
|
46
|
-
|
|
91
|
+
execSync("npm install", {
|
|
92
|
+
cwd: backendPath,
|
|
93
|
+
stdio: "inherit"
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
spinner.succeed(
|
|
98
|
+
chalk.green("Project created successfully!")
|
|
99
|
+
);
|
|
47
100
|
|
|
48
|
-
|
|
49
|
-
cwd: path.join(projectPath, 'frontend'),
|
|
50
|
-
stdio: 'inherit',
|
|
51
|
-
});
|
|
101
|
+
console.log("\n");
|
|
52
102
|
|
|
53
|
-
|
|
54
|
-
console.log('Installing backend dependencies...');
|
|
103
|
+
console.log(chalk.cyan("Next steps:"));
|
|
55
104
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
105
|
+
console.log(
|
|
106
|
+
chalk.white(`cd ${answers.projectName}`)
|
|
107
|
+
);
|
|
60
108
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
109
|
+
console.log(
|
|
110
|
+
chalk.white("cd frontend && npm run dev")
|
|
111
|
+
);
|
|
64
112
|
|
|
65
|
-
|
|
113
|
+
console.log(
|
|
114
|
+
chalk.white("cd backend && npm run dev")
|
|
115
|
+
);
|
|
66
116
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
117
|
+
} catch (err) {
|
|
118
|
+
spinner.fail(
|
|
119
|
+
chalk.red("Failed to create project")
|
|
120
|
+
);
|
|
70
121
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
console.log('cd frontend && npm run dev');
|
|
122
|
+
console.log(err);
|
|
123
|
+
}
|
|
74
124
|
}
|
|
75
125
|
|
|
76
126
|
createProject();
|