diff --git a/npm/.travis.yml b/npm/.travis.yml index 244b7e88e327..991d04b6e227 100644 --- a/npm/.travis.yml +++ b/npm/.travis.yml @@ -1,3 +1,5 @@ language: node_js node_js: - '0.10' + - '0.12' + - 'iojs' diff --git a/npm/install.js b/npm/install.js index 76626bbfe84a..bf4002ed6f0c 100755 --- a/npm/install.js +++ b/npm/install.js @@ -2,10 +2,12 @@ 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 platform = os.platform() var arch = os.arch() var version = '0.25.2' @@ -22,12 +24,28 @@ var paths = { win32: path.join(__dirname, './dist/electron.exe') } +var cache = { + darwin: path.join(getHomePath, './.electron'), + linux: path.join(getHomePath, './.electron'), + win32: path.join(getHomePath, './.electron') +} + if (!paths[platform]) throw new Error('Unknown platform: ' + platform) -nugget(url, {target: filename, dir: __dirname, resume: true, verbose: true}, function (err) { +// use cache if possible +if (pathExists.sync(path.join(cache[platform], filename))) { + extractFile() +} else { + mkdir(cache[platform], function(err) { + if (err) return onerror(err) + nugget(url, {target: filename, dir: cache[platform], resume: true, verbose: true}, extractFile) + }) +} + +function extractFile (err) { if (err) return onerror(err) fs.writeFileSync(path.join(__dirname, 'path.txt'), paths[platform]) - extract(path.join(__dirname, filename), {dir: path.join(__dirname, 'dist')}, function (err) { + extract(path.join(cache[platform], filename), {dir: path.join(__dirname, 'dist')}, function (err) { if (err) return onerror(err) }) -}) +} diff --git a/npm/package.json b/npm/package.json index 531b3bfaa929..5bb1b9f7db9f 100644 --- a/npm/package.json +++ b/npm/package.json @@ -8,7 +8,8 @@ }, "scripts": { "install": "node install.js", - "test": "tape test/*.js" + "test": "tape test/*.js", + "cache-clean": "rimraf ~/.electron" }, "bin": { "electron": "cli.js" @@ -16,10 +17,13 @@ "main": "index.js", "dependencies": { "extract-zip": "^1.0.3", - "nugget": "^1.2.0" + "home-path": "^0.1.1", + "mkdirp": "^0.5.0", + "nugget": "^1.2.0", + "path-exists": "^1.0.0" }, "devDependencies": { - "path-exists": "^1.0.0", + "rimraf": "^2.3.3", "tape": "^3.0.1" }, "author": "Mathias Buus", diff --git a/npm/test/index.js b/npm/test/index.js index 02dac6340c7b..798a9377dc33 100644 --- a/npm/test/index.js +++ b/npm/test/index.js @@ -1,8 +1,15 @@ var tape = require('tape') var electron = require('../') +var path = require('path'); var pathExists = require('path-exists') +var getHomePath = require('home-path')() -tape('has binary', function(t) { +tape('has local binary', function(t) { t.ok(pathExists.sync(electron), 'electron was downloaded') t.end() }) + +tape('has cache folder', function(t) { + t.ok(pathExists.sync(path.join(getHomePath, './.electron')), 'cache exists') + t.end() +})