-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbinary.js
More file actions
55 lines (43 loc) · 1.18 KB
/
binary.js
File metadata and controls
55 lines (43 loc) · 1.18 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
const path = require('path');
const os = require('os');
const fs = require('fs');
function getPlatform() {
const platform = os.platform();
const arch = os.arch();
if (platform === 'win32') {
return arch === 'x64' ? 'windows-amd64' : null;
}
if (platform === 'darwin') {
if (arch === 'arm64') return 'darwin-arm64';
if (arch === 'x64') return 'darwin-amd64';
return null;
}
if (platform === 'linux') {
return arch === 'x64' ? 'linux-amd64' : null;
}
return null;
}
function getBinaryName() {
const platform = os.platform();
return platform === 'win32' ? 'opencore.exe' : 'opencore';
}
function getBinaryPath() {
const platform = getPlatform();
if (!platform) {
throw new Error(`Unsupported platform: ${os.platform()} ${os.arch()}`);
}
const binaryName = getBinaryName();
const binaryPath = path.join(__dirname, 'bin', binaryName);
if (!fs.existsSync(binaryPath)) {
throw new Error(
`Binary not found at ${binaryPath}. ` +
`This might be an installation issue. Please try reinstalling @open-core/cli.`
);
}
return binaryPath;
}
module.exports = {
getPlatform,
getBinaryName,
getBinaryPath
};