Spaces:
Running
Running
Update ftp-upload.js
Browse files- ftp-upload.js +57 -3
ftp-upload.js
CHANGED
@@ -1,5 +1,59 @@
|
|
1 |
-
|
2 |
-
const { execSync } = require("child_process");
|
3 |
const path = require("path");
|
4 |
const repoPath = path.join(__dirname, "dist");
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const { execSync, exec, spawn } = require("child_process");
|
|
|
2 |
const path = require("path");
|
3 |
const repoPath = path.join(__dirname, "dist");
|
4 |
+
|
5 |
+
function runWithExecSync() {
|
6 |
+
return new Promise((resolve, reject) => {
|
7 |
+
try {
|
8 |
+
execSync("sh upload.sh", { cwd: repoPath, stdio: "inherit" });
|
9 |
+
resolve("execSync success");
|
10 |
+
} catch (err) {
|
11 |
+
reject(err);
|
12 |
+
}
|
13 |
+
});
|
14 |
+
}
|
15 |
+
|
16 |
+
function runWithExec() {
|
17 |
+
return new Promise((resolve, reject) => {
|
18 |
+
exec("sh upload.sh", { cwd: repoPath }, (error, stdout, stderr) => {
|
19 |
+
if (error) {
|
20 |
+
reject(error);
|
21 |
+
return;
|
22 |
+
}
|
23 |
+
console.log(stdout);
|
24 |
+
resolve("exec success");
|
25 |
+
});
|
26 |
+
});
|
27 |
+
}
|
28 |
+
|
29 |
+
function runWithSpawn() {
|
30 |
+
return new Promise((resolve, reject) => {
|
31 |
+
const child = spawn("sh", ["upload.sh"], { cwd: repoPath, stdio: "inherit" });
|
32 |
+
child.on("close", (code) => {
|
33 |
+
if (code === 0) {
|
34 |
+
resolve("spawn success");
|
35 |
+
} else {
|
36 |
+
reject(new Error(`spawn exited with code ${code}`));
|
37 |
+
}
|
38 |
+
});
|
39 |
+
});
|
40 |
+
}
|
41 |
+
|
42 |
+
(async () => {
|
43 |
+
try {
|
44 |
+
await runWithExecSync();
|
45 |
+
} catch (e1) {
|
46 |
+
console.error("execSync failed:", e1);
|
47 |
+
try {
|
48 |
+
await runWithExec();
|
49 |
+
} catch (e2) {
|
50 |
+
console.error("exec failed:", e2);
|
51 |
+
try {
|
52 |
+
await runWithSpawn();
|
53 |
+
} catch (e3) {
|
54 |
+
console.error("spawn failed:", e3);
|
55 |
+
process.exit(1);
|
56 |
+
}
|
57 |
+
}
|
58 |
+
}
|
59 |
+
})();
|