|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const { spawn } = require("child_process"); |
| 4 | +const path = require("path"); |
| 5 | +const fs = require("fs"); |
| 6 | + |
| 7 | +const PLATFORM_MAP = { |
| 8 | + "linux-x64": "lark-daemon-linux-amd64", |
| 9 | + "linux-arm64": "lark-daemon-linux-arm64", |
| 10 | + "darwin-x64": "lark-daemon-darwin-amd64", |
| 11 | + "darwin-arm64": "lark-daemon-darwin-arm64", |
| 12 | + "win32-x64": "lark-daemon-windows-amd64.exe", |
| 13 | +}; |
| 14 | + |
| 15 | +function getBinaryName() { |
| 16 | + const key = `${process.platform}-${process.arch}`; |
| 17 | + const name = PLATFORM_MAP[key]; |
| 18 | + if (!name) { |
| 19 | + console.error(`Unsupported platform: ${key}`); |
| 20 | + console.error(`Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`); |
| 21 | + process.exit(1); |
| 22 | + } |
| 23 | + return name; |
| 24 | +} |
| 25 | + |
| 26 | +function getBinaryPath() { |
| 27 | + const name = getBinaryName(); |
| 28 | + return path.join(__dirname, name); |
| 29 | +} |
| 30 | + |
| 31 | +const binaryPath = getBinaryPath(); |
| 32 | + |
| 33 | +if (!fs.existsSync(binaryPath)) { |
| 34 | + console.error("lark-daemon binary not found."); |
| 35 | + console.error("Run `npm install` in this package directory to download it,"); |
| 36 | + console.error("or download manually from:"); |
| 37 | + console.error(" https://github.com/GrayCodeAI/lark-daemon/releases"); |
| 38 | + process.exit(1); |
| 39 | +} |
| 40 | + |
| 41 | +const args = process.argv.slice(2); |
| 42 | +const child = spawn(binaryPath, args, { stdio: "inherit" }); |
| 43 | + |
| 44 | +child.on("exit", (code) => { |
| 45 | + process.exit(code ?? 0); |
| 46 | +}); |
| 47 | + |
| 48 | +child.on("error", (err) => { |
| 49 | + if (err.code === "EACCES") { |
| 50 | + console.error(`Permission denied: ${binaryPath}`); |
| 51 | + console.error(`Run: chmod +x ${binaryPath}`); |
| 52 | + } else { |
| 53 | + console.error(err); |
| 54 | + } |
| 55 | + process.exit(1); |
| 56 | +}); |
0 commit comments