-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
35 lines (31 loc) · 999 Bytes
/
index.js
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
const os = require('os');
const getBinaryName = () => {
const platform = os.platform();
const binaries = {
"linux": "index-linux.node",
"darwin": {
x64: "index-macos-x64.node",
arm64: "index-macos-arm64.node"
},
"win32": "index-win.node"
};
const binaryName = binaries[platform];
if (binaryName && typeof binaryName === 'string') {
return `./build/${binaryName}`
} else if (binaryName && typeof binaryName === 'object') {
const arch = process.arch;
const binaryNameArch = binaryName[arch];
if (binaryNameArch) {
return `./build/${binaryNameArch}`
} else {
console.error(`Unsupported architecture: ${arch}`);
process.exit(1);
}
} else {
console.error(`Unsupported platform: ${platform}`);
process.exit(1);
}
}
const binary = getBinaryName();
const nativeAddon = require(binary);
module.exports = nativeAddon;