import { readFileSync } from 'node:fs' export const REQUIRED_SIGNING_ENV = { macos: [ 'APPLE_CERTIFICATE', 'APPLE_CERTIFICATE_PASSWORD', 'APPLE_SIGNING_IDENTITY', 'APPLE_ID', 'APPLE_PASSWORD', 'APPLE_TEAM_ID', ], windows: ['WINDOWS_CERTIFICATE_BASE64', 'WINDOWS_CERTIFICATE_PASSWORD'], } export function missingSigningVariables(platform, env = process.env) { const required = REQUIRED_SIGNING_ENV[platform] if (!required) throw new Error(`Unsupported release platform: ${platform}`) return required.filter(name => !env[name]?.trim()) } export function readPeMachine(path) { const buffer = readFileSync(path) if (buffer.length < 64 || buffer.readUInt16LE(0) !== 0x5a4d) { throw new Error(`${path} is not a PE executable`) } const peOffset = buffer.readUInt32LE(0x3c) if (peOffset + 6 > buffer.length || buffer.toString('ascii', peOffset, peOffset + 4) !== 'PE\0\0') { throw new Error(`${path} has an invalid PE header`) } return buffer.readUInt16LE(peOffset + 4) } export function assertWithinSize(path, maxBytes) { const size = readFileSync(path).byteLength if (size > maxBytes) { throw new Error(`${path} is ${(size / 1024 / 1024).toFixed(1)} MB; limit is ${(maxBytes / 1024 / 1024).toFixed(1)} MB`) } return size }