1 | # electron-download
|
2 |
|
3 | [![Travis Build Status](https://travis-ci.org/electron-userland/electron-download.svg?branch=master)](https://travis-ci.org/electron-userland/electron-download)
|
4 | [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/fmfbjmrs42d7bctn/branch/master?svg=true)](https://ci.appveyor.com/project/electron-bot/electron-download/branch/master)
|
5 |
|
6 | [![NPM](https://nodei.co/npm/electron-download.png?downloads=true)](https://www.npmjs.com/package/electron-download)
|
7 |
|
8 | Downloads an Electron release zip from GitHub.
|
9 |
|
10 | Used by [electron-prebuilt](https://npmjs.org/electron-prebuilt) and [electron-packager](https://npmjs.org/electron-packager)
|
11 |
|
12 | ### Usage
|
13 |
|
14 | **Note: Requires Node >= 4.0 to run.**
|
15 |
|
16 | ```shell
|
17 | $ npm install --global electron-download
|
18 | $ electron-download --version=0.31.1
|
19 | ```
|
20 |
|
21 | ```javascript
|
22 | const download = require('electron-download')
|
23 |
|
24 | download({
|
25 | version: '0.25.1',
|
26 | arch: 'ia32',
|
27 | platform: 'win32',
|
28 | cache: './zips'
|
29 | }, function (err, zipPath) {
|
30 | // zipPath will be the path of the zip that it downloaded.
|
31 | // If the zip was already cached it will skip
|
32 | // downloading and call the cb with the cached zip path.
|
33 | // If it wasn't cached it will download the zip and save
|
34 | // it in the cache path.
|
35 | })
|
36 | ```
|
37 |
|
38 | If you don't specify `arch` or `platform` args it will use the built-in `os` module to get the values from the current OS. Specifying `version` is mandatory. If there is a `SHASUMS256.txt` file available for the `version`, the file downloaded will be validated against its checksum to ensure that it was downloaded without errors.
|
39 |
|
40 | You can also use `electron-download` to download the `chromedriver`, `ffmpeg`,
|
41 | `mksnapshot`, and symbols assets for a specific Electron release. This can be
|
42 | configured by setting the `chromedriver`, `ffmpeg`, `mksnapshot`, or
|
43 | `symbols` property to `true` in the specified options object. Only one of
|
44 | these options may be specified per download call.
|
45 |
|
46 | You can force a re-download of the asset and the `SHASUM` file by setting the
|
47 | `force` option to `true`.
|
48 |
|
49 | If you would like to override the mirror location, three options are available. The mirror URL is composed as `url = ELECTRON_MIRROR + ELECTRON_CUSTOM_DIR + '/' + ELECTRON_CUSTOM_FILENAME`.
|
50 |
|
51 | You can set the `ELECTRON_MIRROR` or [`NPM_CONFIG_ELECTRON_MIRROR`](https://docs.npmjs.com/misc/config#environment-variables) environment variable or `mirror` opt variable to use a custom base URL for grabbing Electron zips. The same pattern applies to `ELECTRON_CUSTOM_DIR` and `ELECTRON_CUSTOM_FILENAME`:
|
52 |
|
53 | ```plain
|
54 | ## Electron Mirror of China
|
55 | ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/"
|
56 |
|
57 | ## or for a local mirror
|
58 | ELECTRON_MIRROR="https://10.1.2.105/"
|
59 | ELECTRON_CUSTOM_DIR="our/internal/filePath"
|
60 | ```
|
61 |
|
62 | You can set ELECTRON_MIRROR in `.npmrc` as well, using the lowercase name:
|
63 |
|
64 | ```plain
|
65 | electron_mirror=https://10.1.2.105/
|
66 | ```
|
67 |
|
68 | ### Cache location
|
69 | The location of the cache depends on the operating system, the defaults are:
|
70 | - Linux: `$XDG_CACHE_HOME` or `~/.cache/electron/`
|
71 | - MacOS: `~/Library/Caches/electron/`
|
72 | - Windows: `$LOCALAPPDATA/electron/Cache` or `~/AppData/Local/electron/Cache/`
|
73 |
|