Spaces:
Running
Running
console.log("ftp-uploading..............") | |
const { execSync, exec, spawn } = require("child_process"); | |
const path = require("path"); | |
const repoPath = path.join(__dirname, "dist"); | |
function runWithExecSync() { | |
return new Promise((resolve, reject) => { | |
try { | |
execSync("sh upload.sh", { cwd: repoPath, stdio: "inherit" }); | |
resolve("execSync success"); | |
} catch (err) { | |
reject(err); | |
} | |
}); | |
} | |
function runWithExec() { | |
return new Promise((resolve, reject) => { | |
exec("sh upload.sh", { cwd: repoPath }, (error, stdout, stderr) => { | |
if (error) { | |
reject(error); | |
return; | |
} | |
console.log(stdout); | |
resolve("exec success"); | |
}); | |
}); | |
} | |
function runWithSpawn() { | |
return new Promise((resolve, reject) => { | |
const child = spawn("sh", ["upload.sh"], { cwd: repoPath, stdio: "inherit" }); | |
child.on("close", (code) => { | |
if (code === 0) { | |
resolve("spawn success"); | |
} else { | |
reject(new Error(`spawn exited with code ${code}`)); | |
} | |
}); | |
}); | |
} | |
(async () => { | |
try { | |
await runWithExecSync(); | |
} catch (e1) { | |
console.error("execSync failed:", e1); | |
try { | |
await runWithExec(); | |
} catch (e2) { | |
console.error("exec failed:", e2); | |
try { | |
await runWithSpawn(); | |
} catch (e3) { | |
console.error("spawn failed:", e3); | |
process.exit(1); | |
} | |
} | |
} | |
})(); | |