|
@@ -1,21 +1,21 @@
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
-const {version} = require('./package')
|
|
|
+const { version } = require('./package');
|
|
|
|
|
|
-const fs = require('fs')
|
|
|
-const os = require('os')
|
|
|
-const path = require('path')
|
|
|
-const extract = require('extract-zip')
|
|
|
-const { downloadArtifact } = require('@electron/get')
|
|
|
+const fs = require('fs');
|
|
|
+const os = require('os');
|
|
|
+const path = require('path');
|
|
|
+const extract = require('extract-zip');
|
|
|
+const { downloadArtifact } = require('@electron/get');
|
|
|
|
|
|
if (process.env.ELECTRON_SKIP_BINARY_DOWNLOAD) {
|
|
|
- process.exit(0)
|
|
|
+ process.exit(0);
|
|
|
}
|
|
|
|
|
|
-const platformPath = getPlatformPath()
|
|
|
+const platformPath = getPlatformPath();
|
|
|
|
|
|
if (isInstalled()) {
|
|
|
- process.exit(0)
|
|
|
+ process.exit(0);
|
|
|
}
|
|
|
|
|
|
// downloads if not cached
|
|
@@ -27,57 +27,57 @@ downloadArtifact({
|
|
|
platform: process.env.npm_config_platform || process.platform,
|
|
|
arch: process.env.npm_config_arch || process.arch
|
|
|
}).then(extractFile).catch(err => {
|
|
|
- console.error(err.stack)
|
|
|
- process.exit(1)
|
|
|
-})
|
|
|
+ console.error(err.stack);
|
|
|
+ process.exit(1);
|
|
|
+});
|
|
|
|
|
|
function isInstalled () {
|
|
|
try {
|
|
|
if (fs.readFileSync(path.join(__dirname, 'dist', 'version'), 'utf-8').replace(/^v/, '') !== version) {
|
|
|
- return false
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
if (fs.readFileSync(path.join(__dirname, 'path.txt'), 'utf-8') !== platformPath) {
|
|
|
- return false
|
|
|
+ return false;
|
|
|
}
|
|
|
} catch (ignored) {
|
|
|
- return false
|
|
|
+ return false;
|
|
|
}
|
|
|
-
|
|
|
- const electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist', platformPath)
|
|
|
-
|
|
|
- return fs.existsSync(electronPath)
|
|
|
+
|
|
|
+ const electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist', platformPath);
|
|
|
+
|
|
|
+ return fs.existsSync(electronPath);
|
|
|
}
|
|
|
|
|
|
// unzips and makes path.txt point at the correct executable
|
|
|
function extractFile (zipPath) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
extract(zipPath, { dir: path.join(__dirname, 'dist') }, err => {
|
|
|
- if (err) return reject(err)
|
|
|
+ if (err) return reject(err);
|
|
|
|
|
|
fs.writeFile(path.join(__dirname, 'path.txt'), platformPath, err => {
|
|
|
- if (err) return reject(err)
|
|
|
+ if (err) return reject(err);
|
|
|
|
|
|
- resolve()
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
+ resolve();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
function getPlatformPath () {
|
|
|
- const platform = process.env.npm_config_platform || os.platform()
|
|
|
+ const platform = process.env.npm_config_platform || os.platform();
|
|
|
|
|
|
switch (platform) {
|
|
|
case 'mas':
|
|
|
case 'darwin':
|
|
|
- return 'Electron.app/Contents/MacOS/Electron'
|
|
|
+ return 'Electron.app/Contents/MacOS/Electron';
|
|
|
case 'freebsd':
|
|
|
case 'openbsd':
|
|
|
case 'linux':
|
|
|
- return 'electron'
|
|
|
+ return 'electron';
|
|
|
case 'win32':
|
|
|
- return 'electron.exe'
|
|
|
+ return 'electron.exe';
|
|
|
default:
|
|
|
- throw new Error('Electron builds are not available on platform: ' + platform)
|
|
|
+ throw new Error('Electron builds are not available on platform: ' + platform);
|
|
|
}
|
|
|
}
|