forked from plotly/falcon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage.js
146 lines (130 loc) · 4.52 KB
/
package.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* eslint strict: 0, no-shadow: 0, no-unused-vars: 0, no-console: 0 */
'use strict';
require('babel-polyfill');
const os = require('os');
const webpack = require('webpack');
const electronCfg = require('./webpack.config.electron.js');
const cfg = require('./webpack.config.production.js');
const packager = require('electron-packager');
const del = require('del');
const exec = require('child_process').exec;
const execSync = require('child_process').execSync;
const argv = require('minimist')(process.argv.slice(2));
const pkg = require('./package.json');
const deps = Object.keys(pkg.dependencies);
const devDeps = Object.keys(pkg.devDependencies);
const appName = argv.name || argv.n || pkg.productName;
const shouldUseAsar = argv.asar || argv.a || false;
const shouldBuildAll = argv.all || false;
const userFriendlyAppNames = {
arch: {ia32: '32bit', x64: '64bit'}, plat: {linux: 'Linux', darwin: 'Mac', win32: 'Windows'}
};
const DEFAULT_OPTS = {
electronVersion: devDeps.electron,
dir: './',
name: appName,
asar: shouldUseAsar,
ignore: [
'^/scripts($|/)',
'^/spec($|/)',
'^/test($|/)',
'^/tools($|/)',
'^/release($|/)',
'^/ssl/certs($|/)',
'^/backend/main.development.js'
]
.concat(
devDeps
.map(dep => `/node_modules/${dep}($|/)`))
};
const icon = argv.icon || argv.i || 'app/app';
if (icon) {
DEFAULT_OPTS.icon = icon;
}
startPack();
function build(cfg) {
return new Promise((resolve, reject) => {
webpack(cfg, (err, stats) => {
if (err) return reject(err);
resolve(stats);
});
});
}
function startPack() {
console.log('start pack: ' + os.platform());
/*
* Workaround for: https://github.com/ibmdb/node-ibm_db/issues/329
* This can be removed once the issue is resolved.
*/
if (os.platform() === 'darwin') {
// Surpressed ESLint cause this is a complex command and concatenation would make it harder to maintain
// eslint-disable-next-line max-len
console.log('Running command:');
execSync('echo install_name_tool -change ' +
'`pwd`/node_modules/ibm_db/installer/clidriver/lib/libdb2.dylib ' +
'@loader_path/../../installer/clidriver/lib/libdb2.dylib ' +
'node_modules/ibm_db/build/Release/odbc_bindings.node', {stdio: [0, 1, 2]});
execSync('install_name_tool -change ' +
'`pwd`/node_modules/ibm_db/installer/clidriver/lib/libdb2.dylib ' +
'@loader_path/../../installer/clidriver/lib/libdb2.dylib ' +
'node_modules/ibm_db/build/Release/odbc_bindings.node',
function(err, stdout, stderr) {
console.log(stdout);
if (stderr) {
console.warn('An error occured:' + stderr);
return;
}
});
}
build(electronCfg)
.then(() => build(cfg))
.then(() => del('release'))
.then(paths => {
if (shouldBuildAll) {
// build for all platforms
const archs = ['ia32', 'x64'];
const platforms = ['linux', 'win32', 'darwin'];
platforms.forEach(plat => {
archs.forEach(arch => {
pack(plat, arch, log(plat, arch));
});
});
} else {
// build for current platform only
pack(os.platform(), os.arch(), log(os.platform(), os.arch()));
}
})
.catch(err => {
console.error(err);
});
}
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, iconObj, {
platform: plat,
arch,
prune: true,
'appVersion': pkg.version,
out: `release/${userFriendlyAppNames.plat[plat]}-${userFriendlyAppNames.arch[arch]}`
});
packager(opts, cb);
}
function log(plat, arch) {
return (err, filepath) => {
if (err) return console.error(err);
console.log(`${plat}-${arch} finished! see release/` +
`${userFriendlyAppNames.plat[plat]}-${userFriendlyAppNames.arch[arch]}`);
};
}