2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-11-11 07:41:04 +00:00

Add basic Linux support

Copies both the electron-prebuilt distribution into the app's toplevel
dist directory (by default) and the user's app into the correct subdirectory.
This commit is contained in:
Mark Lee 2015-05-04 21:11:53 -07:00
parent 17803f01d1
commit 6634913bb2
2 changed files with 72 additions and 0 deletions

View File

@ -22,6 +22,7 @@ module.exports = function packager (opts, cb) {
switch (os.platform()) {
case 'darwin': platform = require('./mac'); break
case 'linux': platform = require('./linux'); break
default: cb(new Error('Unsupported platform'))
}

71
linux.js Normal file
View File

@ -0,0 +1,71 @@
var path = require('path')
var fs = require('fs')
var child = require('child_process')
var mkdirp = require('mkdirp')
var ncp = require('ncp').ncp
module.exports = {
createApp: function createApp (opts, cb, electronPath) {
var templateApp = path.join(electronPath, 'dist')
var finalDir = opts.out || path.join(process.cwd(), 'dist')
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: userFilter}, 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)
})
}
function prune (cb) {
child.exec('npm prune --production', { cwd: userAppDir }, cb)
}
function appFilter (file) {
return file.match(/default_app/) === null
}
function userFilter (file) {
var ignore = opts.ignore || []
if (!Array.isArray(ignore)) ignore = [ignore]
ignore = ignore.concat([finalDir])
for (var i = 0; i < ignore.length; i++) {
if (file.match(ignore[i])) {
return false
}
}
return true
}
copyApp()
}
}