sk-test-node-deploy 1.0.3 ā 1.0.6
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/lib/index.js +124 -111
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,13 +1,41 @@
|
|
|
1
1
|
const fs = require("fs-extra");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
const {
|
|
3
|
+
const { spawn } = require("child_process");
|
|
4
4
|
const chalk = require("chalk");
|
|
5
5
|
const ora = require("ora");
|
|
6
6
|
const os = require("os");
|
|
7
7
|
|
|
8
|
+
// Helper function to run commands with proper Windows support
|
|
9
|
+
function runCommand(command, args, options = {}) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const isWindows = os.platform() === "win32";
|
|
12
|
+
const cmd = isWindows ? "cmd" : command;
|
|
13
|
+
const cmdArgs = isWindows ? ["/c", command, ...args] : args;
|
|
14
|
+
|
|
15
|
+
const child = spawn(cmd, cmdArgs, {
|
|
16
|
+
...options,
|
|
17
|
+
shell: false,
|
|
18
|
+
stdio: options.stdio || "inherit",
|
|
19
|
+
env: { ...process.env, ...options.env },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
child.on("error", (error) => {
|
|
23
|
+
reject(error);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
child.on("close", (code) => {
|
|
27
|
+
if (code !== 0) {
|
|
28
|
+
reject(new Error(`Command failed with exit code ${code}`));
|
|
29
|
+
} else {
|
|
30
|
+
resolve();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
8
36
|
async function createProject(projectName) {
|
|
9
37
|
const targetPath = path.join(process.cwd(), projectName);
|
|
10
|
-
const templatePath = path.join(__dirname, "
|
|
38
|
+
const templatePath = path.join(__dirname, "..", "template");
|
|
11
39
|
|
|
12
40
|
// Debug: Check if template exists
|
|
13
41
|
if (!fs.existsSync(templatePath)) {
|
|
@@ -54,124 +82,109 @@ async function createProject(projectName) {
|
|
|
54
82
|
}
|
|
55
83
|
|
|
56
84
|
// Step 3: Detect package manager
|
|
57
|
-
const packageManager = detectPackageManager();
|
|
85
|
+
const packageManager = await detectPackageManager();
|
|
58
86
|
console.log(chalk.gray(`Using package manager: ${packageManager}\n`));
|
|
59
87
|
|
|
60
|
-
// Step 4: Install production dependencies
|
|
61
|
-
console.log(chalk.blue("š¦ Installing dependencies...\n"));
|
|
62
|
-
const installSpinner = ora("Installing production dependencies...").start();
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
//
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
execSync("git --version", { stdio: "ignore", shell: true });
|
|
148
|
-
execSync("git init", { cwd: targetPath, stdio: "ignore", shell: true });
|
|
149
|
-
gitSpinner.succeed(chalk.green("Git repository initialized!"));
|
|
150
|
-
} catch (error) {
|
|
151
|
-
gitSpinner.warn(chalk.yellow("Git not found or initialization skipped"));
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Step 7: Create .env from .env.example if exists
|
|
155
|
-
const envExamplePath = path.join(targetPath, ".env.example");
|
|
156
|
-
const envPath = path.join(targetPath, ".env");
|
|
157
|
-
|
|
158
|
-
if (fs.existsSync(envExamplePath) && !fs.existsSync(envPath)) {
|
|
159
|
-
await fs.copy(envExamplePath, envPath);
|
|
160
|
-
console.log(chalk.green("ā .env file created from .env.example"));
|
|
161
|
-
}
|
|
88
|
+
// // Step 4: Install production dependencies
|
|
89
|
+
// console.log(chalk.blue("š¦ Installing dependencies...\n"));
|
|
90
|
+
// const installSpinner = ora("Installing production dependencies...").start();
|
|
91
|
+
|
|
92
|
+
// try {
|
|
93
|
+
// const prodDeps = [
|
|
94
|
+
// "bcryptjs",
|
|
95
|
+
// "compression",
|
|
96
|
+
// "cors",
|
|
97
|
+
// "dotenv",
|
|
98
|
+
// "express",
|
|
99
|
+
// "helmet",
|
|
100
|
+
// "joi",
|
|
101
|
+
// "jsonwebtoken",
|
|
102
|
+
// "mongoose",
|
|
103
|
+
// "socket.io",
|
|
104
|
+
// "multer",
|
|
105
|
+
// ];
|
|
106
|
+
|
|
107
|
+
// await runCommand(
|
|
108
|
+
// packageManager,
|
|
109
|
+
// [packageManager === "npm" ? "install" : "add", ...prodDeps],
|
|
110
|
+
// { cwd: targetPath },
|
|
111
|
+
// );
|
|
112
|
+
|
|
113
|
+
// installSpinner.succeed(chalk.green("Production dependencies installed!"));
|
|
114
|
+
// } catch (error) {
|
|
115
|
+
// installSpinner.fail(
|
|
116
|
+
// chalk.red("Failed to install production dependencies"),
|
|
117
|
+
// );
|
|
118
|
+
// console.error(chalk.red(error.message));
|
|
119
|
+
// throw error;
|
|
120
|
+
// }
|
|
121
|
+
|
|
122
|
+
// // Step 5: Install dev dependencies
|
|
123
|
+
// const devInstallSpinner = ora("Installing dev dependencies...").start();
|
|
124
|
+
|
|
125
|
+
// try {
|
|
126
|
+
// const devDeps = [
|
|
127
|
+
// "typescript",
|
|
128
|
+
// "ts-node",
|
|
129
|
+
// "@types/node",
|
|
130
|
+
// "@types/express",
|
|
131
|
+
// "@types/bcryptjs",
|
|
132
|
+
// "@types/compression",
|
|
133
|
+
// "@types/cors",
|
|
134
|
+
// "@types/jsonwebtoken",
|
|
135
|
+
// "@types/mongoose",
|
|
136
|
+
// "@types/socket.io",
|
|
137
|
+
// "@types/multer",
|
|
138
|
+
// "nodemon",
|
|
139
|
+
// ];
|
|
140
|
+
|
|
141
|
+
// const devArgs =
|
|
142
|
+
// packageManager === "npm"
|
|
143
|
+
// ? ["install", "-D", ...devDeps]
|
|
144
|
+
// : ["add", "-D", ...devDeps];
|
|
145
|
+
|
|
146
|
+
// await runCommand(packageManager, devArgs, { cwd: targetPath });
|
|
147
|
+
|
|
148
|
+
// devInstallSpinner.succeed(chalk.green("Dev dependencies installed!"));
|
|
149
|
+
// } catch (error) {
|
|
150
|
+
// devInstallSpinner.fail(chalk.red("Failed to install dev dependencies"));
|
|
151
|
+
// console.error(chalk.red(error.message));
|
|
152
|
+
// throw error;
|
|
153
|
+
// }
|
|
154
|
+
|
|
155
|
+
// // Step 6: Initialize git (optional)
|
|
156
|
+
// const gitSpinner = ora("Initializing git repository...").start();
|
|
157
|
+
// try {
|
|
158
|
+
// await runCommand("git", ["init"], {
|
|
159
|
+
// cwd: targetPath,
|
|
160
|
+
// stdio: "ignore",
|
|
161
|
+
// });
|
|
162
|
+
// gitSpinner.succeed(chalk.green("Git repository initialized!"));
|
|
163
|
+
// } catch (error) {
|
|
164
|
+
// gitSpinner.warn(chalk.yellow("Git not found or initialization skipped"));
|
|
165
|
+
// }
|
|
166
|
+
|
|
167
|
+
// // Step 7: Create .env from .env.example if exists
|
|
168
|
+
// const envExamplePath = path.join(targetPath, ".env.example");
|
|
169
|
+
// const envPath = path.join(targetPath, ".env");
|
|
170
|
+
|
|
171
|
+
// if (fs.existsSync(envExamplePath) && !fs.existsSync(envPath)) {
|
|
172
|
+
// await fs.copy(envExamplePath, envPath);
|
|
173
|
+
// console.log(chalk.green("ā .env file created from .env.example"));
|
|
174
|
+
// }
|
|
162
175
|
|
|
163
176
|
// Success message
|
|
164
177
|
console.log(chalk.green.bold("\n⨠Project created successfully!\n"));
|
|
165
|
-
console.log(chalk.cyan("To get started, run:"));
|
|
166
|
-
console.log(chalk.white(` cd ${projectName}`));
|
|
167
|
-
console.log(chalk.white(" npm run dev\n"));
|
|
178
|
+
// console.log(chalk.cyan("To get started, run:"));
|
|
179
|
+
// console.log(chalk.white(` cd ${projectName}`));
|
|
180
|
+
// console.log(chalk.white(" npm run dev\n"));
|
|
168
181
|
} catch (error) {
|
|
169
182
|
console.error(chalk.red("\nā Error creating project:"), error.message);
|
|
170
183
|
|
|
171
184
|
// Cleanup on error
|
|
172
185
|
if (fs.existsSync(targetPath)) {
|
|
173
186
|
console.log(chalk.yellow("Cleaning up..."));
|
|
174
|
-
await fs.remove(targetPath);
|
|
187
|
+
// await fs.remove(targetPath);
|
|
175
188
|
}
|
|
176
189
|
|
|
177
190
|
process.exit(1);
|
|
@@ -179,9 +192,9 @@ async function createProject(projectName) {
|
|
|
179
192
|
}
|
|
180
193
|
|
|
181
194
|
// Detect which package manager is available
|
|
182
|
-
function detectPackageManager() {
|
|
195
|
+
async function detectPackageManager() {
|
|
183
196
|
try {
|
|
184
|
-
|
|
197
|
+
await runCommand("yarn", ["--version"], { stdio: "ignore" });
|
|
185
198
|
return "yarn";
|
|
186
199
|
} catch {
|
|
187
200
|
return "npm";
|