mirror of
https://github.com/larksuite/cli.git
synced 2026-07-03 14:02:43 +08:00
feat: add update command with self-update, verification, and rollback (#391)
This commit is contained in:
@@ -9,6 +9,38 @@ const path = require("path");
|
||||
const ext = process.platform === "win32" ? ".exe" : "";
|
||||
const bin = path.join(__dirname, "..", "bin", "lark-cli" + ext);
|
||||
|
||||
// On Windows, a crashed self-update may have left the binary renamed to .old.
|
||||
// Recover it before proceeding so the CLI remains functional.
|
||||
const oldBin = bin + ".old";
|
||||
function restoreOldBinary() {
|
||||
try {
|
||||
if (fs.existsSync(bin)) {
|
||||
fs.rmSync(bin, { force: true });
|
||||
}
|
||||
fs.renameSync(oldBin, bin);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (process.platform === "win32" && fs.existsSync(oldBin)) {
|
||||
if (!fs.existsSync(bin)) {
|
||||
restoreOldBinary();
|
||||
} else {
|
||||
try {
|
||||
execFileSync(bin, ["--version"], { stdio: "ignore", timeout: 10000 });
|
||||
try {
|
||||
fs.rmSync(oldBin, { force: true });
|
||||
} catch (_) {
|
||||
// Best-effort cleanup; keep running the healthy binary.
|
||||
}
|
||||
} catch (_) {
|
||||
restoreOldBinary();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!fs.existsSync(bin)) {
|
||||
console.error(
|
||||
`Error: lark-cli binary not found at ${bin}\n\n` +
|
||||
|
||||
Reference in New Issue
Block a user