2014-10-20 04:17:38 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2019-05-24 20:40:53 +00:00
|
|
|
const version = require('./package').version
|
2015-05-10 20:54:06 +00:00
|
|
|
|
2019-05-24 20:40:53 +00:00
|
|
|
const fs = require('fs')
|
|
|
|
const os = require('os')
|
|
|
|
const path = require('path')
|
|
|
|
const extract = require('extract-zip')
|
|
|
|
const { downloadArtifact } = require('@electron/get')
|
2015-05-10 20:54:06 +00:00
|
|
|
|
2019-05-24 20:40:53 +00:00
|
|
|
let installedVersion = null
|
2015-12-09 15:16:56 +00:00
|
|
|
try {
|
|
|
|
installedVersion = fs.readFileSync(path.join(__dirname, 'dist', 'version'), 'utf-8').replace(/^v/, '')
|
2016-12-27 19:49:44 +00:00
|
|
|
} catch (ignored) {
|
2015-12-09 15:16:56 +00:00
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2019-05-03 17:17:15 +00:00
|
|
|
if (process.env.ELECTRON_SKIP_BINARY_DOWNLOAD) {
|
|
|
|
process.exit(0)
|
|
|
|
}
|
|
|
|
|
2019-05-24 20:40:53 +00:00
|
|
|
const platformPath = getPlatformPath()
|
2014-10-20 04:56:49 +00:00
|
|
|
|
2019-05-24 20:40:53 +00:00
|
|
|
const electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist', platformPath)
|
2018-08-19 16:40:12 +00:00
|
|
|
|
|
|
|
if (installedVersion === version && fs.existsSync(electronPath)) {
|
2015-12-09 15:30:46 +00:00
|
|
|
process.exit(0)
|
2015-12-09 15:16:56 +00:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
platform: process.env.npm_config_platform || process.platform,
|
|
|
|
arch: process.env.npm_config_arch || process.arch
|
|
|
|
}).then((zipPath) => extractFile(zipPath)).catch((err) => onerror(err))
|
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) {
|
2018-09-13 16:10:51 +00:00
|
|
|
extract(zipPath, { dir: path.join(__dirname, 'dist') }, function (err) {
|
2014-10-20 04:17:38 +00:00
|
|
|
if (err) return onerror(err)
|
2016-12-27 19:13:15 +00:00
|
|
|
fs.writeFile(path.join(__dirname, 'path.txt'), platformPath, function (err) {
|
2015-05-10 20:54:06 +00:00
|
|
|
if (err) return onerror(err)
|
|
|
|
})
|
2014-10-20 04:17:38 +00:00
|
|
|
})
|
2015-05-07 04:44:10 +00:00
|
|
|
}
|
2016-12-27 19:48:14 +00:00
|
|
|
|
|
|
|
function onerror (err) {
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPlatformPath () {
|
2019-05-24 20:40:53 +00:00
|
|
|
const platform = process.env.npm_config_platform || os.platform()
|
2016-12-27 19:48:14 +00:00
|
|
|
|
|
|
|
switch (platform) {
|
|
|
|
case 'darwin':
|
2018-03-25 04:03:17 +00:00
|
|
|
return 'Electron.app/Contents/MacOS/Electron'
|
2016-12-27 19:48:14 +00:00
|
|
|
case 'freebsd':
|
|
|
|
case 'linux':
|
2018-03-25 04:03:17 +00:00
|
|
|
return 'electron'
|
2016-12-27 19:48:14 +00:00
|
|
|
case 'win32':
|
2018-03-25 04:03:17 +00:00
|
|
|
return 'electron.exe'
|
2016-12-27 19:48:14 +00:00
|
|
|
default:
|
|
|
|
throw new Error('Electron builds are not available on platform: ' + platform)
|
|
|
|
}
|
|
|
|
}
|