diff --git a/package.json b/package.json index ab4eb91..7c9784c 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ }, "devDependencies": { "electron-packager": "^4.1.2", - "electron-prebuilt": "^0.27.2" + "electron-prebuilt": "0.27.2" }, "bin": { "playback": "./app.js" @@ -33,8 +33,9 @@ "scripts": { "start": "electron app.js", "dev": "electron app.js test.mp4", - "mac-bundle": "electron-packager . Playback --platform=darwin --arch=x64 --version=0.27.2 --ignore=node_modules/electron-prebuilt && cp info.plist Playback.app/Contents/Info.plist && cp icon.icns Playback.app/Contents/Resources/atom.icns", - "win-bundle": "electron-packager . Playback --platform=win32 --arch=ia32 --version=0.27.2 --icon=icon.ico" + "mac-bundle": "node pkg.js darwin x64", + "win-bundle": "node pkg.js win32 ia32", + "bundle": "node pkg.js" }, "repository": { "type": "git", diff --git a/pkg.js b/pkg.js new file mode 100644 index 0000000..81e9fba --- /dev/null +++ b/pkg.js @@ -0,0 +1,52 @@ +#!/usr/bin/env node + +// from https://github.com/moose-team/friends/blob/master/pkg.js + +var os = require('os') +var pkgjson = require('./package.json') +var path = require('path') +var sh = require('shelljs') + +var appVersion = pkgjson.version +var appName = 'Playback' +var electronPackager = './node_modules/.bin/electron-packager' +var electronVersion = require('./node_modules/electron-prebuilt/package.json').version +var icon = 'icon.icns' + +if (process.argv[2] === '--all') { + // build for all platforms + var archs = ['ia32', 'x64'] + var platforms = ['linux', 'win32', 'darwin'] + + platforms.forEach(function (plat) { + archs.forEach(function (arch) { + pack(plat, arch) + }) + }) +} else if (process.argv[2] && process.argv[3]) { + pack(process.argv[2], process.argv[3]) +} else { + // build for current platform only + pack(os.platform(), os.arch()) +} + +function pack (plat, arch) { + var outputPath = path.join('.', 'pkg', appVersion, plat, arch) + + sh.exec('./node_modules/.bin/rimraf ' + outputPath) + + // there is no darwin ia32 electron + if (plat === 'darwin' && arch === 'ia32') return + + var cmd = electronPackager + ' . "' + appName + '"' + + ' --platform=' + plat + + ' --arch=' + arch + + ' --version=' + electronVersion + + ' --app-version' + appVersion + + ' --icon=' + icon + + ' --out=' + outputPath + + ' --prune' + + ' --ignore=pkg' // ignore the pkg directory or hilarity will ensue + console.log(cmd) + sh.exec(cmd) +}