2015-03-23 02:51:19 +00:00
|
|
|
var path = require('path')
|
2015-05-10 20:57:42 +00:00
|
|
|
var os = require('os')
|
2015-03-23 02:51:19 +00:00
|
|
|
|
2015-05-10 20:57:42 +00:00
|
|
|
var download = require('electron-download')
|
|
|
|
var extract = require('extract-zip')
|
|
|
|
var mkdirp = require('mkdirp')
|
|
|
|
var rimraf = require('rimraf')
|
2015-04-05 16:04:24 +00:00
|
|
|
|
2015-05-10 20:57:42 +00:00
|
|
|
var mac = require('./mac.js')
|
|
|
|
var linux = require('./linux.js')
|
|
|
|
var win32 = require('./win32.js')
|
|
|
|
|
|
|
|
module.exports = function packager (opts, cb) {
|
2015-06-10 02:37:46 +00:00
|
|
|
var platformPackager
|
2015-05-10 20:57:42 +00:00
|
|
|
var platform = opts.platform
|
|
|
|
var arch = opts.arch
|
|
|
|
var version = opts.version
|
2015-04-04 16:47:01 +00:00
|
|
|
|
2015-05-10 20:57:42 +00:00
|
|
|
if (!platform || !arch || !version) cb(new Error('Must specify platform, arch and version'))
|
2015-04-04 16:47:01 +00:00
|
|
|
|
2015-05-11 15:22:10 +00:00
|
|
|
switch (arch) {
|
|
|
|
case 'ia32': break
|
|
|
|
case 'x64': break
|
2015-05-11 19:10:26 +00:00
|
|
|
default: return cb(new Error('Unsupported arch. Must be either ia32 or x64'))
|
2015-05-11 15:22:10 +00:00
|
|
|
}
|
|
|
|
|
2015-05-10 20:57:42 +00:00
|
|
|
switch (platform) {
|
2015-06-10 02:37:46 +00:00
|
|
|
case 'darwin': platformPackager = mac; break
|
|
|
|
case 'linux': platformPackager = linux; break
|
|
|
|
case 'win32': platformPackager = win32; break
|
2015-05-11 19:10:26 +00:00
|
|
|
default: return cb(new Error('Unsupported platform. Must be either darwin, linux, or win32'))
|
2015-03-23 02:51:19 +00:00
|
|
|
}
|
2015-04-24 12:07:39 +00:00
|
|
|
|
2015-05-18 17:51:33 +00:00
|
|
|
// Ignore this and related modules by default
|
2015-05-22 00:19:05 +00:00
|
|
|
var defaultIgnores = ['/node_modules/electron-prebuilt($|/)', '/node_modules/electron-packager($|/)', '/\.git($|/)']
|
2015-05-18 17:51:33 +00:00
|
|
|
if (opts.ignore && !Array.isArray(opts.ignore)) opts.ignore = [opts.ignore]
|
2015-05-18 21:10:10 +00:00
|
|
|
opts.ignore = (opts.ignore) ? opts.ignore.concat(defaultIgnores) : defaultIgnores
|
2015-05-18 17:51:33 +00:00
|
|
|
|
2015-05-10 20:57:42 +00:00
|
|
|
download({
|
|
|
|
platform: platform,
|
|
|
|
arch: arch,
|
|
|
|
version: version
|
|
|
|
}, function (err, zipPath) {
|
|
|
|
if (err) return cb(err)
|
|
|
|
console.error('Packaging app for platform', platform + ' ' + arch, 'using electron v' + version)
|
|
|
|
// extract zip into tmp so that packager can use it as a template
|
|
|
|
var tmpDir = path.join(os.tmpdir(), 'electron-packager-' + platform + '-template')
|
|
|
|
rimraf(tmpDir, function (err) {
|
|
|
|
if (err) {} // ignore err
|
|
|
|
mkdirp(tmpDir, function (err) {
|
|
|
|
if (err) return cb(err)
|
|
|
|
extract(zipPath, {dir: tmpDir}, function (err) {
|
|
|
|
if (err) return cb(err)
|
2015-06-10 02:37:46 +00:00
|
|
|
platformPackager.createApp(opts, tmpDir, cb)
|
2015-05-10 20:57:42 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2015-03-23 02:51:19 +00:00
|
|
|
}
|