2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-11-16 18:15:08 +00:00
nativefier/index.js

60 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-03-23 02:51:19 +00:00
var path = require('path')
var os = require('os')
2015-03-23 02:51:19 +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
var mac = require('./mac.js')
var linux = require('./linux.js')
var win32 = require('./win32.js')
module.exports = function packager (opts, cb) {
var packager
var platform = opts.platform
var arch = opts.arch
var version = opts.version
if (!platform || !arch || !version) cb(new Error('Must specify platform, arch and version'))
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
}
switch (platform) {
case 'darwin': packager = mac; break
case 'linux': packager = linux; break
case 'win32': packager = 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
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
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)
packager.createApp(opts, tmpDir, cb)
})
})
})
})
2015-03-23 02:51:19 +00:00
}