UNPKG

2.95 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getArtifactVersion = exports.getArtifactRemoteURL = exports.getArtifactFileName = void 0;
4const utils_1 = require("./utils");
5const BASE_URL = 'https://github.com/electron/electron/releases/download/';
6const NIGHTLY_BASE_URL = 'https://github.com/electron/nightlies/releases/download/';
7function 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}
23exports.getArtifactFileName = getArtifactFileName;
24function mirrorVar(name, options, defaultValue) {
25 // Convert camelCase to camel_case for env var reading
26 const snakeName = name.replace(/([a-z])([A-Z])/g, (_, a, b) => `${a}_${b}`).toLowerCase();
27 return (
28 // .npmrc
29 process.env[`npm_config_electron_${name.toLowerCase()}`] ||
30 process.env[`NPM_CONFIG_ELECTRON_${snakeName.toUpperCase()}`] ||
31 process.env[`npm_config_electron_${snakeName}`] ||
32 // package.json
33 process.env[`npm_package_config_electron_${name}`] ||
34 process.env[`npm_package_config_electron_${snakeName.toLowerCase()}`] ||
35 // env
36 process.env[`ELECTRON_${snakeName.toUpperCase()}`] ||
37 options[name] ||
38 defaultValue);
39}
40async 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 // Allow customized download URL resolution.
56 if (opts.resolveAssetURL) {
57 const url = await opts.resolveAssetURL(details);
58 return url;
59 }
60 return `${base}${path}/${file}`;
61}
62exports.getArtifactRemoteURL = getArtifactRemoteURL;
63function getArtifactVersion(details) {
64 return (0, utils_1.normalizeVersion)(mirrorVar('customVersion', details.mirrorOptions || {}, details.version));
65}
66exports.getArtifactVersion = getArtifactVersion;
67//# sourceMappingURL=artifact-utils.js.map
\No newline at end of file