Skip to content

Commit

Permalink
Ref/ Electron packager in external file
Browse files Browse the repository at this point in the history
  • Loading branch information
maximegris committed May 12, 2017
1 parent d77cbf1 commit 17b04e8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 5 deletions.
64 changes: 64 additions & 0 deletions package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"use strict";

var packager = require('electron-packager');
const pkg = require('./package.json');
const argv = require('minimist')(process.argv.slice(1));

const appName = argv.name || pkg.name;
const buildVersion = pkg.version || '1.0';
const shouldUseAsar = argv.asar || false;
const shouldBuildAll = argv.all || false;
const arch = argv.arch || 'all';
const platform = argv.platform || 'darwin';

const DEFAULT_OPTS = {
dir: './dist',
name: appName,
asar: shouldUseAsar,
buildVersion: buildVersion
};

const icon = 'assets/favicon';

if (icon) {
DEFAULT_OPTS.icon = icon;
}

pack(platform, arch, function done(err, appPath) {
if(err) {
console.log(err);
} else {
console.log('Application packaged successfuly!', appPath);
}

});

function pack(plat, arch, cb) {
// there is no darwin ia32 electron
if (plat === 'darwin' && arch === 'ia32') return;

const iconObj = {
icon: DEFAULT_OPTS.icon + (() => {

let extension = '.png';
if (plat === 'darwin') {
extension = '.icns';
} else if (plat === 'win32') {
extension = '.ico';
}
return extension;
})()
};

const opts = Object.assign({}, DEFAULT_OPTS, {
platform: plat,
arch,
prune: true,
overwrite: true,
all: shouldBuildAll,
out: `app-builds`
});

console.log(opts)
packager(opts, cb);
}
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
"lint": "ng lint",
"start": "webpack --watch",
"start:web": "webpack-dev-server . --port 4200",
"build": "webpack --display-error-details && copyfiles main.js dist",
"build": "webpack --display-error-details && copyfiles main.js package.json dist",
"dependencies:prod": "cd ./dist && npm install --only=prod && cd ..",
"build:prod": "cross-env NODE_ENV='production' npm run build",
"electron:serve": "electron . --serve",
"electron:test": "electron ./dist",
"electron:dev": "npm run build && electron dist/main.js",
"electron:prod": "npm run build:prod && electron dist/main.js",
"electron:linux": "npm run build:prod && copyfiles package.json dist && electron-packager dist --overwrite --platform=linux --arch=x64 --asar=true --out=app-builds",
"electron:windows": "npm run build:prod && copyfiles package.json dist && electron-packager dist --overwrite --platform=win32 --arch=ia32 --asar=true --out=app-builds",
"electron:mac": "npm run build:prod && copyfiles package.json dist && electron-packager dist --overwrite --platform=darwin --arch=x64 --asar=true --out=app-builds",
"electron:linux": "npm run build:prod && node package.js --asar --platform=linux --arch=x64",
"electron:windows": "npm run build:prod && node package.js --asar --platform=win32 --arch=ia32",
"electron:mac": "npm run build:prod && node package.js --asar --platform=darwin --arch=x64",
"test": "karma start ./karma.conf.js",
"e2e": "protractor ./protractor.conf.js",
"pree2e": "webdriver-manager update --standalone false --gecko false --quiet"
Expand Down Expand Up @@ -57,7 +59,7 @@
"cross-env": "^4.0.0",
"css-loader": "~0.26.1",
"cssnano": "~3.10.0",
"electron": "~1.6.5",
"electron": "~1.6.7",
"electron-packager": "~8.6.0",
"electron-reload": "~1.1.0",
"exports-loader": "~0.6.4",
Expand All @@ -76,6 +78,8 @@
"karma-jasmine-html-reporter": "~0.2.2",
"karma-sourcemap-loader": "~0.3.7",
"less-loader": "~2.2.3",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"postcss-loader": "~1.3.3",
"postcss-url": "~6.0.4",
"protractor": "~5.1.1",
Expand Down

0 comments on commit 17b04e8

Please sign in to comment.