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 snakeName = name.replace(/([a-z])([A-Z])/g, (_, a, b) => `${a}_${b}`).toLowerCase();
|
26 | return (
|
27 |
|
28 | process.env[`npm_config_electron_${name.toLowerCase()}`] ||
|
29 | process.env[`NPM_CONFIG_ELECTRON_${snakeName.toUpperCase()}`] ||
|
30 | process.env[`npm_config_electron_${snakeName}`] ||
|
31 |
|
32 | process.env[`npm_package_config_electron_${name}`] ||
|
33 | process.env[`npm_package_config_electron_${snakeName.toLowerCase()}`] ||
|
34 |
|
35 | process.env[`ELECTRON_${snakeName.toUpperCase()}`] ||
|
36 | options[name] ||
|
37 | defaultValue);
|
38 | }
|
39 | async function getArtifactRemoteURL(details) {
|
40 | const opts = details.mirrorOptions || {};
|
41 | let base = mirrorVar('mirror', opts, BASE_URL);
|
42 | if (details.version.includes('nightly')) {
|
43 | const nightlyDeprecated = mirrorVar('nightly_mirror', opts, '');
|
44 | if (nightlyDeprecated) {
|
45 | base = nightlyDeprecated;
|
46 | console.warn(`nightly_mirror is deprecated, please use nightlyMirror`);
|
47 | }
|
48 | else {
|
49 | base = mirrorVar('nightlyMirror', opts, NIGHTLY_BASE_URL);
|
50 | }
|
51 | }
|
52 | const path = mirrorVar('customDir', opts, details.version).replace('{{ version }}', details.version.replace(/^v/, ''));
|
53 | const file = mirrorVar('customFilename', opts, getArtifactFileName(details));
|
54 |
|
55 | if (opts.resolveAssetURL) {
|
56 | const url = await opts.resolveAssetURL(details);
|
57 | return url;
|
58 | }
|
59 | return `${base}${path}/${file}`;
|
60 | }
|
61 | exports.getArtifactRemoteURL = getArtifactRemoteURL;
|
62 | function getArtifactVersion(details) {
|
63 | return utils_1.normalizeVersion(mirrorVar('customVersion', details.mirrorOptions || {}, details.version));
|
64 | }
|
65 | exports.getArtifactVersion = getArtifactVersion;
|
66 |
|
\ | No newline at end of file |