#!/usr/bin/env node /** * isocreator binary wrapper * Spawns the appropriate pre-compiled binary for the current platform */ import { spawn } from 'child_process'; import { dirname, join } from 'path'; import { fileURLToPath } from 'url'; import { platform, arch as osArch } from 'os'; import { existsSync } from 'fs'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); // Map Node.js platform names to our binary names const platformMap = { darwin: 'macos', linux: 'linux', win32: 'windows', }; // Map Node.js architecture names const archMap = { x64: 'x64', arm64: 'arm64', }; const detectedPlatform = platformMap[platform()]; const detectedArch = archMap[osArch()]; if (!detectedPlatform || !detectedArch) { console.error(`❌ Unsupported platform: ${platform()}-${osArch()}`); console.error('Supported platforms: linux-x64, linux-arm64, darwin-x64, darwin-arm64, win32-x64'); process.exit(1); } const ext = detectedPlatform === 'windows' ? '.exe' : ''; const binaryName = `isocreator-${detectedPlatform}-${detectedArch}${ext}`; const binaryPath = join(__dirname, '..', 'dist', 'binaries', binaryName); // Check if binary exists if (!existsSync(binaryPath)) { console.error(`❌ Binary not found: ${binaryPath}`); console.error('\nThis might be due to a failed installation.'); console.error('Try reinstalling:'); console.error(' npm install -g @serve.zone/isocreator'); console.error('\nOr use the direct installer:'); console.error(' curl -sSL https://code.foss.global/serve.zone/isocreator/raw/branch/main/install.sh | sudo bash'); process.exit(1); } // Spawn the binary with all arguments const child = spawn(binaryPath, process.argv.slice(2), { stdio: 'inherit', windowsHide: false, }); // Forward signals process.on('SIGINT', () => child.kill('SIGINT')); process.on('SIGTERM', () => child.kill('SIGTERM')); process.on('SIGHUP', () => child.kill('SIGHUP')); // Exit with the same code as the binary child.on('exit', (code, signal) => { if (signal) { process.kill(process.pid, signal); } else { process.exit(code || 0); } }); child.on('error', (err) => { console.error('❌ Failed to start isocreator:', err.message); process.exit(1); });