2014-10-20 04:17:38 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2024-10-03 02:10:44 +00:00
|
|
|
const { downloadArtifact } = require('@electron/get');
|
|
|
|
|
|
|
|
const extract = require('extract-zip');
|
2015-05-10 20:54:06 +00:00
|
|
|
|
2021-07-06 01:40:26 +00:00
|
|
|
const childProcess = require('child_process');
|
2020-10-21 22:43:52 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const os = require('os');
|
|
|
|
const path = require('path');
|
2024-10-03 02:10:44 +00:00
|
|
|
|
|
|
|
const { version } = require('./package');
|
2015-05-10 20:54:06 +00:00
|
|
|
|
2019-05-03 17:17:15 +00:00
|
|
|
if (process.env.ELECTRON_SKIP_BINARY_DOWNLOAD) {
|
2020-10-21 22:43:52 +00:00
|
|
|
process.exit(0);
|
2019-05-03 17:17:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 22:43:52 +00:00
|
|
|
const platformPath = getPlatformPath();
|
2014-10-20 04:56:49 +00:00
|
|
|
|
2019-12-30 17:48:54 +00:00
|
|
|
if (isInstalled()) {
|
2020-10-21 22:43:52 +00:00
|
|
|
process.exit(0);
|
2015-12-09 15:16:56 +00:00
|
|
|
}
|
|
|
|
|
2021-07-06 01:40:26 +00:00
|
|
|
const platform = process.env.npm_config_platform || process.platform;
|
|
|
|
let arch = process.env.npm_config_arch || process.arch;
|
|
|
|
|
2022-01-07 08:53:15 +00:00
|
|
|
if (platform === 'darwin' && process.platform === 'darwin' && arch === 'x64' &&
|
|
|
|
process.env.npm_config_arch === undefined) {
|
2021-07-06 01:40:26 +00:00
|
|
|
// When downloading for macOS ON macOS and we think we need x64 we should
|
|
|
|
// check if we're running under rosetta and download the arm64 version if appropriate
|
|
|
|
try {
|
|
|
|
const output = childProcess.execSync('sysctl -in sysctl.proc_translated');
|
|
|
|
if (output.toString().trim() === '1') {
|
|
|
|
arch = 'arm64';
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// Ignore failure
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-22 17:34:52 +00:00
|
|
|
// downloads if not cached
|
2019-05-24 20:40:53 +00:00
|
|
|
downloadArtifact({
|
|
|
|
version,
|
|
|
|
artifactName: 'electron',
|
2017-05-23 20:16:01 +00:00
|
|
|
force: process.env.force_no_cache === 'true',
|
2019-05-24 20:40:53 +00:00
|
|
|
cacheRoot: process.env.electron_config_cache,
|
2023-10-31 20:51:59 +00:00
|
|
|
checksums: process.env.electron_use_remote_checksums ?? process.env.npm_config_electron_use_remote_checksums ? undefined : require('./checksums.json'),
|
2021-07-06 01:40:26 +00:00
|
|
|
platform,
|
|
|
|
arch
|
2019-12-30 17:48:54 +00:00
|
|
|
}).then(extractFile).catch(err => {
|
2020-10-21 22:43:52 +00:00
|
|
|
console.error(err.stack);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2019-12-30 17:48:54 +00:00
|
|
|
|
|
|
|
function isInstalled () {
|
|
|
|
try {
|
|
|
|
if (fs.readFileSync(path.join(__dirname, 'dist', 'version'), 'utf-8').replace(/^v/, '') !== version) {
|
2020-10-21 22:43:52 +00:00
|
|
|
return false;
|
2019-12-30 17:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fs.readFileSync(path.join(__dirname, 'path.txt'), 'utf-8') !== platformPath) {
|
2020-10-21 22:43:52 +00:00
|
|
|
return false;
|
2019-12-30 17:48:54 +00:00
|
|
|
}
|
2024-09-26 07:12:11 +00:00
|
|
|
} catch {
|
2020-10-21 22:43:52 +00:00
|
|
|
return false;
|
2019-12-30 17:48:54 +00:00
|
|
|
}
|
2020-10-21 22:43:52 +00:00
|
|
|
|
|
|
|
const electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist', platformPath);
|
|
|
|
|
|
|
|
return fs.existsSync(electronPath);
|
2019-12-30 17:48:54 +00:00
|
|
|
}
|
2015-05-07 04:44:10 +00:00
|
|
|
|
2015-05-10 20:54:06 +00:00
|
|
|
// unzips and makes path.txt point at the correct executable
|
2019-05-24 20:40:53 +00:00
|
|
|
function extractFile (zipPath) {
|
2022-11-18 23:21:11 +00:00
|
|
|
const distPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist');
|
|
|
|
|
|
|
|
return extract(zipPath, { dir: path.join(__dirname, 'dist') }).then(() => {
|
|
|
|
// If the zip contains an "electron.d.ts" file,
|
|
|
|
// move that up
|
|
|
|
const srcTypeDefPath = path.join(distPath, 'electron.d.ts');
|
|
|
|
const targetTypeDefPath = path.join(__dirname, 'electron.d.ts');
|
|
|
|
const hasTypeDefinitions = fs.existsSync(srcTypeDefPath);
|
|
|
|
|
|
|
|
if (hasTypeDefinitions) {
|
|
|
|
fs.renameSync(srcTypeDefPath, targetTypeDefPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write a "path.txt" file.
|
|
|
|
return fs.promises.writeFile(path.join(__dirname, 'path.txt'), platformPath);
|
2022-09-26 18:39:26 +00:00
|
|
|
});
|
2015-05-07 04:44:10 +00:00
|
|
|
}
|
2016-12-27 19:48:14 +00:00
|
|
|
|
|
|
|
function getPlatformPath () {
|
2020-10-21 22:43:52 +00:00
|
|
|
const platform = process.env.npm_config_platform || os.platform();
|
2016-12-27 19:48:14 +00:00
|
|
|
|
|
|
|
switch (platform) {
|
2020-01-17 05:44:21 +00:00
|
|
|
case 'mas':
|
2016-12-27 19:48:14 +00:00
|
|
|
case 'darwin':
|
2020-10-21 22:43:52 +00:00
|
|
|
return 'Electron.app/Contents/MacOS/Electron';
|
2016-12-27 19:48:14 +00:00
|
|
|
case 'freebsd':
|
2019-08-22 19:09:15 +00:00
|
|
|
case 'openbsd':
|
2016-12-27 19:48:14 +00:00
|
|
|
case 'linux':
|
2020-10-21 22:43:52 +00:00
|
|
|
return 'electron';
|
2016-12-27 19:48:14 +00:00
|
|
|
case 'win32':
|
2020-10-21 22:43:52 +00:00
|
|
|
return 'electron.exe';
|
2016-12-27 19:48:14 +00:00
|
|
|
default:
|
2020-10-21 22:43:52 +00:00
|
|
|
throw new Error('Electron builds are not available on platform: ' + platform);
|
2016-12-27 19:48:14 +00:00
|
|
|
}
|
|
|
|
}
|