-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.js
More file actions
57 lines (44 loc) · 1.38 KB
/
install.js
File metadata and controls
57 lines (44 loc) · 1.38 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
#!/usr/bin/env node
// Postinstall script: copies the correct platform binary to bin/ames-unifi-mcp
const fs = require("fs");
const path = require("path");
const os = require("os");
const BINARY_NAME = "ames-unifi-mcp";
const PLATFORM_MAP = {
"darwin-arm64": `${BINARY_NAME}-darwin-arm64`,
"darwin-x64": `${BINARY_NAME}-darwin-amd64`,
"linux-arm64": `${BINARY_NAME}-linux-arm64`,
"linux-x64": `${BINARY_NAME}-linux-amd64`,
};
function install() {
const platform = os.platform();
const arch = os.arch();
const key = `${platform}-${arch}`;
const binaryFile = PLATFORM_MAP[key];
if (!binaryFile) {
console.error(
`Unsupported platform: ${platform}-${arch}. ` +
`Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`
);
process.exit(1);
}
const distDir = path.join(__dirname, "dist");
const binDir = path.join(__dirname, "bin");
const src = path.join(distDir, binaryFile);
const dest = path.join(binDir, BINARY_NAME);
if (!fs.existsSync(src)) {
console.error(`Binary not found: ${src}`);
console.error("Try rebuilding: make build-all");
process.exit(1);
}
// Ensure bin/ exists
if (!fs.existsSync(binDir)) {
fs.mkdirSync(binDir, { recursive: true });
}
// Copy binary
fs.copyFileSync(src, dest);
// Make executable
fs.chmodSync(dest, 0o755);
console.log(`Installed ${BINARY_NAME} for ${platform}/${arch}`);
}
install();