-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathbinDownload.ts
66 lines (57 loc) · 2.5 KB
/
binDownload.ts
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
import { executeAppBuilder } from "builder-util"
const versionToPromise = new Map<string, Promise<string>>()
export function download(url: string, output: string, checksum?: string | null): Promise<void> {
const args = ["download", "--url", url, "--output", output]
if (checksum != null) {
args.push("--sha512", checksum)
}
return executeAppBuilder(args) as Promise<any>
}
export function getBinFromCustomLoc(name: string, version: string, binariesLocUrl: string, checksum: string): Promise<string> {
const dirName = `${name}-${version}`
return getBin(dirName, binariesLocUrl, checksum)
}
export function getBinFromUrl(name: string, version: string, checksum: string): Promise<string> {
const dirName = `${name}-${version}`
let url: string
if (process.env.ELECTRON_BUILDER_BINARIES_DOWNLOAD_OVERRIDE_URL) {
url = process.env.ELECTRON_BUILDER_BINARIES_DOWNLOAD_OVERRIDE_URL + "/" + dirName + ".7z"
} else {
const baseUrl =
process.env.NPM_CONFIG_ELECTRON_BUILDER_BINARIES_MIRROR ||
process.env.npm_config_electron_builder_binaries_mirror ||
process.env.npm_package_config_electron_builder_binaries_mirror ||
process.env.ELECTRON_BUILDER_BINARIES_MIRROR ||
"https://github.com/electron-userland/electron-builder-binaries/releases/download/"
const middleUrl =
process.env.NPM_CONFIG_ELECTRON_BUILDER_BINARIES_CUSTOM_DIR ||
process.env.npm_config_electron_builder_binaries_custom_dir ||
process.env.npm_package_config_electron_builder_binaries_custom_dir ||
process.env.ELECTRON_BUILDER_BINARIES_CUSTOM_DIR ||
dirName
const urlSuffix = dirName + ".7z"
url = `${baseUrl}${middleUrl}/${urlSuffix}`
}
return getBin(dirName, url, checksum)
}
export function getBin(name: string, url?: string | null, checksum?: string | null): Promise<string> {
// Old cache is ignored if cache environment variable changes
const cacheName = `${process.env.ELECTRON_BUILDER_CACHE}${name}`
let promise = versionToPromise.get(cacheName) // if rejected, we will try to download again
if (promise != null) {
return promise
}
promise = doGetBin(name, url, checksum)
versionToPromise.set(cacheName, promise)
return promise
}
function doGetBin(name: string, url: string | undefined | null, checksum: string | null | undefined): Promise<string> {
const args = ["download-artifact", "--name", name]
if (url != null) {
args.push("--url", url)
}
if (checksum != null) {
args.push("--sha512", checksum)
}
return executeAppBuilder(args)
}