This repository has been archived by the owner on Jun 14, 2021. It is now read-only.
generated from josephjkahn/quantum_god2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary.js
62 lines (52 loc) · 1.56 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
const { Binary } = require("./binary-install");
const os = require("os");
const { join } = require("path");
const getPlatform = () => {
const type = os.type();
const arch = os.arch();
if (type === "Windows_NT" && arch === "x64") {
return "x86_64-pc-windows-msvc";
}
if (type === "Linux" && arch === "x64") {
return "x86_64-unknown-linux-musl";
}
if (type === "Darwin" && (arch === "x64" || arch == "arm64")) {
// for users of M1 / Apple Silicon devices, use an x86 binary automatically run by Rosetta 2.
return "x86_64-apple-darwin";
}
throw new Error(`Unsupported platform: ${type} ${arch}`);
};
const getBinaryURL = (version, platform) => {
const site =
process.env.WRANGLER_BINARY_HOST ||
process.env.npm_config_wrangler_binary_host ||
"https://workers.cloudflare.com/get-npm-wrangler-binary";
return `${site}/${version}/${platform}`;
};
const getBinary = () => {
const platform = getPlatform();
const version = require("./package.json").version;
const url = getBinaryURL(version, platform);
const customPath =
process.env.WRANGLER_INSTALL_PATH ||
process.env.npm_config_wrangler_install_path;
const installDirectory = join(customPath || os.homedir(), ".wrangler");
return new Binary(url, { name: "wrangler", 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,
};