electron/npm/install.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2014-10-20 04:17:38 +00:00
#!/usr/bin/env node
var os = require('os')
var path = require('path')
2015-05-07 04:44:10 +00:00
var pathExists = require('path-exists')
var mkdir = require('mkdirp')
2014-10-20 04:17:38 +00:00
var nugget = require('nugget')
var extract = require('extract-zip')
2014-10-20 04:56:49 +00:00
var fs = require('fs')
2015-05-07 04:44:10 +00:00
var getHomePath = require('home-path')()
2014-10-20 04:56:49 +00:00
var platform = os.platform()
var arch = os.arch()
2015-05-08 10:31:29 +00:00
var version = '0.25.3'
2015-04-17 18:19:50 +00:00
var filename = 'electron-v' + version + '-' + platform + '-' + arch + '.zip'
var url = 'https://github.com/atom/electron/releases/download/v' + version + '/electron-v' + version + '-' + platform + '-' + arch + '.zip'
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 = {
2015-04-17 18:19:50 +00:00
darwin: path.join(__dirname, './dist/Electron.app/Contents/MacOS/Electron'),
linux: path.join(__dirname, './dist/electron'),
win32: path.join(__dirname, './dist/electron.exe')
2014-10-20 04:56:49 +00:00
}
2015-05-07 21:21:51 +00:00
var cache = path.join(getHomePath, './.electron')
2015-05-07 04:44:10 +00:00
2015-03-04 21:08:16 +00:00
if (!paths[platform]) throw new Error('Unknown platform: ' + platform)
2014-10-20 04:56:49 +00:00
2015-05-07 04:44:10 +00:00
// use cache if possible
2015-05-07 21:21:51 +00:00
if (pathExists.sync(path.join(cache, filename))) {
2015-05-07 04:44:10 +00:00
extractFile()
} else {
2015-05-07 21:21:51 +00:00
mkdir(cache, function(err) {
2015-05-07 04:44:10 +00:00
if (err) return onerror(err)
2015-05-07 21:21:51 +00:00
nugget(url, {target: filename, dir: cache, resume: true, verbose: true}, extractFile)
2015-05-07 04:44:10 +00:00
})
}
function extractFile (err) {
2014-10-20 04:17:38 +00:00
if (err) return onerror(err)
2014-11-15 09:21:07 +00:00
fs.writeFileSync(path.join(__dirname, 'path.txt'), paths[platform])
2015-05-07 21:21:51 +00:00
extract(path.join(cache, filename), {dir: path.join(__dirname, 'dist')}, function (err) {
2014-10-20 04:17:38 +00:00
if (err) return onerror(err)
})
2015-05-07 04:44:10 +00:00
}