#!/usr/bin/env node /** * Build script for the native host. * Generates the bridge-swarm-host launcher script. */ const fs = require('fs'); const path = require('path'); const { execSync } = require('child_process'); const nativeHostDir = path.join(__dirname, '..', 'native-host'); const launcherPath = path.join(nativeHostDir, 'bridge-swarm-host'); const nodeBin = process.execPath; function isExecutable(p) { try { fs.accessSync(p, fs.constants.X_OK); return true; } catch { return false; } } // Prefer the Bare package installed with native-host (pinned runtime). let bareBin = path.join(nativeHostDir, 'node_modules', 'bare', 'bin', 'bare'); if (!isExecutable(bareBin)) { bareBin = null; try { bareBin = execSync('which bare', { encoding: 'utf8' }).trim(); } catch {} } if (!bareBin) { for (const p of ['/opt/homebrew/bin/bare', '/usr/local/bin/bare']) { if (isExecutable(p)) { bareBin = p; break; } } } if (!bareBin) { bareBin = nodeBin.replace(/node$/, 'bare'); } // bare's npm bin is a Node script that spawns bare-runtime const launcherContent = `#!/usr/bin/env bash DIR="$(cd "$(dirname "$0")" && pwd)" exec "${nodeBin}" "${bareBin}" "$DIR/index.mjs" "$@" `; fs.writeFileSync(launcherPath, launcherContent); fs.chmodSync(launcherPath, '755'); console.log('Native host launcher generated at:', launcherPath); console.log('Using node:', nodeBin); console.log('Using bare:', bareBin);