-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
package.ts
146 lines (128 loc) · 3.82 KB
/
package.ts
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
import * as builder from 'electron-builder'
import * as fs from 'fs'
import * as path from 'path'
import * as dotProp from 'dot-prop'
const linuxAppImage: builder.CliOptions = {
x64: true,
ia32: false,
armv7l: true,
arm64: true,
projectDir: './build/clean',
publish: 'always',
}
const linuxSnap: builder.CliOptions = {
x64: true,
ia32: false,
armv7l: false, // not supported to build on x64
arm64: false, // not supported to build on x64
projectDir: './build/clean',
publish: 'always',
}
const linuxDeb: builder.CliOptions = {
x64: true,
ia32: false,
armv7l: true,
arm64: true,
projectDir: './build/clean',
publish: 'always',
}
const winPortable: builder.CliOptions = {
x64: true,
ia32: false,
armv7l: false,
arm64: false,
projectDir: './build/clean',
publish: 'always',
}
const winNsis: builder.CliOptions = {
x64: true,
ia32: false,
armv7l: false,
arm64: false,
projectDir: './build/clean',
publish: 'always',
}
const winAppx: builder.CliOptions = {
x64: true,
ia32: false,
armv7l: false,
arm64: false,
projectDir: './build/clean',
publish: 'onTag',
}
const mac: builder.CliOptions = {
x64: true,
ia32: false,
armv7l: false,
arm64: true,
projectDir: './build/clean',
publish: 'always',
}
async function executeBuild() {
switch (process.argv[2]) {
case 'win':
await buildWithOptions(winPortable, { platform: 'win', package: 'portable' })
await buildWithOptions(winNsis, { platform: 'win', package: 'nsis' })
break
case 'appx':
await buildWithOptions(winAppx, { platform: 'win', package: 'appx' })
break
case 'linux':
await buildWithOptions(linuxAppImage, { platform: 'linux', package: 'AppImage' })
await buildWithOptions(linuxSnap, { platform: 'linux', package: 'snap' })
await buildWithOptions(linuxDeb, { platform: 'linux', package: 'deb' })
break
case 'mac':
await buildWithOptions(mac, { platform: 'mac', package: 'dmg' })
// await buildWithOptions(mac, { platform: 'mac', package: 'mas' })
// await buildWithOptions(mac, { platform: 'mac', package: 'zip' })
break
default:
await buildWithOptions({ ...mac, projectDir: '' }, { platform: 'mac', package: 'mas-dev' })
}
}
export interface BuildInfo {
platform: 'win' | 'linux' | 'mac'
package: Packages
}
type Packages = 'portable' | 'nsis' | 'appx' | 'AppImage' | 'snap' | 'dmg' | 'zip' | 'mas' | 'mas-dev' | 'deb'
async function buildWithOptions(options: builder.CliOptions, buildInfo: BuildInfo) {
fs.writeFileSync(path.join(options.projectDir!, 'buildOptions.json'), JSON.stringify(buildInfo))
const jsonLocation = path.join(options.projectDir as string, 'package.json')
const packageJsonStr = fs.readFileSync(jsonLocation).toString()
const packageJson = JSON.parse(fs.readFileSync(jsonLocation).toString())
// AppX must have a different name since the store name is already taken (but not used)
if (buildInfo.package === 'appx') {
dotProp.set(packageJson, 'build.productName', 'MQTT-Explorer')
}
if (buildInfo.platform === 'mac') {
console.log(buildInfo.package)
const provisioningProfile =
buildInfo.package === 'mas'
? 'res/MQTT_Explorer_Store_Distribution_Profile.provisionprofile'
: 'res/MQTTExplorerdmg.provisionprofile'
dotProp.set(packageJson, 'build.mac.provisioningProfile', provisioningProfile)
}
try {
// Write modified package.json
fs.writeFileSync(jsonLocation, JSON.stringify(packageJson))
await builder.build({
...options,
[buildInfo.platform]: [buildInfo.package],
})
} catch (error) {
throw error
} finally {
// Roll back changes to package.json
fs.writeFileSync(jsonLocation, packageJsonStr)
}
}
function build() {
try {
executeBuild()
} catch (error) {
console.error(error)
process.exit(1)
}
}
build()