Skip to content

Instantly share code, notes, and snippets.

@coelhoadler
Created September 23, 2017 14:10
Show Gist options
  • Select an option

  • Save coelhoadler/9560004069c92c73346b2b56197a63c9 to your computer and use it in GitHub Desktop.

Select an option

Save coelhoadler/9560004069c92c73346b2b56197a63c9 to your computer and use it in GitHub Desktop.
electron-packager nº 2
"use strict";
var packager = require('electron-packager');
const pkg = require('./package.json');
const argv = require('minimist')(process.argv.slice(1));
const platform = (argv.platform) || 'darwin';
const aux_platform = (platform == "darwin") ? "mac" : (platform == "win32") ? "win" : platform;
const arch = argv.arch || 'all';
const appName = argv.name || pkg.version + "-" + aux_platform;
const buildVersion = pkg.version || '0.0.0';
const shouldUseAsar = argv.asar || false;
const shouldBuildAll = argv.all || false;
const DEFAULT_OPTS = {
dir: '.',
name: appName,
asar: shouldUseAsar,
buildVersion: buildVersion
};
const icon = './assets/icons/logotipo';
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 whatIsTheExtension(plat) {
let extension = '.png';
if (plat === 'darwin') {
extension = '.icns';
} else if (plat === 'win32') {
extension = '.ico';
}
return extension;
}
function pack(plat, arch, cb) {
// there is no darwin ia32 electron
if (plat === 'darwin' && arch === 'ia32') return;
const iconObj = {
icon: DEFAULT_OPTS.icon + whatIsTheExtension(plat)
};
DEFAULT_OPTS.icon = iconObj.icon;
const opts = Object.assign({}, DEFAULT_OPTS, {
platform: plat,
arch,
prune: true,
overwrite: true,
all: shouldBuildAll,
out: `app-builds`
});
console.log(opts)
packager(opts, cb);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment