-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
67 lines (56 loc) · 1.97 KB
/
Copy pathindex.ts
File metadata and controls
67 lines (56 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
import { spawn } from "child_process";
import * as path from "path";
import * as fs from "fs";
import * as os from "os";
import { fileURLToPath } from "url";
import { createRequire } from "module";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const require = createRequire(import.meta.url);
const PLATFORM = os.platform();
const ARCH = os.arch();
const BINARY_NAME = PLATFORM === "win32" ? "star-run.exe" : "star-run";
const NPM_SCOPE = "@bidyut26";
function getBinaryPath(): string | null {
const platformPkg = `${NPM_SCOPE}/star-run-${PLATFORM}-${ARCH}`;
try {
const pkgPath = require.resolve(`${platformPkg}/package.json`);
const binaryPath = path.join(path.dirname(pkgPath), BINARY_NAME);
if (fs.existsSync(binaryPath)) return binaryPath;
} catch {
}
const candidates = [
path.join(__dirname, "bin", BINARY_NAME),
path.join(__dirname, "..", "bin", BINARY_NAME),
path.join(process.cwd(), "bin", BINARY_NAME),
];
for (const p of candidates) {
if (fs.existsSync(p)) return p;
}
return null;
}
const binaryPath = getBinaryPath();
if (!binaryPath) {
console.error("");
console.error(`❌ star-run: No binary found for ${PLATFORM}-${ARCH}.`);
console.error("");
console.error(` Supported platforms:`);
console.error(` • macOS: darwin-x64, darwin-arm64`);
console.error(` • Linux: linux-x64, linux-arm64`);
console.error(` • Windows: win32-x64`);
console.error("");
console.error(` Install from source:`);
console.error(` git clone https://github.com/bidyut18/star-run.git`);
console.error(` cd star-run && go build -o bin/star-run ./src`);
console.error("");
process.exit(1);
}
const child = spawn(binaryPath, process.argv.slice(2), {
stdio: "inherit",
windowsHide: true,
});
child.on("exit", (code: number | null) => process.exit(code ?? 0));
child.on("error", (err: Error) => {
console.error(`❌ Failed to spawn star-run: ${err.message}`);
process.exit(1);
});