1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const utils_1 = require("./utils");
|
4 | const BASE_URL = 'https://github.com/electron/electron/releases/download/';
|
5 | const NIGHTLY_BASE_URL = 'https://github.com/electron/nightlies/releases/download/';
|
6 | function getArtifactFileName(details) {
|
7 | utils_1.ensureIsTruthyString(details, 'artifactName');
|
8 | if (details.isGeneric) {
|
9 | return details.artifactName;
|
10 | }
|
11 | utils_1.ensureIsTruthyString(details, 'arch');
|
12 | utils_1.ensureIsTruthyString(details, 'platform');
|
13 | utils_1.ensureIsTruthyString(details, 'version');
|
14 | return `${[
|
15 | details.artifactName,
|
16 | details.version,
|
17 | details.platform,
|
18 | details.arch,
|
19 | ...(details.artifactSuffix ? [details.artifactSuffix] : []),
|
20 | ].join('-')}.zip`;
|
21 | }
|
22 | exports.getArtifactFileName = getArtifactFileName;
|
23 | function mirrorVar(name, options, defaultValue) {
|
24 |
|
25 | const lowerName = name.replace(/([a-z])([A-Z])/g, (_, a, b) => `${a}_${b}`).toLowerCase();
|
26 | return (process.env[`NPM_CONFIG_ELECTRON_${lowerName.toUpperCase()}`] ||
|
27 | process.env[`npm_config_electron_${lowerName}`] ||
|
28 | process.env[`npm_package_config_electron_${lowerName}`] ||
|
29 | process.env[`ELECTRON_${lowerName.toUpperCase()}`] ||
|
30 | options[name] ||
|
31 | defaultValue);
|
32 | }
|
33 | async function getArtifactRemoteURL(details) {
|
34 | const opts = details.mirrorOptions || {};
|
35 | let base = mirrorVar('mirror', opts, BASE_URL);
|
36 | if (details.version.includes('nightly')) {
|
37 | const nightlyDeprecated = mirrorVar('nightly_mirror', opts, '');
|
38 | if (nightlyDeprecated) {
|
39 | base = nightlyDeprecated;
|
40 | console.warn(`nightly_mirror is deprecated, please use nightlyMirror`);
|
41 | }
|
42 | else {
|
43 | base = mirrorVar('nightlyMirror', opts, NIGHTLY_BASE_URL);
|
44 | }
|
45 | }
|
46 | const path = mirrorVar('customDir', opts, details.version).replace('{{ version }}', details.version.replace(/^v/, ''));
|
47 | const file = mirrorVar('customFilename', opts, getArtifactFileName(details));
|
48 |
|
49 | if (opts.resolveAssetURL) {
|
50 | const url = await opts.resolveAssetURL(details);
|
51 | return url;
|
52 | }
|
53 | return `${base}${path}/${file}`;
|
54 | }
|
55 | exports.getArtifactRemoteURL = getArtifactRemoteURL;
|
56 |
|
\ | No newline at end of file |