-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostinstall.js
More file actions
70 lines (59 loc) · 2.02 KB
/
postinstall.js
File metadata and controls
70 lines (59 loc) · 2.02 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
68
69
70
#!/usr/bin/env node
const https = require("https");
const fs = require("fs");
const path = require("path");
const { execSync } = require("child_process");
const VERSION = require("./package.json").version;
const REPO = "jottenlips/agave";
function getPlatformBinaryName() {
const platform = process.platform;
const arch = process.arch;
if (platform === "linux" && arch === "x64") return "agave-linux-x64";
if (platform === "darwin" && arch === "arm64") return "agave-darwin-arm64";
console.error(
`Unsupported platform: ${platform}-${arch}. You can build from source with opam + dune.`
);
process.exit(1);
}
function download(url, dest) {
return new Promise((resolve, reject) => {
const request = (url) => {
https
.get(url, (res) => {
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
request(res.headers.location);
return;
}
if (res.statusCode !== 200) {
reject(new Error(`Download failed with status ${res.statusCode}: ${url}`));
return;
}
const file = fs.createWriteStream(dest);
res.pipe(file);
file.on("finish", () => {
file.close();
resolve();
});
})
.on("error", reject);
};
request(url);
});
}
async function main() {
const binaryName = getPlatformBinaryName();
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${binaryName}`;
const dest = path.join(__dirname, "bin", "agave-native");
fs.mkdirSync(path.join(__dirname, "bin"), { recursive: true });
console.log(`Downloading agave binary for ${process.platform}-${process.arch}...`);
try {
await download(url, dest);
fs.chmodSync(dest, 0o755);
console.log("agave binary installed successfully.");
} catch (err) {
console.error(`Failed to download binary: ${err.message}`);
console.error("You can build from source with: opam install . --deps-only && dune build");
process.exit(1);
}
}
main();