import { existsSync, mkdirSync } from 'node:fs' import path from 'node:path' import { spawnSync } from 'node:child_process' import { fileURLToPath } from 'node:url' const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..') const entrypoint = path.join(rootDir, 'src/bun/deeplink.js') export function buildWindowsDeeplinkExe(outputPath) { if (!existsSync(entrypoint)) { throw new Error(`build-windows-deeplink: entrypoint not found: ${entrypoint}`) } mkdirSync(path.dirname(outputPath), { recursive: true }) const target = process.env.ELECTROBUN_ARCH === 'arm64' ? 'bun-windows-x64' : 'bun-windows-x64' const result = spawnSync( 'bun', [ 'build', '--compile', '--minify', `--target=${target}`, entrypoint, '--outfile', outputPath ], { cwd: rootDir, stdio: 'inherit', env: process.env } ) if (result.status !== 0) { throw new Error( `build-windows-deeplink: bun build failed with exit code ${result.status ?? 1}` ) } if (!existsSync(outputPath)) { throw new Error(`build-windows-deeplink: output not created: ${outputPath}`) } console.log(`build-windows-deeplink: created ${outputPath}`) return outputPath } if (process.argv[1] === fileURLToPath(import.meta.url)) { const outputArg = process.argv[2] if (!outputArg) { console.error('Usage: bun scripts/build-windows-deeplink.mjs ') process.exit(1) } buildWindowsDeeplinkExe(path.resolve(outputArg)) }