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