|
| 1 | +#!/usr/bin/env node |
| 2 | +/** |
| 3 | + * Windows portable packaging script that suppresses winCodeSign extraction errors. |
| 4 | + * This mirrors package-windows.mjs but produces a portable .exe. |
| 5 | + */ |
| 6 | + |
| 7 | +import { spawn } from "child_process" |
| 8 | +import { fileURLToPath } from "url" |
| 9 | +import { dirname, join } from "path" |
| 10 | +import { existsSync } from "fs" |
| 11 | + |
| 12 | +const __filename = fileURLToPath(import.meta.url) |
| 13 | +const __dirname = dirname(__filename) |
| 14 | +const projectRoot = join(__dirname, "..") |
| 15 | + |
| 16 | +// Set environment variables to prevent code signing attempts |
| 17 | +const env = { |
| 18 | + ...process.env, |
| 19 | + CSC_IDENTITY_AUTO_SELECT: "false", |
| 20 | + WIN_CSC_LINK: "", |
| 21 | + WIN_CSC_KEY_PASSWORD: "", |
| 22 | +} |
| 23 | + |
| 24 | +// Track if we detect file lock errors |
| 25 | +let hasFileLockError = false |
| 26 | + |
| 27 | +// Filter out winCodeSign/darwin symlink errors from output |
| 28 | +const filterOutput = (data) => { |
| 29 | + const lines = data.toString().split("\n") |
| 30 | + const filtered = lines.filter((line) => { |
| 31 | + const lower = line.toLowerCase() |
| 32 | + |
| 33 | + // Detect file lock/overwrite errors in stdout too |
| 34 | + if ( |
| 35 | + lower.includes("ebusy") || |
| 36 | + lower.includes("eacces") || |
| 37 | + lower.includes("eperm") || |
| 38 | + lower.includes("file is in use") || |
| 39 | + lower.includes("cannot overwrite") || |
| 40 | + lower.includes("access is denied") || |
| 41 | + lower.includes("the process cannot access the file") || |
| 42 | + lower.includes("being used by another process") || |
| 43 | + lower.includes("file is locked") || |
| 44 | + lower.includes("cannot delete") || |
| 45 | + lower.includes("sharing violation") |
| 46 | + ) { |
| 47 | + hasFileLockError = true |
| 48 | + } |
| 49 | + |
| 50 | + return ( |
| 51 | + !lower.includes("wincodesign") && |
| 52 | + !lower.includes("darwin") && |
| 53 | + !lower.includes("symbolic link") && |
| 54 | + !lower.includes("libcrypto.dylib") && |
| 55 | + !lower.includes("libssl.dylib") && |
| 56 | + !lower.includes("cannot create symbolic link") |
| 57 | + ) |
| 58 | + }) |
| 59 | + if (filtered.length > 0) { |
| 60 | + process.stdout.write(filtered.join("\n")) |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +const electronBuilder = spawn("npx", ["electron-builder", "--win", "portable"], { |
| 65 | + cwd: projectRoot, |
| 66 | + shell: true, |
| 67 | + env, |
| 68 | +}) |
| 69 | + |
| 70 | +// Filter stdout |
| 71 | +electronBuilder.stdout?.on("data", filterOutput) |
| 72 | + |
| 73 | +// Filter stderr but keep important errors |
| 74 | +electronBuilder.stderr?.on("data", (data) => { |
| 75 | + const text = data.toString() |
| 76 | + const lower = text.toLowerCase() |
| 77 | + |
| 78 | + // Detect file lock/overwrite errors in stderr too |
| 79 | + if ( |
| 80 | + lower.includes("ebusy") || |
| 81 | + lower.includes("eacces") || |
| 82 | + lower.includes("eperm") || |
| 83 | + lower.includes("file is in use") || |
| 84 | + lower.includes("cannot overwrite") || |
| 85 | + lower.includes("access is denied") || |
| 86 | + lower.includes("the process cannot access the file") || |
| 87 | + lower.includes("being used by another process") || |
| 88 | + lower.includes("file is locked") || |
| 89 | + lower.includes("cannot delete") || |
| 90 | + lower.includes("sharing violation") |
| 91 | + ) { |
| 92 | + hasFileLockError = true |
| 93 | + } |
| 94 | + |
| 95 | + // Only show errors that aren't related to winCodeSign/darwin |
| 96 | + if ( |
| 97 | + !lower.includes("wincodesign") && |
| 98 | + !lower.includes("darwin") && |
| 99 | + !lower.includes("symbolic link") && |
| 100 | + !lower.includes("libcrypto.dylib") && |
| 101 | + !lower.includes("libssl.dylib") |
| 102 | + ) { |
| 103 | + process.stderr.write(data) |
| 104 | + } |
| 105 | +}) |
| 106 | + |
| 107 | +electronBuilder.on("error", (error) => { |
| 108 | + console.error("Failed to start electron-builder:", error) |
| 109 | + process.exit(1) |
| 110 | +}) |
| 111 | + |
| 112 | +electronBuilder.on("close", (code) => { |
| 113 | + const releaseDir = join(projectRoot, "release") |
| 114 | + const exeCandidates = [ |
| 115 | + join(releaseDir, "1Code.exe"), |
| 116 | + ] |
| 117 | + const exePath = exeCandidates.find((p) => existsSync(p)) |
| 118 | + |
| 119 | + if (hasFileLockError) { |
| 120 | + console.log("\n❌ Build failed: Cannot overwrite files (app may be running)") |
| 121 | + console.log(" Please close 1Code.exe and try again") |
| 122 | + process.exit(1) |
| 123 | + } else if (exePath) { |
| 124 | + console.log("\n✅ Build completed successfully!") |
| 125 | + console.log(` Executable: ${exePath}`) |
| 126 | + process.exit(0) |
| 127 | + } else if (code === 0) { |
| 128 | + console.log("\n⚠️ Build completed but executable not found in release/") |
| 129 | + process.exit(1) |
| 130 | + } else { |
| 131 | + process.exit(code || 1) |
| 132 | + } |
| 133 | +}) |
0 commit comments