2015-05-05 04:11:53 +00:00
|
|
|
var path = require('path')
|
|
|
|
var fs = require('fs')
|
|
|
|
var mkdirp = require('mkdirp')
|
|
|
|
var ncp = require('ncp').ncp
|
2015-06-10 02:17:21 +00:00
|
|
|
var common = require('./common')
|
2015-05-05 04:11:53 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2015-05-10 20:57:42 +00:00
|
|
|
createApp: function createApp (opts, templateApp, cb) {
|
|
|
|
var finalDir = opts.out || path.join(process.cwd(), opts.name + '-linux')
|
2015-05-05 04:11:53 +00:00
|
|
|
var userAppDir = path.join(finalDir, 'resources', 'default_app')
|
|
|
|
var originalBinary = path.join(finalDir, 'electron')
|
|
|
|
var finalBinary = path.join(finalDir, opts.name)
|
|
|
|
|
|
|
|
function copyApp () {
|
|
|
|
mkdirp(finalDir, function AppFolderCreated (err) {
|
|
|
|
if (err) return cb(err)
|
|
|
|
copyAppTemplate()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyAppTemplate () {
|
|
|
|
ncp(templateApp, finalDir, {filter: appFilter}, function AppCreated (err) {
|
|
|
|
if (err) return cb(err)
|
|
|
|
copyUserApp()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyUserApp () {
|
2015-06-10 02:26:55 +00:00
|
|
|
ncp(opts.dir, userAppDir, {filter: common.userIgnoreFilter(opts, false, finalDir), dereference: true}, function copied (err) {
|
2015-05-05 04:11:53 +00:00
|
|
|
if (err) return cb(err)
|
2015-06-10 02:30:43 +00:00
|
|
|
common.prune(opts, userAppDir, cb, renameElectronBinary)
|
2015-05-05 04:11:53 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function renameElectronBinary () {
|
|
|
|
fs.rename(originalBinary, finalBinary, function electronRenamed (err) {
|
2015-06-22 14:52:44 +00:00
|
|
|
var asarDir
|
2015-05-05 04:11:53 +00:00
|
|
|
if (err) return cb(err)
|
2015-05-06 04:32:17 +00:00
|
|
|
if (opts.asar) {
|
2015-06-22 14:52:44 +00:00
|
|
|
asarDir = path.join(finalDir, 'resources')
|
|
|
|
common.asarApp(asarDir, cb)
|
2015-05-06 04:32:17 +00:00
|
|
|
} else {
|
2015-05-10 20:57:42 +00:00
|
|
|
cb(null, finalBinary)
|
2015-05-06 04:32:17 +00:00
|
|
|
}
|
2015-05-05 04:11:53 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function appFilter (file) {
|
|
|
|
return file.match(/default_app/) === null
|
|
|
|
}
|
|
|
|
|
|
|
|
copyApp()
|
|
|
|
}
|
|
|
|
}
|