-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
package.js
162 lines (132 loc) · 4.23 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
const { spawnSync } = require('child_process');
const { Builder } = require('./build');
const builder = new Builder();
// Define input and output directories
const path = (directory) => {
return require('path').resolve(__dirname, directory);
};
/**
* @namespace Packager
* @description - Packages app for various operating systems.
*/
class Packager {
/**
* @description - Creates DEB installer for linux.
* @memberof Packager
*
* @tutorial https://github.com/electron-userland/electron-installer-debian
*/
packageLinux = () => {
// Build Python & React distribution files
builder.buildAll();
const options = {
build: [
'app',
'--extra-resource=./resources',
'--icon ./public/favicon.ico',
'--platform linux',
'--arch x64',
'--out',
'./dist/linux',
'--overwrite'
].join(' '),
package: [
`--src ${path('../dist/linux/app-linux-x64/')}`,
'electron-react-python-template',
`--dest ${path('../dist/linux/setup')}`,
'--arch amd64',
`--icon ${path('../utilities/deb/images/icon.ico')}`,
`--background ${path('../utilities/deb/images/background.png')}`,
'--title "Example app"',
'--overwrite'
].join(' '),
spawn: { detached: false, shell: true, stdio: 'inherit' }
};
spawnSync(`electron-packager . ${options.build}`, options.spawn);
spawnSync(`electron-installer-debian ${options.package}`, options.spawn);
};
/**
* @description - Creates DMG installer for macOS.
* @memberof Packager
*
* @tutorial https://github.com/electron-userland/electron-installer-dmg
*/
packageMacOS = () => {
// Build Python & React distribution files
builder.buildAll();
const options = {
build: [
'app',
'--extra-resource=./resources',
'--icon ./public/favicon.ico',
'--win32',
'--out',
'./dist/mac',
'--overwrite'
].join(' '),
package: [
path('../dist/mac/app-darwin-x64/app.app'),
'electron-react-python-template',
`--out=${path('../dist/mac/setup')}`,
`--icon=${path('../utilities/dmg/images/icon.icns')}`,
`--background=${path('../utilities/dmg/images/background.png')}`,
'--title="Example app"',
'--overwrite'
].join(' '),
spawn: { detached: false, shell: true, stdio: 'inherit' }
};
spawnSync(`electron-packager . ${options.build}`, options.spawn);
spawnSync(`electron-installer-dmg ${options.package}`, options.spawn);
};
/**
* @description - Creates MSI installer for Windows.
* @memberof Packager
*
* @tutorial https://github.com/felixrieseberg/electron-wix-msi
*/
packageWindows = () => {
// eslint-disable-next-line no-console
console.log('Building windows package...');
// Build Python & React distribution files
builder.buildAll();
const options = {
app: [
'app',
'--asar',
'--extra-resource=./resources/app',
'--icon ./public/favicon.ico',
'--win32',
'--out',
'./dist/windows',
'--overwrite'
].join(' '),
spawn: { detached: false, shell: true, stdio: 'inherit' }
};
spawnSync(`electron-packager . ${options.app}`, options.spawn);
const { MSICreator } = require('electron-wix-msi');
const msiCreator = new MSICreator({
appDirectory: path('../dist/windows/app-win32-x64'),
appIconPath: path('../utilities/msi/images/icon.ico'),
description: 'Example app',
exe: 'app',
manufacturer: 'Example Manufacturer',
name: 'electron-react-python-template',
outputDirectory: path('../dist/windows/setup'),
ui: {
chooseDirectory: true,
images: {
background: path('../utilities/msi/images/background.png'),
banner: path('../utilities/msi/images/banner.png')
}
},
version: '1.0.0'
});
// Customized MSI template
msiCreator.wixTemplate = msiCreator.wixTemplate
.replace(/ \(Machine - MSI\)/gi, '')
.replace(/ \(Machine\)/gi, '');
// Create .wxs template and compile MSI
msiCreator.create().then(() => msiCreator.compile());
};
}
module.exports.Packager = Packager;