-
-
Notifications
You must be signed in to change notification settings - Fork 284
/
package.ts
116 lines (102 loc) · 3 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
import * as builder from 'electron-builder'
import * as fs from 'fs'
import * as path from 'path'
const linuxAppImage: builder.CliOptions = {
x64: true,
ia32: true,
armv7l: true,
arm64: false,
projectDir: './build/clean',
publish: 'always',
}
const linuxSnap: builder.CliOptions = {
x64: true,
ia32: false,
armv7l: false,
arm64: false,
projectDir: './build/clean',
publish: 'always',
}
const winPortable: builder.CliOptions = {
x64: true,
ia32: true,
armv7l: false,
arm64: false,
projectDir: './build/clean',
publish: 'always',
}
const winNsis: builder.CliOptions = {
x64: true,
ia32: true,
armv7l: false,
arm64: false,
projectDir: './build/clean',
publish: 'always',
}
const winAppx: builder.CliOptions = {
x64: true,
ia32: true,
armv7l: false,
arm64: false,
projectDir: './build/clean',
publish: 'onTag',
}
const mac: builder.CliOptions = {
x64: true,
ia32: true,
armv7l: false,
arm64: false,
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' })
break
case 'mac':
await buildWithOptions(mac, { platform: 'mac', package: 'mas' })
await buildWithOptions(mac, { platform: 'mac', package: 'dmg' })
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))
ensureAppNameForPackage(options, buildInfo.package)
await builder.build({
...options,
[buildInfo.platform]: [buildInfo.package],
})
}
// AppX must hav a different name since the store name is already taken (but not used)
function ensureAppNameForPackage(options: builder.CliOptions, packageOption: Packages) {
const jsonLocation = path.join((options.projectDir as string), 'package.json')
const packageJson = JSON.parse(fs.readFileSync(jsonLocation).toString())
packageJson.build.productName = packageOption === 'appx' ? 'MQTT-Explorer' : 'MQTT Explorer'
fs.writeFileSync(jsonLocation, JSON.stringify(packageJson, undefined, ' '))
}
function build() {
try {
executeBuild()
} catch (error) {
console.error(error)
process.exit(1)
}
}
build()