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