1 | # @electron/get
|
2 |
|
3 | > Download Electron release artifacts
|
4 |
|
5 | [![CircleCI](https://circleci.com/gh/electron/get.svg?style=shield)](https://circleci.com/gh/electron/get)
|
6 | [![NPM package](https://img.shields.io/npm/v/@electron/get)](https://npm.im/@electron/get)
|
7 |
|
8 | ## Usage
|
9 |
|
10 | ### Simple: Downloading an Electron Binary ZIP
|
11 |
|
12 | ```typescript
|
13 | import { download } from '@electron/get';
|
14 |
|
15 | // NB: Use this syntax within an async function, Node does not have support for
|
16 | // top-level await as of Node 12.
|
17 | const zipFilePath = await download('4.0.4');
|
18 | ```
|
19 |
|
20 | ### Advanced: Downloading a macOS Electron Symbol File
|
21 |
|
22 |
|
23 | ```typescript
|
24 | import { downloadArtifact } from '@electron/get';
|
25 |
|
26 | // NB: Use this syntax within an async function, Node does not have support for
|
27 | // top-level await as of Node 12.
|
28 | const zipFilePath = await downloadArtifact({
|
29 | version: '4.0.4',
|
30 | platform: 'darwin',
|
31 | artifactName: 'electron',
|
32 | artifactSuffix: 'symbols',
|
33 | arch: 'x64',
|
34 | });
|
35 | ```
|
36 |
|
37 | ### Specifying a mirror
|
38 |
|
39 | To specify another location to download Electron assets from, the following options are
|
40 | available:
|
41 |
|
42 | * `mirrorOptions` Object
|
43 | * `mirror` String (optional) - The base URL of the mirror to download from.
|
44 | * `nightlyMirror` String (optional) - The Electron nightly-specific mirror URL.
|
45 | * `customDir` String (optional) - The name of the directory to download from, often scoped by version number.
|
46 | * `customFilename` String (optional) - The name of the asset to download.
|
47 | * `resolveAssetURL` Function (optional) - A function allowing customization of the url used to download the asset.
|
48 |
|
49 | Anatomy of a download URL, in terms of `mirrorOptions`:
|
50 |
|
51 | ```
|
52 | https://github.com/electron/electron/releases/download/v4.0.4/electron-v4.0.4-linux-x64.zip
|
53 | | | | |
|
54 | ------------------------------------------------------- -----------------------------
|
55 | | |
|
56 | mirror / nightlyMirror | | customFilename
|
57 | ------
|
58 | ||
|
59 | customDir
|
60 | ```
|
61 |
|
62 | Example:
|
63 |
|
64 | ```typescript
|
65 | import { download } from '@electron/get';
|
66 |
|
67 | const zipFilePath = await download('4.0.4', {
|
68 | mirrorOptions: {
|
69 | mirror: 'https://mirror.example.com/electron/',
|
70 | customDir: 'custom',
|
71 | customFilename: 'unofficial-electron-linux.zip'
|
72 | }
|
73 | });
|
74 | // Will download from https://mirror.example.com/electron/custom/unofficial-electron-linux.zip
|
75 |
|
76 | const nightlyZipFilePath = await download('8.0.0-nightly.20190901', {
|
77 | mirrorOptions: {
|
78 | nightlyMirror: 'https://nightly.example.com/',
|
79 | customDir: 'nightlies',
|
80 | customFilename: 'nightly-linux.zip'
|
81 | }
|
82 | });
|
83 | // Will download from https://nightly.example.com/nightlies/nightly-linux.zip
|
84 | ```
|
85 |
|
86 | `customDir` can have the placeholder `{{ version }}`, which will be replaced by the version
|
87 | specified (without the leading `v`). For example:
|
88 |
|
89 | ```javascript
|
90 | const zipFilePath = await download('4.0.4', {
|
91 | mirrorOptions: {
|
92 | mirror: 'https://mirror.example.com/electron/',
|
93 | customDir: 'version-{{ version }}',
|
94 | platform: 'linux',
|
95 | arch: 'x64'
|
96 | }
|
97 | });
|
98 | // Will download from https://mirror.example.com/electron/version-4.0.4/electron-v4.0.4-linux-x64.zip
|
99 | ```
|
100 |
|
101 | #### Using environment variables for mirror options
|
102 | Mirror options can also be specified via the following environment variables:
|
103 | * `ELECTRON_CUSTOM_DIR` - Specifies the custom directory to download from.
|
104 | * `ELECTRON_CUSTOM_FILENAME` - Specifies the custom file name to download.
|
105 | * `ELECTRON_MIRROR` - Specifies the URL of the server to download from if the version is not a nightly version.
|
106 | * `ELECTRON_NIGHTLY_MIRROR` - Specifies the URL of the server to download from if the version is a nightly version.
|
107 |
|
108 | ### Overriding the version downloaded
|
109 |
|
110 | The version downloaded can be overriden by setting the `ELECTRON_CUSTOM_VERSION` environment variable.
|
111 | Setting this environment variable will override the version passed in to `download` or `downloadArtifact`.
|
112 |
|
113 | ## How It Works
|
114 |
|
115 | This module downloads Electron to a known place on your system and caches it
|
116 | so that future requests for that asset can be returned instantly. The cache
|
117 | locations are:
|
118 |
|
119 | * Linux: `$XDG_CACHE_HOME` or `~/.cache/electron/`
|
120 | * MacOS: `~/Library/Caches/electron/`
|
121 | * Windows: `%LOCALAPPDATA%/electron/Cache` or `~/AppData/Local/electron/Cache/`
|
122 |
|
123 | By default, the module uses [`got`](https://github.com/sindresorhus/got) as the
|
124 | downloader. As a result, you can use the same [options](https://github.com/sindresorhus/got#options)
|
125 | via `downloadOptions`.
|
126 |
|
127 | ### Progress Bar
|
128 |
|
129 | By default, a progress bar is shown when downloading an artifact for more than 30 seconds. To
|
130 | disable, set the `ELECTRON_GET_NO_PROGRESS` environment variable to any non-empty value, or set
|
131 | `quiet` to `true` in `downloadOptions`. If you need to monitor progress yourself via the API, set
|
132 | `getProgressCallback` in `downloadOptions`, which has the same function signature as `got`'s
|
133 | [`downloadProgress` event callback](https://github.com/sindresorhus/got#ondownloadprogress-progress).
|
134 |
|
135 | ### Proxies
|
136 |
|
137 | Downstream packages should utilize the `initializeProxy` function to add HTTP(S) proxy support. If
|
138 | the environment variable `ELECTRON_GET_USE_PROXY` is set, it is called automatically.
|