2014-10-20 04:17:38 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2015-06-09 16:48:09 +00:00
|
|
|
// maintainer note - x.y.z-ab version in package.json -> x.y.z
|
|
|
|
var version = require('./package').version.replace(/-.*/, '')
|
2015-05-10 20:54:06 +00:00
|
|
|
|
|
|
|
var fs = require('fs')
|
2014-10-20 04:17:38 +00:00
|
|
|
var os = require('os')
|
|
|
|
var path = require('path')
|
|
|
|
var extract = require('extract-zip')
|
2015-05-10 20:54:06 +00:00
|
|
|
var download = require('electron-download')
|
|
|
|
|
2015-12-09 15:16:56 +00:00
|
|
|
var installedVersion = null
|
|
|
|
try {
|
|
|
|
installedVersion = fs.readFileSync(path.join(__dirname, 'dist', 'version'), 'utf-8').replace(/^v/, '')
|
|
|
|
} catch (err) {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2016-12-27 19:48:14 +00:00
|
|
|
var platformPath = getPlatformPath()
|
2014-10-20 04:56:49 +00:00
|
|
|
|
2016-12-27 19:13:15 +00:00
|
|
|
if (installedVersion === version && fs.existsSync(path.join(__dirname, platformPath))) {
|
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
|
2016-09-19 21:32:11 +00:00
|
|
|
download({
|
|
|
|
version: version,
|
|
|
|
platform: process.env.npm_config_platform,
|
|
|
|
arch: process.env.npm_config_arch,
|
|
|
|
strictSSL: process.env.npm_config_strict_ssl === 'true',
|
2016-11-11 06:38:02 +00:00
|
|
|
quiet: ['info', 'verbose', 'silly', 'http'].indexOf(process.env.npm_config_loglevel) === -1
|
2016-09-19 21:32:11 +00:00
|
|
|
}, extractFile)
|
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
|
|
|
|
function extractFile (err, zipPath) {
|
2014-10-20 04:17:38 +00:00
|
|
|
if (err) return onerror(err)
|
2016-12-27 19:03: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 () {
|
|
|
|
var platform = process.env.npm_config_platform || os.platform()
|
|
|
|
|
|
|
|
switch (platform) {
|
|
|
|
case 'darwin':
|
|
|
|
return 'dist/Electron.app/Contents/MacOS/Electron'
|
|
|
|
case 'freebsd':
|
|
|
|
case 'linux':
|
|
|
|
return 'dist/electron'
|
|
|
|
case 'win32':
|
|
|
|
return 'dist/electron.exe'
|
|
|
|
default:
|
|
|
|
throw new Error('Electron builds are not available on platform: ' + platform)
|
|
|
|
}
|
|
|
|
}
|