2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-11-16 01:37:07 +00:00

Merge pull request #18 from shama/asar

Add asar support. Closes GH-2
This commit is contained in:
Mathias Buus 2015-05-06 15:44:15 +02:00
commit ac3e2903ae
3 changed files with 36 additions and 1 deletions

View File

@ -3,6 +3,8 @@ var fs = require('fs')
var child = require('child_process') var child = require('child_process')
var mkdirp = require('mkdirp') var mkdirp = require('mkdirp')
var ncp = require('ncp').ncp var ncp = require('ncp').ncp
var rimraf = require('rimraf')
var asar = require('asar')
module.exports = { module.exports = {
createApp: function createApp (opts, cb, electronPath) { createApp: function createApp (opts, cb, electronPath) {
@ -43,6 +45,11 @@ module.exports = {
function renameElectronBinary () { function renameElectronBinary () {
fs.rename(originalBinary, finalBinary, function electronRenamed (err) { fs.rename(originalBinary, finalBinary, function electronRenamed (err) {
if (err) return cb(err) if (err) return cb(err)
if (opts.asar) {
asarApp(cb)
} else {
cb()
}
}) })
} }
@ -66,6 +73,15 @@ module.exports = {
return true return true
} }
function asarApp (cb) {
var src = path.join(finalDir, 'resources', 'app')
var dest = path.join(finalDir, 'resources', 'app.asar')
asar.createPackage(src, dest, function (err) {
if (err) return cb(err)
rimraf(src, cb)
})
}
copyApp() copyApp()
} }
} }

18
mac.js
View File

@ -7,6 +7,7 @@ var plist = require('plist')
var mkdirp = require('mkdirp') var mkdirp = require('mkdirp')
var rimraf = require('rimraf') var rimraf = require('rimraf')
var ncp = require('ncp').ncp var ncp = require('ncp').ncp
var asar = require('asar')
module.exports = { module.exports = {
createApp: function createApp (opts, cb, electronPath) { createApp: function createApp (opts, cb, electronPath) {
@ -100,9 +101,16 @@ function buildMacApp (opts, cb, newApp) {
var finalPath = path.join(opts.out || process.cwd(), opts.name + '.app') var finalPath = path.join(opts.out || process.cwd(), opts.name + '.app')
fs.rename(newApp, finalPath, function moved (err) { fs.rename(newApp, finalPath, function moved (err) {
if (err) return cb(err)
if (opts.asar) {
asarApp(function (err) {
if (err) return cb(err) if (err) return cb(err)
updateMacIcon() updateMacIcon()
}) })
} else {
updateMacIcon()
}
})
} }
function updateMacIcon () { function updateMacIcon () {
@ -116,5 +124,15 @@ function buildMacApp (opts, cb, newApp) {
cb(err, finalPath) cb(err, finalPath)
}) })
} }
function asarApp (cb) {
var finalPath = path.join(opts.out || process.cwd(), opts.name + '.app', 'Contents', 'Resources')
var src = path.join(finalPath, 'app')
var dest = path.join(finalPath, 'app.asar')
asar.createPackage(src, dest, function (err) {
if (err) return cb(err)
rimraf(src, cb)
})
}
}) })
} }

View File

@ -17,6 +17,7 @@
}, },
"homepage": "https://github.com/maxogden/electron-packager", "homepage": "https://github.com/maxogden/electron-packager",
"dependencies": { "dependencies": {
"asar": "^0.6.1",
"minimist": "^1.1.1", "minimist": "^1.1.1",
"mkdirp": "^0.5.0", "mkdirp": "^0.5.0",
"ncp": "^2.0.0", "ncp": "^2.0.0",