Unified · Split
| @@ -32,16 +32,49 @@ const CLI_BIN_PATH = join(CLI_BIN_DIR, process.platform === "win32" ? "executor. · 31 unmodified lines | ||
| 32 | 32 | // CLI install — copy sidecar to ~/.executor/bin and patch shell PATH |
| 33 | 33 | // --------------------------------------------------------------------------- |
| 34 | 34 | |
| 35 | +const getInstalledCliVersion = (): string | null => { | |
| 36 | + if (!existsSync(CLI_BIN_PATH)) return null; | |
| 37 | + try { | |
| 38 | + const { execFileSync } = require("node:child_process") as typeof import("node:child_process"); | |
| 39 | + return execFileSync(CLI_BIN_PATH, ["--version"], { | |
| 40 | + timeout: 5000, | |
| 41 | + encoding: "utf-8", | |
| 42 | + }).trim(); | |
| 43 | + } catch { | |
| 44 | + return null; | |
| 45 | + } | |
| 46 | +}; | |
| 47 | + | |
| 35 | 48 | const installCli = (): void => { |
| 36 | 49 | if (isDev) return; |
| 37 | 50 | |
| 38 | 51 | const sidecar = join(process.resourcesPath, binaryName); |
| 39 | 52 | if (!existsSync(sidecar)) return; |
| 40 | 53 | |
| 54 | + // Check if installed version is already same or newer | |
| 55 | + const appVersion = app.getVersion(); | |
| 56 | + const installedVersion = getInstalledCliVersion(); | |
| 57 | + if (installedVersion) { | |
| 58 | + const parse = (v: string) => v.replace(/^v/, "").split(/[.-]/).map((s) => { | |
| 59 | + const n = parseInt(s, 10); | |
| 60 | + return isNaN(n) ? 0 : n; | |
| 61 | + }); | |
| 62 | + const installed = parse(installedVersion); | |
| 63 | + const bundled = parse(appVersion); | |
| 64 | + const len = Math.max(installed.length, bundled.length); | |
| 65 | + let cmp = 0; | |
| 66 | + for (let i = 0; i < len && cmp === 0; i++) { | |
| 67 | + cmp = (installed[i] ?? 0) - (bundled[i] ?? 0); | |
| 68 | + } | |
| 69 | + if (cmp >= 0) return; // Already up to date or newer | |
| 70 | + } | |
| 71 | + | |
| 41 | 72 | // Copy binary |
| 42 | 73 | mkdirSync(CLI_BIN_DIR, { recursive: true }); |
| 43 | 74 | copyFileSync(sidecar, CLI_BIN_PATH); |
| 44 | 75 | try { chmodSync(CLI_BIN_PATH, 0o755); } catch {} |
| 76 | + console.log(`Installed executor CLI ${appVersion} to ${CLI_BIN_PATH}` + | |
| 77 | + (installedVersion ? ` (was ${installedVersion})` : "")); | |
| 45 | 78 | |
| 46 | 79 | // Copy WASM if present |
| 47 | 80 | const wasm = join(process.resourcesPath, "emscripten-module.wasm"); |