refactor to use electron-download
This commit is contained in:
parent
92a2eb2864
commit
e2fc1a0fb1
2 changed files with 15 additions and 28 deletions
|
@ -1,18 +1,15 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
// maintainer note - update this manually when doing new releases:
|
||||
var version = '0.25.3'
|
||||
|
||||
var fs = require('fs')
|
||||
var os = require('os')
|
||||
var path = require('path')
|
||||
var pathExists = require('path-exists')
|
||||
var mkdir = require('mkdirp')
|
||||
var nugget = require('nugget')
|
||||
var extract = require('extract-zip')
|
||||
var fs = require('fs')
|
||||
var getHomePath = require('home-path')()
|
||||
var download = require('electron-download')
|
||||
|
||||
var platform = os.platform()
|
||||
var arch = os.arch()
|
||||
var version = '0.25.3'
|
||||
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'
|
||||
|
||||
function onerror (err) {
|
||||
throw err
|
||||
|
@ -24,24 +21,18 @@ var paths = {
|
|||
win32: path.join(__dirname, './dist/electron.exe')
|
||||
}
|
||||
|
||||
var cache = path.join(getHomePath, './.electron')
|
||||
|
||||
if (!paths[platform]) throw new Error('Unknown platform: ' + platform)
|
||||
|
||||
// use cache if possible
|
||||
if (pathExists.sync(path.join(cache, filename))) {
|
||||
extractFile()
|
||||
} else {
|
||||
mkdir(cache, function(err) {
|
||||
if (err) return onerror(err)
|
||||
nugget(url, {target: filename, dir: cache, resume: true, verbose: true}, extractFile)
|
||||
})
|
||||
}
|
||||
// downloads if not cached
|
||||
download({version: version}, extractFile)
|
||||
|
||||
function extractFile (err) {
|
||||
// unzips and makes path.txt point at the correct executable
|
||||
function extractFile (err, zipPath) {
|
||||
if (err) return onerror(err)
|
||||
fs.writeFileSync(path.join(__dirname, 'path.txt'), paths[platform])
|
||||
extract(path.join(cache, filename), {dir: path.join(__dirname, 'dist')}, function (err) {
|
||||
fs.writeFile(path.join(__dirname, 'path.txt'), paths[platform], function (err) {
|
||||
if (err) return onerror(err)
|
||||
extract(zipPath, {dir: path.join(__dirname, 'dist')}, function (err) {
|
||||
if (err) return onerror(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -17,13 +17,9 @@
|
|||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"extract-zip": "^1.0.3",
|
||||
"home-path": "^0.1.1",
|
||||
"mkdirp": "^0.5.0",
|
||||
"nugget": "^1.2.0",
|
||||
"path-exists": "^1.0.0"
|
||||
"electron-download": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.3.3",
|
||||
"tape": "^3.0.1"
|
||||
},
|
||||
"author": "Mathias Buus",
|
||||
|
|
Loading…
Reference in a new issue