forked from machawk1/wail
-
Notifications
You must be signed in to change notification settings - Fork 9
/
build-binary.js
360 lines (327 loc) · 10.2 KB
/
build-binary.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
const fs = require('fs-extra')
const path = require('path')
const os = require('os')
const Promise = require('bluebird')
const webpack = require('webpack')
const zip = require('cross-zip')
const cp = require('child_process')
const electronCfg = require('./webpackConfigs/ui/webpack.config.electron.js')
const cfgUI = require('./webpackConfigs/ui/webpack.config.production.js')
const cfgCore = require('./webpackConfigs/core/webpack.config.production.js')
const packager = require('electron-packager')
const pkg = require('./package.json')
const moveThemP = require('./tools/noImportMoveJdkMemgator').moveThemP
const argv = require('minimist')(process.argv.slice(2))
const cwd = process.cwd()
const iconPath = path.normalize(path.join(cwd, 'build/icons/whale.ico'))
// fs.emptyDirSync(path.join(cwd, 'dist'))
const darwinBuild = {
icon: 'whale.icns',
iconPath: path.normalize(path.join(cwd, 'buildResources/osx/whale.icns')),
archiveIcon: 'archive.icns',
archiveIconPath: path.normalize(path.join(cwd, 'buildResources/osx/archive.icns')),
extendPlist: path.normalize(path.join(cwd, 'buildResources/osx/Extended-Info.plist'))
}
const deps = Object.keys(pkg.dependencies)
const devDeps = Object.keys(pkg.devDependencies)
const shouldBuildAll = argv.all || false
const shouldBuildWindows = argv.win || false
const shouldBuildOSX = argv.osx || false
const shouldBuildLinux = argv.linux || false
const shouldBuildCurrent = !shouldBuildAll && !shouldBuildLinux && !shouldBuildOSX && !shouldBuildWindows
const ignore = [
'^/archiveIndexes($|/)',
'^/archives2($|/)',
'^/.babelrc($|/)',
'^/node_modules/.cache($|/)',
'^/.babelrc2($|/)',
'^/.babelrc.bk($|/)',
'^/.gitattributes$',
'^/depDifWinRest.txt$',
'^/build($|/)',
'^/build-binary.js$',
'^/build-binary-old.js$',
'^/bundledApps/heritrix/heritrix_out.log$',
'^/bundledApps/heritrix/adhoc.keystore$',
'^/bundledApps/heritrix/heritrix.pid$',
'^/bundledApps/heritrix/jobs/',
'^/bundledApps/memgator($|/)',
'^/bundledApps/old($|/)',
'^/bundledApps/bk($|/)',
'^/bundledApps/openjdk($|/)',
'^/bundledApps/wailpy($|/)',
'^/bundledApps/tomcat($|/)',
'^/bundledApps/pywb_($|/)',
'^/.codeclimate.yml($|/)',
'^/crawler-beans_bk.cxml$',
'^/dev_coreData',
'^/coreData($|/)',
'^/doElectron.sh$',
'^/wail-core_old($|/)',
'^/bootstrap.sh$',
'^/npm-debug.log.*$',
'^/tests($|/)',
'^/chromDLogs($|/)',
'^/electron-main-dev.js$',
'^/.gitignore($|/)',
'^/.idea($|/)',
'^/images($|/)',
'^/memgators($|/)',
'^/newbinaries($|/)',
'^/README.md$',
'^/release($|/)',
'^/requirements.txt$',
'^/test($|/)',
'^/tools($|/)',
'^/waillogs($|/)',
'^/webpack.config.*$',
'^/webpackConfigs($|/)$',
'^/buildResources($|/)$',
'^/sharedUtil($|/)$',
'^/wail_utils($|/)$',
'^/wail-core_old($|/)$',
'^/wail-config($|/)$',
'^/bundledApps/pywb_old($|/)$',
'^/support($|/)$',
'^/temp($|/)$',
'^/yarn.lock$',
'^/zips($|/)'
].concat(devDeps.map(name => `/node_modules/${name}($|/)`))
.concat(
deps.filter(name => !electronCfg.externals.includes(name))
.filter(name => !cfgUI.externals.includes(name))
.map(name => `/node_modules/${name}($|/)`)
)
const DEFAULT_OPTS = {
appCopyright: 'Copyright © 2016-2017 Web Science And Digital Libraries Research Group ODU CS',
appVersion: pkg.version,
asar: false,
prune: true,
dir: cwd,
name: pkg.name,
ignore,
overwrite: true,
out: path.normalize(path.join(cwd, 'release')),
electronVersion: '1.8.1'
}
// OSX
const darwinSpecificOpts = {
'appBundleId': 'wsdl.cs.odu.edu.wail',
// The application category type, as shown in the Finder via 'View' -> 'Arrange by
// Application Category' when viewing the Applications directory (OS X only).
'appCategoryType': 'public.app-category.utilities',
// // The bundle identifier to use in the application helper's plist (OS X only).
'helperBundleId': 'wsdl.wail.cs.odu.edu-helper',
'extraResource': [darwinBuild.archiveIconPath, darwinBuild.iconPath],
// Application icon.
icon: darwinBuild.iconPath
}
const windowsSpecificOpts = {
win32metadata: {
// Company that produced the file.
CompanyName: 'wsdl.cs.odu.edu',
// Name of the program, displayed to users
FileDescription: pkg.name,
// Original name of the file, not including a path. This information enables an
// application to determine whether a file has been renamed by a user. The format of
// the name depends on the file system for which the file was created.
OriginalFilename: `${pkg.name}.exe`,
// Name of the product with which the file is distributed.
ProductName: pkg.name,
// Internal name of the file, if one exists, for example, a module name if the file
// is a dynamic-link library. If the file has no internal name, this string should be
// the original filename, without extension. This string is required.
InternalName: pkg.name
},
// Application icon.
icon: iconPath
}
const linuxSpecificOpts = {
icon: path.normalize(path.join(cwd, 'buildResources/linux/icon.png'))
}
function emptyRelease () {
return new Promise((resolve, reject) => {
fs.emptyDir(path.join(cwd, 'release'), error => {
if (error) {
reject(error)
} else {
resolve()
}
})
})
}
function build (cfg) {
return new Promise((resolve, reject) => {
webpack(cfg, (err, stats) => {
if (err) return reject(err)
resolve(stats)
})
})
}
function zipUp (inPath, outPath) {
return new Promise((resolve, reject) => {
zip.zip(inPath, outPath, (error) => {
if (error) {
reject(error)
} else {
resolve()
}
})
})
}
function packWindows (platform, arch) {
return new Promise((resolve, reject) => {
let opts = Object.assign({}, DEFAULT_OPTS, windowsSpecificOpts, {platform, arch})
packager(opts, (err) => {
if (err) {
reject(err)
} else {
resolve()
}
})
})
}
function packDarwin (platform, arch) {
return new Promise((resolve, reject) => {
let opts = Object.assign({}, DEFAULT_OPTS, darwinSpecificOpts, {platform, arch})
packager(opts, (err) => {
if (err) {
reject(err)
} else {
resolve()
}
})
})
}
function makeDMG (appPath) {
return new Promise((resolve, reject) => {
let _createDMG = require('electron-installer-dmg')
let out = path.join(cwd, 'release', 'wail-darwin-dmg')
fs.emptyDirSync(out)
let dmgOpts = {
appPath,
debug: true,
name: DEFAULT_OPTS.name,
icon: darwinSpecificOpts.icon,
overwrite: true,
out
}
_createDMG(dmgOpts, error => {
if (error) {
reject(error)
} else {
resolve()
}
})
})
}
function packLinux (platform, arch) {
return new Promise((resolve, reject) => {
let opts = Object.assign({}, DEFAULT_OPTS, linuxSpecificOpts, {platform, arch})
packager(opts, (err) => {
if (err) {
reject(err)
} else {
resolve()
}
})
})
}
async function darwinDoBuild (platform, arch) {
if (arch === 'ia32') return
console.log(`building the binary for ${platform}-${arch}`)
let packagedPath = path.join(cwd, 'release', `WAIL-${platform}-${arch}`)
let appPath = `${packagedPath}/WAIL.app`
let moveToPath = `${appPath}/Contents/Resources/app/bundledApps`
await packDarwin(platform, arch)
await moveThemP({arch: `${platform}${arch}`, to: moveToPath})
console.log('Building dmg')
await makeDMG(appPath)
console.log(`zipping up the release for ${platform}-${arch}`)
await zipUp(appPath, `${packagedPath}.zip`)
console.log(`${platform}-${arch} finished!`)
}
async function linuxDoBuild (platform, arch) {
console.log(`building the binary for ${platform}-${arch}`)
let packagedPath = path.join(cwd, `release/WAIL-${platform}-${arch}`)
let moveToPath = `${packagedPath}/resources/app/bundledApps`
await packLinux(platform, arch)
await moveThemP({arch: `${platform}${arch}`, to: moveToPath})
console.log(`zipping up the release for ${platform}-${arch}`)
await zipUp(packagedPath, `${packagedPath}.zip`)
console.log(`${platform}-${arch} finished!`)
}
async function windowsDoBuild (platform, arch) {
console.log(`building the binary for ${platform}-${arch}`)
let packagedPath = path.join(cwd, 'release', `WAIL-${platform}-${arch}`)
let moveToPath = path.join(packagedPath, 'resources', 'app', 'bundledApps')
await packWindows(platform, arch)
await moveThemP({arch: `${platform}${arch}`, to: moveToPath})
console.log(`zipping up the release for ${platform}-${arch}`)
await zipUp(packagedPath, `${packagedPath}.zip`)
console.log(`${platform}-${arch} finished!`)
}
async function buildForPlatArch (plats, archs) {
let i = 0
let plen = plats.length
let alen = archs.length
for (; i < plen; ++i) {
let plat = plats[i]
let j = 0
for (; j < alen; ++j) {
let arch = archs[j]
if (plat === 'darwin') {
await darwinDoBuild(plat, arch)
} else if (plat === 'linux') {
await linuxDoBuild(plat, arch)
} else {
await windowsDoBuild(plat, arch)
}
}
}
}
async function doBuild () {
console.log('Building WAIL')
console.log('Transpiling and Creating Single File WAIL-Electron-Main')
await build(electronCfg)
console.log('Transpiling and Creating Single File WAIL-UI')
await build(cfgUI)
console.log('Transpiling and Creating Single File WAIL-Core')
await build(cfgCore)
console.log('cleaning previous releases')
await emptyRelease()
if (shouldBuildCurrent) {
const thePlat = os.platform()
if (thePlat === 'darwin') {
await darwinDoBuild(thePlat, os.arch())
} else if (thePlat === 'linux') {
await linuxDoBuild(thePlat, os.arch())
} else {
await windowsDoBuild(thePlat, os.arch())
}
} else {
let archs
let platforms
if (shouldBuildAll) {
archs = ['ia32', 'x64']
platforms = ['linux', 'win32', 'darwin']
} else if (shouldBuildLinux) {
archs = ['ia32', 'x64']
platforms = ['linux']
} else if (shouldBuildOSX) {
archs = ['x64']
platforms = ['darwin']
} else {
archs = ['ia32', 'x64']
platforms = ['win32']
}
await buildForPlatArch(platforms, archs)
}
}
doBuild()
.then(() => {
console.log('done')
})
.catch(error => {
console.error('failed', error)
})