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