-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.js
executable file
·113 lines (99 loc) · 2.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
/* eslint-disable import/no-extraneous-dependencies */
const os = require('os')
const webpack = require('webpack')
const packager = require('electron-packager')
const assign = require('object-assign')
const del = require('del')
const argv = require('minimist')(process.argv.slice(2))
const cfg = require('./webpack.config.production.js')
const devDeps = Object.keys(require('./package.json').devDependencies)
/* eslint-enable */
const appName = argv.name || argv.n || 'TodoX'
const shouldUseAsar = argv.asar || argv.a || true
const shouldBuildAll = argv.all || false
const DEFAULT_OPTS = {
dir: './',
name: appName,
win32metadata: {
FileDescription: appName,
ProductName: appName
},
asar: shouldUseAsar,
packageManager: false,
prune: false,
ignore: [
'/.vscode',
'/README.md',
'/server.js',
'/webpack.*',
'/app/mainApp.jsx',
'/app/containers($|/)',
'/app/assets/style($|/)',
'/build($|/)',
'/test($|/)',
'/tools($|/)',
'/release($|/)'
].concat(devDeps.map(name => '/node_modules/' + name + '($|/)'))
}
const icon = argv.icon || argv.i || 'build/icon'
if (icon) {
DEFAULT_OPTS.icon = icon
}
const version = argv.version || argv.v || '1.0.0'
DEFAULT_OPTS.version = version
startPack()
function startPack() {
console.log('start pack...')
// pack(os.platform(), os.arch(), log(os.platform(), os.arch()));return
webpack(cfg, (err, /* stats */) => {
if (err) return console.error(err)
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((err2) => {
console.error(err2)
})
})
}
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 = assign({}, DEFAULT_OPTS, iconObj, {
platform: plat,
arch,
out: 'release/' + plat + '-' + arch
})
packager(opts, cb)
}
function log(plat, arch) {
return (err, /* filepath */) => {
if (err) return console.error(err)
console.log(plat + '-' + arch + ' finished!')
}
}