electron/npm/install.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

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
}
2014-10-20 04:56:49 +00:00
var platform = os.platform()
2014-10-20 04:17:38 +00:00
2015-03-04 21:08:16 +00:00
function onerror (err) {
2014-10-20 04:17:38 +00:00
throw err
}
2014-10-20 04:56:49 +00:00
var paths = {
darwin: 'dist/Electron.app/Contents/MacOS/Electron',
2015-12-12 22:14:09 +00:00
freebsd: 'dist/electron',
linux: 'dist/electron',
win32: 'dist/electron.exe'
2014-10-20 04:56:49 +00:00
}
2016-07-28 20:47:03 +00:00
if (!paths[platform]) throw new Error('Electron builds are not available on platform: ' + platform)
2014-10-20 04:56:49 +00:00
if (installedVersion === version && fs.existsSync(path.join(__dirname, paths[platform]))) {
2015-12-09 15:30:46 +00:00
process.exit(0)
2015-12-09 15:16:56 +00:00
}
// downloads if not cached
download({
version: version,
platform: process.env.npm_config_platform,
arch: process.env.npm_config_arch,
strictSSL: process.env.npm_config_strict_ssl === 'true',
2016-09-19 21:36:07 +00:00
quiet: process.env.npm_config_loglevel === 'silent'
}, 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)
2015-05-10 20:54:06 +00:00
fs.writeFile(path.join(__dirname, 'path.txt'), paths[platform], function (err) {
2014-10-20 04:17:38 +00:00
if (err) return onerror(err)
2015-05-10 20:54:06 +00:00
extract(zipPath, {dir: path.join(__dirname, 'dist')}, function (err) {
if (err) return onerror(err)
})
2014-10-20 04:17:38 +00:00
})
2015-05-07 04:44:10 +00:00
}