UNPKG

2.83 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 snakeName = name.replace(/([a-z])([A-Z])/g, (_, a, b) => `${a}_${b}`).toLowerCase();
26 return (
27 // .npmrc
28 process.env[`npm_config_electron_${name.toLowerCase()}`] ||
29 process.env[`NPM_CONFIG_ELECTRON_${snakeName.toUpperCase()}`] ||
30 process.env[`npm_config_electron_${snakeName}`] ||
31 // package.json
32 process.env[`npm_package_config_electron_${name}`] ||
33 process.env[`npm_package_config_electron_${snakeName.toLowerCase()}`] ||
34 // env
35 process.env[`ELECTRON_${snakeName.toUpperCase()}`] ||
36 options[name] ||
37 defaultValue);
38}
39async 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 // Allow customized download URL resolution.
55 if (opts.resolveAssetURL) {
56 const url = await opts.resolveAssetURL(details);
57 return url;
58 }
59 return `${base}${path}/${file}`;
60}
61exports.getArtifactRemoteURL = getArtifactRemoteURL;
62function getArtifactVersion(details) {
63 return utils_1.normalizeVersion(mirrorVar('customVersion', details.mirrorOptions || {}, details.version));
64}
65exports.getArtifactVersion = getArtifactVersion;
66//# sourceMappingURL=artifact-utils.js.map
\No newline at end of file