Merge pull request #157 from feross/package

Cleanup build script; Run plist update function for all builds
This commit is contained in:
Feross Aboukhadijeh
2016-03-19 16:09:04 -07:00

View File

@@ -10,6 +10,20 @@ var electronPackager = require('electron-packager')
var fs = require('fs') var fs = require('fs')
var path = require('path') var path = require('path')
var pkg = require('../package.json') var pkg = require('../package.json')
var plist = require('plist')
function build () {
var platform = process.argv[2]
if (platform === '--darwin') {
buildDarwin()
} else if (platform === '--win32') {
buildWin32()
} else if (platform === '--linux') {
buildLinux()
} else {
buildDarwin(() => buildWin32(() => buildLinux())) // Build all
}
}
var all = { var all = {
// Build 64 bit binaries only. // Build 64 bit binaries only.
@@ -110,77 +124,60 @@ var linux = {
// Note: Application icon for Linux is specified via the BrowserWindow `icon` option. // Note: Application icon for Linux is specified via the BrowserWindow `icon` option.
} }
var platform = process.argv[2] build()
if (platform === '--darwin') {
buildDarwin(postDarwinism)
} else if (platform === '--win32') {
buildWin32()
} else if (platform === '--linux') {
buildLinux()
} else {
// Build all
buildDarwin(() => buildWin32(() => buildLinux()))
}
function buildDarwin (cb) { function buildDarwin (cb) {
electronPackager(Object.assign({}, all, darwin), done.bind(null, cb)) electronPackager(Object.assign({}, all, darwin), function (err, appPath) {
} printDone(err, appPath)
if (err) return cb(err)
function buildWin32 (cb) { var contentsPath = path.join(
electronPackager(Object.assign({}, all, win32), done.bind(null, cb))
}
function buildLinux (cb) {
electronPackager(Object.assign({}, all, linux), done.bind(null, cb))
}
function postDarwinism () {
var plist = require('plist')
var contentsPath = path.join.apply(null, [
__dirname, __dirname,
'..', '..',
'dist', 'dist',
`${config.APP_NAME}-darwin-x64`, `${config.APP_NAME}-darwin-x64`,
`${config.APP_NAME}.app`, `${config.APP_NAME}.app`,
'Contents' 'Contents'
]) )
var resourcesPath = path.join(contentsPath, 'Resources') var resourcesPath = path.join(contentsPath, 'Resources')
var infoPlistPath = path.join(contentsPath, 'Info.plist') var infoPlistPath = path.join(contentsPath, 'Info.plist')
var webTorrentFileIconPath = path.join.apply(null, [ var webTorrentFileIconPath = path.join(
__dirname, __dirname,
'..', '..',
'static', 'static',
'WebTorrentFile.icns' 'WebTorrentFile.icns'
]) )
var infoPlist = plist.parse(fs.readFileSync(infoPlistPath, 'utf8')) var infoPlist = plist.parse(fs.readFileSync(infoPlistPath).toString())
infoPlist.CFBundleDocumentTypes = [ infoPlist['CFBundleDocumentTypes'] = [{
{
CFBundleTypeExtensions: [ 'torrent' ], CFBundleTypeExtensions: [ 'torrent' ],
CFBundleTypeIconFile: 'WebTorrentFile.icns',
CFBundleTypeName: 'BitTorrent Document', CFBundleTypeName: 'BitTorrent Document',
CFBundleTypeRole: 'Editor', CFBundleTypeRole: 'Editor',
LSHandlerRank: 'Owner', CFBundleTypeIconFile: 'WebTorrentFile.icns'
LSItemContentTypes: [ 'org.bittorrent.torrent' ] }]
},
{
CFBundleTypeName: 'Any',
CFBundleTypeOSTypes: [ '****' ],
CFBundleTypeRole: 'Editor',
LSTypeIsPackage: false,
LSHandlerRank: 'Owner'
}
]
infoPlist.NSHumanReadableCopyright = 'Copyright © 2014-2016 The WebTorrent Project'
fs.writeFileSync(infoPlistPath, plist.build(infoPlist)) fs.writeFileSync(infoPlistPath, plist.build(infoPlist))
cp.execSync(`cp ${webTorrentFileIconPath} ${resourcesPath}`) cp.execSync(`cp ${webTorrentFileIconPath} ${resourcesPath}`)
if (cb) cb(null)
})
} }
function done (cb, err, appPath) { function buildWin32 (cb) {
electronPackager(Object.assign({}, all, win32), function (err, appPath) {
printDone(err, appPath)
if (cb) cb(err)
})
}
function buildLinux (cb) {
electronPackager(Object.assign({}, all, linux), function (err, appPath) {
printDone(err, appPath)
if (cb) cb(err)
})
}
function printDone (err, appPath) {
if (err) console.error(err.message || err) if (err) console.error(err.message || err)
else console.log('Built ' + appPath) else console.log('Built ' + appPath)
if (cb) cb()
} }