2015-05-06 19:11:03 +00:00
|
|
|
var os = require('os')
|
|
|
|
var path = require('path')
|
|
|
|
var child = require('child_process')
|
|
|
|
|
|
|
|
var mkdirp = require('mkdirp')
|
|
|
|
var rimraf = require('rimraf')
|
|
|
|
var ncp = require('ncp').ncp
|
|
|
|
var mv = require('mv')
|
|
|
|
var rcedit = require('rcedit')
|
2015-06-10 02:17:21 +00:00
|
|
|
var common = require('./common')
|
2015-05-06 19:11:03 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2015-05-10 20:57:42 +00:00
|
|
|
createApp: function createApp (opts, electronApp, cb) {
|
2015-05-06 19:11:03 +00:00
|
|
|
var tmpDir = path.join(os.tmpdir(), 'electron-packager-windows')
|
|
|
|
|
2015-05-10 20:57:42 +00:00
|
|
|
var newApp = path.join(tmpDir, opts.name + '-win32')
|
2015-05-06 19:11:03 +00:00
|
|
|
// reset build folders + copy template app
|
|
|
|
rimraf(tmpDir, function rmrfd () {
|
|
|
|
// ignore errors
|
|
|
|
mkdirp(newApp, function mkdirpd () {
|
|
|
|
// ignore errors
|
2015-05-10 20:57:42 +00:00
|
|
|
// copy app folder and use as template (this is exactly what Atom editor does)
|
2015-05-06 19:11:03 +00:00
|
|
|
ncp(electronApp, newApp, function copied (err) {
|
|
|
|
if (err) return cb(err)
|
2015-05-06 19:19:03 +00:00
|
|
|
// rename electron.exe
|
|
|
|
mv(path.join(newApp, 'electron.exe'), path.join(newApp, opts.name + '.exe'), function (err) {
|
|
|
|
if (err) return cb(err)
|
|
|
|
|
|
|
|
buildWinApp(opts, cb, newApp)
|
|
|
|
})
|
2015-05-06 19:11:03 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function copy (from, to, cb) {
|
|
|
|
rimraf(to, function () {
|
|
|
|
mkdirp(to, function () {
|
|
|
|
ncp(from, to, function (err) {
|
|
|
|
if (err) { return cb(err) }
|
|
|
|
cb()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildWinApp (opts, cb, newApp) {
|
|
|
|
var paths = {
|
2015-05-06 19:19:03 +00:00
|
|
|
app: path.join(newApp, 'resources', 'app')
|
2015-05-06 19:11:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function filter (file) {
|
2015-05-22 01:18:15 +00:00
|
|
|
// convert slashes so unix-format ignores work
|
|
|
|
file = file.replace(/\\/g, '/')
|
|
|
|
|
2015-05-06 19:11:03 +00:00
|
|
|
var ignore = opts.ignore || []
|
|
|
|
if (!Array.isArray(ignore)) ignore = [ignore]
|
|
|
|
for (var i = 0; i < ignore.length; i++) {
|
|
|
|
if (file.match(ignore[i])) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2015-06-10 02:17:57 +00:00
|
|
|
// copy users app into destination path
|
2015-05-21 02:05:47 +00:00
|
|
|
ncp(opts.dir, paths.app, {filter: filter, dereference: true}, function copied (err) {
|
2015-05-06 19:11:03 +00:00
|
|
|
if (err) return cb(err)
|
|
|
|
|
|
|
|
if (opts.prune) {
|
|
|
|
prune(function pruned (err) {
|
|
|
|
if (err) return cb(err)
|
|
|
|
moveApp()
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
moveApp()
|
|
|
|
}
|
|
|
|
|
|
|
|
function prune (cb) {
|
|
|
|
child.exec('npm prune --production', { cwd: paths.app }, cb)
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveApp () {
|
|
|
|
// finally, move app into cwd
|
2015-05-10 20:57:42 +00:00
|
|
|
var finalPath = path.join(opts.out || process.cwd(), opts.name + '-win32')
|
2015-05-06 19:11:03 +00:00
|
|
|
copy(newApp, finalPath, function moved (err) {
|
|
|
|
if (err) return cb(err)
|
|
|
|
if (opts.asar) {
|
2015-06-10 02:17:21 +00:00
|
|
|
var finalPath = path.join(opts.out || process.cwd(), opts.name + '-win32', 'resources')
|
|
|
|
common.asarApp(finalPath, function (err) {
|
2015-05-06 19:11:03 +00:00
|
|
|
if (err) return cb(err)
|
|
|
|
updateIcon()
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
updateIcon()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateIcon () {
|
2015-05-10 20:57:42 +00:00
|
|
|
var finalPath = path.join(opts.out || process.cwd(), opts.name + '-win32')
|
2015-05-06 19:11:03 +00:00
|
|
|
|
|
|
|
if (!opts.icon) {
|
|
|
|
return cb(null, finalPath)
|
|
|
|
}
|
|
|
|
|
2015-05-10 20:57:42 +00:00
|
|
|
var exePath = path.join(opts.out || process.cwd(), opts.name + '-win32', opts.name + '.exe')
|
2015-05-06 19:11:03 +00:00
|
|
|
|
|
|
|
rcedit(exePath, {icon: opts.icon}, function (err) {
|
|
|
|
cb(err, finalPath)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|