import { existsSync, mkdirSync, rmSync, copyFileSync, cpSync, renameSync, writeFileSync } from "node:fs"; import { homedir } from "node:os"; import { basename, join } from "node:path"; import { spawnSync } from "node:child_process"; const root = join(import.meta.dirname, ".."); const electronVersion = "36.9.5"; const cacheRoot = join(homedir(), "Library", "Caches", "electron"); const zipName = `electron-v${electronVersion}-win32-x64.zip`; const appDir = join(root, "dist", "Vynte Connect-win32-x64"); const zipPath = join(root, "dist", "Vynte-Connect-Windows-x64.zip"); function run(command, args, options = {}) { const result = spawnSync(command, args, { stdio: "inherit", ...options }); if (result.status !== 0) { throw new Error(`${command} ${args.join(" ")} failed with exit code ${result.status}`); } } function findElectronZip(dir) { if (!existsSync(dir)) return null; const result = spawnSync("find", [dir, "-name", zipName, "-print", "-quit"], { encoding: "utf8" }); return result.stdout.trim() || null; } function sha256(file) { const result = spawnSync("shasum", ["-a", "256", file], { encoding: "utf8" }); if (result.status !== 0) return "unknown"; return result.stdout.split(/\s+/)[0]; } const electronZip = findElectronZip(cacheRoot); if (!electronZip) { throw new Error(`Missing ${zipName}. Run npm install once so Electron downloads its Windows runtime.`); } mkdirSync(join(root, "dist"), { recursive: true }); rmSync(appDir, { recursive: true, force: true }); rmSync(zipPath, { force: true }); mkdirSync(appDir, { recursive: true }); run("ditto", ["-x", "-k", electronZip, appDir]); renameSync(join(appDir, "electron.exe"), join(appDir, "Vynte Connect.exe")); const packagedAppDir = join(appDir, "resources", "app"); mkdirSync(packagedAppDir, { recursive: true }); copyFileSync(join(root, "package.json"), join(packagedAppDir, "package.json")); cpSync(join(root, "src"), join(packagedAppDir, "src"), { recursive: true }); cpSync(join(root, "resources"), join(packagedAppDir, "resources"), { recursive: true }); writeFileSync( join(appDir, "BUILD-INFO.txt"), [ "Vynte Connect for Windows", `Electron runtime: ${basename(electronZip)}`, `Electron runtime sha256: ${sha256(electronZip)}`, "Gateway: https://vpn.vyntehome.com", "", ].join("\n"), ); run("zip", ["-qry", zipPath, "."], { cwd: appDir }); console.log(`Packaged ${appDir}`); console.log(`Created ${zipPath}`);