UNPKG

6.18 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _bluebirdLst;
8
9function _load_bluebirdLst() {
10 return _bluebirdLst = require("bluebird-lst");
11}
12
13var _bluebirdLst2;
14
15function _load_bluebirdLst2() {
16 return _bluebirdLst2 = _interopRequireDefault(require("bluebird-lst"));
17}
18
19// we cache in the global location - in the home dir, not in the node_modules/.cache (https://www.npmjs.com/package/find-cache-dir) because
20// * don't need to find node_modules
21// * don't pollute user project dir (important in case of 1-package.json project structure)
22// * simplify/speed-up tests (don't download fpm for each test project)
23let doGetBin = (() => {
24 var _ref = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (name, dirName, url, checksum) {
25 const cachePath = _path.join((0, (_util || _load_util()).getCacheDirectory)(), name);
26 const dirPath = _path.join(cachePath, dirName);
27 const dirStat = yield (0, (_fs || _load_fs()).statOrNull)(dirPath);
28 //noinspection ES6MissingAwait
29 if (dirStat != null && dirStat.isDirectory()) {
30 debug(`Found existing ${name} ${dirPath}`);
31 return dirPath;
32 }
33 (0, (_log || _load_log()).log)(`Downloading ${dirName}, please wait`);
34 // 7z cannot be extracted from the input stream, temp file is required
35 const tempUnpackDir = _path.join(cachePath, (0, (_tempFile || _load_tempFile()).getTempName)());
36 const archiveName = `${tempUnpackDir}.7z`;
37 debug(`Download ${name} from ${url} to ${archiveName}`);
38 // 7z doesn't create out dir, so, we don't create dir in parallel to download - dir creation will create parent dirs for archive file also
39 yield (0, (_fsExtraP || _load_fsExtraP()).emptyDir)(tempUnpackDir);
40 const options = {
41 skipDirCreation: true,
42 cancellationToken: new (_electronBuilderHttp || _load_electronBuilderHttp()).CancellationToken()
43 };
44 if (checksum.length === 64 && !(checksum.indexOf("+") !== -1) && !(checksum.indexOf("Z") !== -1) && !(checksum.indexOf("=") !== -1)) {
45 options.sha2 = checksum;
46 } else {
47 options.sha512 = checksum;
48 }
49 for (let attemptNumber = 1; attemptNumber < 4; attemptNumber++) {
50 try {
51 yield (_nodeHttpExecutor || _load_nodeHttpExecutor()).httpExecutor.download(url, archiveName, options);
52 } catch (e) {
53 if (attemptNumber >= 3) {
54 throw e;
55 }
56 (0, (_log || _load_log()).warn)(`Cannot download ${name}, attempt #${attemptNumber}: ${e}`);
57 yield new (_bluebirdLst2 || _load_bluebirdLst2()).default(function (resolve, reject) {
58 setTimeout(function () {
59 return (_nodeHttpExecutor || _load_nodeHttpExecutor()).httpExecutor.download(url, archiveName, options).then(resolve).catch(reject);
60 }, 1000 * attemptNumber);
61 });
62 }
63 }
64 yield (0, (_util || _load_util()).spawn)((_zipBin || _load_zipBin()).path7za, (0, (_util || _load_util()).debug7zArgs)("x").concat(archiveName, `-o${tempUnpackDir}`), {
65 cwd: cachePath
66 });
67 yield (_bluebirdLst2 || _load_bluebirdLst2()).default.all([(0, (_fsExtraP || _load_fsExtraP()).rename)(tempUnpackDir, dirPath).catch(function (e) {
68 console.warn(`Cannot move downloaded ${name} into final location (another process downloaded faster?): ${e}`);
69 }), (0, (_fsExtraP || _load_fsExtraP()).unlink)(archiveName)]);
70 debug(`${name}} downloaded to ${dirPath}`);
71 return dirPath;
72 });
73
74 return function doGetBin(_x, _x2, _x3, _x4) {
75 return _ref.apply(this, arguments);
76 };
77})();
78//# sourceMappingURL=binDownload.js.map
79
80
81exports.getBinFromBintray = getBinFromBintray;
82exports.getBinFromGithub = getBinFromGithub;
83exports.getBin = getBin;
84
85var _zipBin;
86
87function _load_zipBin() {
88 return _zipBin = require("7zip-bin");
89}
90
91var _debug2;
92
93function _load_debug() {
94 return _debug2 = _interopRequireDefault(require("debug"));
95}
96
97var _electronBuilderHttp;
98
99function _load_electronBuilderHttp() {
100 return _electronBuilderHttp = require("electron-builder-http");
101}
102
103var _fsExtraP;
104
105function _load_fsExtraP() {
106 return _fsExtraP = require("fs-extra-p");
107}
108
109var _path = _interopRequireWildcard(require("path"));
110
111var _tempFile;
112
113function _load_tempFile() {
114 return _tempFile = require("temp-file");
115}
116
117var _fs;
118
119function _load_fs() {
120 return _fs = require("./fs");
121}
122
123var _log;
124
125function _load_log() {
126 return _log = require("./log");
127}
128
129var _nodeHttpExecutor;
130
131function _load_nodeHttpExecutor() {
132 return _nodeHttpExecutor = require("./nodeHttpExecutor");
133}
134
135var _util;
136
137function _load_util() {
138 return _util = require("./util");
139}
140
141function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
142
143function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
144
145const debug = (0, (_debug2 || _load_debug()).default)("electron-builder:binDownload");
146const versionToPromise = new Map();
147function getBinFromBintray(name, version, sha2) {
148 const dirName = `${name}-${version}`;
149 return getBin(name, dirName, `https://dl.bintray.com/electron-userland/bin/${dirName}.7z`, sha2);
150}
151function getBinFromGithub(name, version, checksum) {
152 const dirName = `${name}-${version}`;
153 return getBin(name, dirName, `https://github.com/electron-userland/electron-builder-binaries/releases/download/${dirName}/${dirName}.7z`, checksum);
154}
155function getBin(name, dirName, url, checksum) {
156 let promise = versionToPromise.get(dirName);
157 // if rejected, we will try to download again
158 if (promise != null && !promise.isRejected()) {
159 return promise;
160 }
161 promise = doGetBin(name, dirName, url, checksum);
162 versionToPromise.set(dirName, promise);
163 return promise;
164}
\No newline at end of file