sk-test-node-deploy 1.0.3 → 1.0.5
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 +47 -34
- 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,7 +82,7 @@ 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
88
|
// Step 4: Install production dependencies
|
|
@@ -76,22 +104,12 @@ async function createProject(projectName) {
|
|
|
76
104
|
"multer",
|
|
77
105
|
];
|
|
78
106
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
cwd: targetPath,
|
|
85
|
-
stdio: "inherit",
|
|
86
|
-
shell: true,
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// Add Windows-specific options
|
|
90
|
-
if (os.platform() === "win32") {
|
|
91
|
-
execOptions.windowsVerbatimArguments = false;
|
|
92
|
-
}
|
|
107
|
+
await runCommand(
|
|
108
|
+
packageManager,
|
|
109
|
+
[packageManager === "npm" ? "install" : "add", ...prodDeps],
|
|
110
|
+
{ cwd: targetPath },
|
|
111
|
+
);
|
|
93
112
|
|
|
94
|
-
execSync(prodCmd, execOptions);
|
|
95
113
|
installSpinner.succeed(chalk.green("Production dependencies installed!"));
|
|
96
114
|
} catch (error) {
|
|
97
115
|
installSpinner.fail(
|
|
@@ -120,20 +138,13 @@ async function createProject(projectName) {
|
|
|
120
138
|
"nodemon",
|
|
121
139
|
];
|
|
122
140
|
|
|
123
|
-
const
|
|
124
|
-
|
|
141
|
+
const devArgs =
|
|
142
|
+
packageManager === "npm"
|
|
143
|
+
? ["install", "-D", ...devDeps]
|
|
144
|
+
: ["add", "-D", ...devDeps];
|
|
125
145
|
|
|
126
|
-
|
|
127
|
-
cwd: targetPath,
|
|
128
|
-
stdio: "inherit",
|
|
129
|
-
shell: true,
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
if (os.platform() === "win32") {
|
|
133
|
-
execOptions.windowsVerbatimArguments = false;
|
|
134
|
-
}
|
|
146
|
+
await runCommand(packageManager, devArgs, { cwd: targetPath });
|
|
135
147
|
|
|
136
|
-
execSync(devCmd, execOptions);
|
|
137
148
|
devInstallSpinner.succeed(chalk.green("Dev dependencies installed!"));
|
|
138
149
|
} catch (error) {
|
|
139
150
|
devInstallSpinner.fail(chalk.red("Failed to install dev dependencies"));
|
|
@@ -144,8 +155,10 @@ async function createProject(projectName) {
|
|
|
144
155
|
// Step 6: Initialize git (optional)
|
|
145
156
|
const gitSpinner = ora("Initializing git repository...").start();
|
|
146
157
|
try {
|
|
147
|
-
|
|
148
|
-
|
|
158
|
+
await runCommand("git", ["init"], {
|
|
159
|
+
cwd: targetPath,
|
|
160
|
+
stdio: "ignore",
|
|
161
|
+
});
|
|
149
162
|
gitSpinner.succeed(chalk.green("Git repository initialized!"));
|
|
150
163
|
} catch (error) {
|
|
151
164
|
gitSpinner.warn(chalk.yellow("Git not found or initialization skipped"));
|
|
@@ -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";
|