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 | ELECTRON_CUSTOM_FILENAME="electron.zip"
|
61 | ```
|
62 |
|
63 | You can set ELECTRON_MIRROR in `.npmrc` as well, using the lowercase name:
|
64 |
|
65 | ```plain
|
66 | electron_mirror=https://10.1.2.105/
|
67 | electron_custom_dir="our/internal/filePath"
|
68 | electron_custom_filename="electron.zip"
|
69 | ```
|
70 |
|
71 | You can also set the same variables in your project's package.json:
|
72 |
|
73 | ```json
|
74 | {
|
75 | "name" : "my-electron-project",
|
76 | "config" : {
|
77 | "electron_mirror": "https://10.1.2.105/",
|
78 | "electron_custom_dir": "our/internal/filePath",
|
79 | "electron_custom_filename": "electron.zip"
|
80 | }
|
81 | }
|
82 | ```
|
83 |
|
84 | The order of precedence is:
|
85 |
|
86 | 1. npm config or .npmrc, uppercase (`process.env.NPM_CONFIG_ELECTRON_*`)
|
87 | 1. npm config or .npmrc, lowercase(`process.env.npm_config_electron_*`)
|
88 | 1. package.json (`process.env.npm_package_config_electron_*`)
|
89 | 1. environment variables (`process.env.ELECTRON_*`)
|
90 | 1. the options given to `download`
|
91 | 1. defaults
|
92 |
|
93 | You can also disable checksum validation if you really want to (this is in
|
94 | general a bad idea). Do this by setting `disableChecksumSafetyCheck` to `true`
|
95 | in the options object. Use this only when testing local build of Electron,
|
96 | if you have internal builds of Electron you should generate the SHASUMS file
|
97 | yourself and let `electron-download` still perform its hash validations.
|
98 |
|
99 | ### Cache location
|
100 | The location of the cache depends on the operating system, the defaults are:
|
101 | - Linux: `$XDG_CACHE_HOME` or `~/.cache/electron/`
|
102 | - MacOS: `~/Library/Caches/electron/`
|
103 | - Windows: `$LOCALAPPDATA/electron/Cache` or `~/AppData/Local/electron/Cache/`
|
104 |
|
105 | You can set the `ELECTRON_CACHE` environment variable to set cache location explicitly.
|
106 |
|