UNPKG

2.42 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const utils_1 = require("./utils");
4const BASE_URL = 'https://github.com/electron/electron/releases/download/';
5const NIGHTLY_BASE_URL = 'https://github.com/electron/nightlies/releases/download/';
6function 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}
22exports.getArtifactFileName = getArtifactFileName;
23function mirrorVar(name, options, defaultValue) {
24 // Convert camelCase to camel_case for env var reading
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}
33async 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 // Allow customized download URL resolution.
49 if (opts.resolveAssetURL) {
50 const url = await opts.resolveAssetURL(details);
51 return url;
52 }
53 return `${base}${path}/${file}`;
54}
55exports.getArtifactRemoteURL = getArtifactRemoteURL;
56//# sourceMappingURL=artifact-utils.js.map
\No newline at end of file