2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-09-27 20:09:03 +00:00
nativefier/linux.js

65 lines
1.7 KiB
JavaScript
Raw Normal View History

var path = require('path')
var fs = require('fs')
var child = require('child_process')
var mkdirp = require('mkdirp')
var ncp = require('ncp').ncp
2015-06-10 02:17:21 +00:00
var common = require('./common')
module.exports = {
createApp: function createApp (opts, templateApp, cb) {
var finalDir = opts.out || path.join(process.cwd(), opts.name + '-linux')
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 () {
ncp(opts.dir, userAppDir, {filter: common.userIgnoreFilter(opts, false, finalDir), dereference: true}, function copied (err) {
if (err) return cb(err)
if (opts.prune) {
prune(function pruned (err) {
if (err) return cb(err)
renameElectronBinary()
})
} else {
renameElectronBinary()
}
})
}
function renameElectronBinary () {
fs.rename(originalBinary, finalBinary, function electronRenamed (err) {
if (err) return cb(err)
2015-05-06 04:32:17 +00:00
if (opts.asar) {
2015-06-10 02:17:21 +00:00
common.asarApp(finalDir, cb)
2015-05-06 04:32:17 +00:00
} else {
cb(null, finalBinary)
2015-05-06 04:32:17 +00:00
}
})
}
function prune (cb) {
child.exec('npm prune --production', { cwd: userAppDir }, cb)
}
function appFilter (file) {
return file.match(/default_app/) === null
}
copyApp()
}
}