This commit is contained in:
RnbWd 2015-05-06 21:44:10 -07:00
Родитель 8fdb5b42d8
Коммит 7864197291
4 изменённых файлов: 39 добавлений и 8 удалений

Просмотреть файл

@ -1,3 +1,5 @@
language: node_js language: node_js
node_js: node_js:
- '0.10' - '0.10'
- '0.12'
- 'iojs'

Просмотреть файл

@ -2,10 +2,12 @@
var os = require('os') var os = require('os')
var path = require('path') var path = require('path')
var pathExists = require('path-exists')
var mkdir = require('mkdirp')
var nugget = require('nugget') var nugget = require('nugget')
var extract = require('extract-zip') var extract = require('extract-zip')
var fs = require('fs') var fs = require('fs')
var getHomePath = require('home-path')()
var platform = os.platform() var platform = os.platform()
var arch = os.arch() var arch = os.arch()
var version = '0.25.2' var version = '0.25.2'
@ -22,12 +24,28 @@ var paths = {
win32: path.join(__dirname, './dist/electron.exe') 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) 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) if (err) return onerror(err)
fs.writeFileSync(path.join(__dirname, 'path.txt'), paths[platform]) 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) if (err) return onerror(err)
}) })
}) }

Просмотреть файл

@ -8,7 +8,8 @@
}, },
"scripts": { "scripts": {
"install": "node install.js", "install": "node install.js",
"test": "tape test/*.js" "test": "tape test/*.js",
"cache-clean": "rimraf ~/.electron"
}, },
"bin": { "bin": {
"electron": "cli.js" "electron": "cli.js"
@ -16,10 +17,13 @@
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"extract-zip": "^1.0.3", "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": { "devDependencies": {
"path-exists": "^1.0.0", "rimraf": "^2.3.3",
"tape": "^3.0.1" "tape": "^3.0.1"
}, },
"author": "Mathias Buus", "author": "Mathias Buus",

Просмотреть файл

@ -1,8 +1,15 @@
var tape = require('tape') var tape = require('tape')
var electron = require('../') var electron = require('../')
var path = require('path');
var pathExists = require('path-exists') 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.ok(pathExists.sync(electron), 'electron was downloaded')
t.end() t.end()
}) })
tape('has cache folder', function(t) {
t.ok(pathExists.sync(path.join(getHomePath, './.electron')), 'cache exists')
t.end()
})