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