-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinary.js
102 lines (93 loc) · 1.94 KB
/
binary.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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const Binary = require("./binary-install/binary");
const os = require("os");
const { version } = require("./package.json");
const repository = "https://github.com/covergates/covergates";
/**
* get user's os and architecture
* @return {string} target platform
*/
function getPlatform() {
const type = os.type();
const arch = os.arch();
const supportedPlatforms = [
{
TYPE: "Linux",
ARCH: "x32",
TARGET: "linux-386",
},
{
TYPE: "Linux",
ARCH: "x64",
TARGET: "linux-amd64",
},
{
TYPE: "Linux",
ARCH: "arm",
TARGET: "linux-arm",
},
{
TYPE: "Linux",
ARCH: "arm64",
TARGET: "linux-arm64",
},
{
TYPE: "Windows_NT",
ARCH: "x32",
TARGET: "windows-386",
},
{
TYPE: "Windows_NT",
ARCH: "x64",
TARGET: "windows-amd64",
},
{
TYPE: "Darwin",
ARCH: "x32",
TARGET: "darwin-386",
},
{
TYPE: "Darwin",
ARCH: "x64",
TARGET: "darwin-amd64",
},
];
for (const platform of supportedPlatforms) {
if (type === platform.TYPE && arch === platform.ARCH) {
return platform.TARGET;
}
}
console.error(
`Platform with type ${type} and architecture ${arch}` +
"is not supported by covergates"
);
process.exit(1);
}
/**
* get binary
* @return {Binary}
*/
function getBinary() {
const platform = getPlatform();
const url = `${repository}/releases/download/v${version}`;
const binary = `covergates-v${version}-${platform}.tar.gz`;
const name = "covergates";
const installDirectory = __dirname;
return new Binary(`${url}/${binary}`, { name, installDirectory });
}
const run = () => {
const binary = getBinary();
binary.run();
};
const install = () => {
const binary = getBinary();
binary.install();
};
const uninstall = () => {
const binary = getBinary();
binary.uninstall();
};
module.exports = {
install,
run,
uninstall,
};