1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _bluebirdLst;
|
8 |
|
9 | function _load_bluebirdLst() {
|
10 | return _bluebirdLst = require("bluebird-lst");
|
11 | }
|
12 |
|
13 | var _bluebirdLst2;
|
14 |
|
15 | function _load_bluebirdLst2() {
|
16 | return _bluebirdLst2 = _interopRequireDefault(require("bluebird-lst"));
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | let 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 |
|
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 |
|
35 | const tempUnpackDir = _path.join(cachePath, (0, (_util || _load_util()).getTempName)());
|
36 | const archiveName = `${tempUnpackDir}.7z`;
|
37 | debug(`Download ${name} from ${url} to ${archiveName}`);
|
38 |
|
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 |
|
79 |
|
80 |
|
81 | exports.getBinFromBintray = getBinFromBintray;
|
82 | exports.getBinFromGithub = getBinFromGithub;
|
83 | exports.getBin = getBin;
|
84 |
|
85 | var _zipBin;
|
86 |
|
87 | function _load_zipBin() {
|
88 | return _zipBin = require("7zip-bin");
|
89 | }
|
90 |
|
91 | var _debug2;
|
92 |
|
93 | function _load_debug() {
|
94 | return _debug2 = _interopRequireDefault(require("debug"));
|
95 | }
|
96 |
|
97 | var _electronBuilderHttp;
|
98 |
|
99 | function _load_electronBuilderHttp() {
|
100 | return _electronBuilderHttp = require("electron-builder-http");
|
101 | }
|
102 |
|
103 | var _fsExtraP;
|
104 |
|
105 | function _load_fsExtraP() {
|
106 | return _fsExtraP = require("fs-extra-p");
|
107 | }
|
108 |
|
109 | var _path = _interopRequireWildcard(require("path"));
|
110 |
|
111 | var _fs;
|
112 |
|
113 | function _load_fs() {
|
114 | return _fs = require("./fs");
|
115 | }
|
116 |
|
117 | var _log;
|
118 |
|
119 | function _load_log() {
|
120 | return _log = require("./log");
|
121 | }
|
122 |
|
123 | var _nodeHttpExecutor;
|
124 |
|
125 | function _load_nodeHttpExecutor() {
|
126 | return _nodeHttpExecutor = require("./nodeHttpExecutor");
|
127 | }
|
128 |
|
129 | var _util;
|
130 |
|
131 | function _load_util() {
|
132 | return _util = require("./util");
|
133 | }
|
134 |
|
135 | function _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; } }
|
136 |
|
137 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
138 |
|
139 | const debug = (0, (_debug2 || _load_debug()).default)("electron-builder:binDownload");
|
140 | const versionToPromise = new Map();
|
141 | function getBinFromBintray(name, version, sha2) {
|
142 | const dirName = `${name}-${version}`;
|
143 | return getBin(name, dirName, `https://dl.bintray.com/electron-userland/bin/${dirName}.7z`, sha2);
|
144 | }
|
145 | function getBinFromGithub(name, version, checksum) {
|
146 | const dirName = `${name}-${version}`;
|
147 | return getBin(name, dirName, `https://github.com/electron-userland/electron-builder-binaries/releases/download/${dirName}/${dirName}.7z`, checksum);
|
148 | }
|
149 | function getBin(name, dirName, url, checksum) {
|
150 | let promise = versionToPromise.get(dirName);
|
151 |
|
152 | if (promise != null && !promise.isRejected()) {
|
153 | return promise;
|
154 | }
|
155 | promise = doGetBin(name, dirName, url, checksum);
|
156 | versionToPromise.set(dirName, promise);
|
157 | return promise;
|
158 | } |
\ | No newline at end of file |