-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-release.js
377 lines (329 loc) · 13.1 KB
/
build-release.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
// this script builds the binaries and make packages for deliveries to various platforms/architects
import { execa } from 'execa'
import fs from 'fs-extra'
import path from 'path'
import archiver from 'archiver'
import { rimrafSync } from 'rimraf'
import commands from './commands/meta.js'
import replaceInFile from 'replace-in-file'
// check release channel, accepts either "dev" (default) or "stable"
let channel = 'dev'
if (process.argv[2] && process.argv[2] === 'stable') {
channel = 'stable'
}
console.log(`[releaser] will build release for the <${channel}> channel`)
const getPath = (...parts) => {
return path.resolve(process.cwd(), ...parts)
}
const config = fs.readJsonSync(getPath('neutralino.config.json'))
const appName = config.cli.binaryName
const applicationId = config.applicationId
const appVersion = process.env.CI_COMMIT_TAG
const startBuilding = async () => {
console.log(`[build] building and releasing started`)
}
const patchNeutralinoConfig = async () => {
// patches the config file to replace the placeholders with actual values that match the version and release channel
console.log(`[build] patching neutralino.config.json...`)
if (!appVersion) {
throw new Error('CI_COMMIT_TAG is not set, cannot determine version')
}
await replaceInFile({
files: 'neutralino.config.json',
from: '$CI_RELEASE_VERSION',
to: appVersion,
})
await replaceInFile({
files: 'neutralino.config.json',
from: '$CI_RELEASE_CHANNEL',
to: channel,
})
if (channel === 'stable') {
await replaceInFile({
files: ['neutralino.config.json', 'gui/index.html'],
from: 'osmflux-dev.png',
to: 'osmflux-stable.png',
})
}
}
const buildBaseApp = async () => {
console.log(`[build] building ${appName}...`)
const logs = await execa('yarn', ['build'])
console.log(logs.stdout)
if (logs.stderr) {
if (
!logs.stderr
.toString()
.includes(
`<script src="/__neutralino_globals.js"> in "/index.html" can't be bundled without type="module" attribute`,
)
) {
throw new Error(logs.stderr)
}
}
// add executing permission, in case more binaries would be used add them in this list to automatically fix permission for them too
// for now we only care about linux and darwin
for (const binary of [
`${appName}-linux_arm64`,
`${appName}-linux_x64`,
`${appName}-mac_arm64`,
`${appName}-mac_x64`,
]) {
fs.chmodSync(getPath('dist', appName, binary), 0o755)
}
}
const buildLinuxPackage = async () => {
console.log('[linux] building linux packages...')
const binaryNameArm = `${appName}-linux_arm64`
const binaryNameX64 = `${appName}-linux_x64`
// remove old app package
console.log('[linux] removing old packages...')
rimrafSync(getPath('dist', 'packages', 'linux'))
// create new app package structure
console.log('[linux] creating package structures...')
fs.mkdirpSync(getPath('dist', 'packages', 'linux', `${appName}-arm64`))
fs.mkdirpSync(getPath('dist', 'packages', 'linux', `${appName}-arm64`, 'commands'))
fs.mkdirpSync(getPath('dist', 'packages', 'linux', `${appName}-x64`))
fs.mkdirpSync(getPath('dist', 'packages', 'linux', `${appName}-x64`, 'commands'))
// copy the binary to app package
console.log('[linux] copying binary and resources...')
fs.copySync(
getPath('dist', appName, binaryNameArm),
getPath('dist', 'packages', 'linux', `${appName}-arm64`, appName),
)
fs.copySync(getPath('dist', appName, binaryNameX64), getPath('dist', 'packages', 'linux', `${appName}-x64`, appName))
// copy resources.neu to app package
fs.copySync(
getPath('dist', appName, 'resources.neu'),
getPath('dist', 'packages', 'linux', `${appName}-arm64`, 'resources.neu'),
)
fs.copySync(
getPath('dist', appName, 'resources.neu'),
getPath('dist', 'packages', 'linux', `${appName}-x64`, 'resources.neu'),
)
// copy commands into the app package
for (const cmd in commands) {
fs.copySync(
getPath('commands', cmd, 'linux', 'arm64', cmd),
getPath('dist', 'packages', 'linux', `${appName}-arm64`, 'commands', cmd),
)
fs.copySync(
getPath('commands', cmd, 'linux', 'x64', cmd),
getPath('dist', 'packages', 'linux', `${appName}-x64`, 'commands', cmd),
)
}
// copy osmosis
fs.copySync(
getPath('commands', 'osmosis'),
getPath('dist', 'packages', 'linux', `${appName}-arm64`, 'commands', 'osmosis'),
)
fs.copySync(
getPath('commands', 'osmosis'),
getPath('dist', 'packages', 'linux', `${appName}-x64`, 'commands', 'osmosis'),
)
console.log('[linux] packaging completed')
}
const buildWindowsPackage = async () => {
console.log('[windows] building windows packages...')
const binaryNameX64 = `${appName}-win_x64.exe`
// remove old app package
console.log('[windows] removing old packages...')
rimrafSync(getPath('dist', 'packages', 'windows'))
// create new app package structure
fs.mkdirpSync(getPath('dist', 'packages', 'windows', `${appName}-x64`))
fs.mkdirpSync(getPath('dist', 'packages', 'windows', `${appName}-x64`, 'commands'))
// copy the binary to app package
console.log('[windows] copying binary and resources...')
fs.copySync(
getPath('dist', appName, binaryNameX64),
getPath('dist', 'packages', 'windows', `${appName}-x64`, `${appName}.exe`),
)
// copy resources.neu to app package
fs.copySync(
getPath('dist', appName, 'resources.neu'),
getPath('dist', 'packages', 'windows', `${appName}-x64`, 'resources.neu'),
)
// copy commands into the app package
for (const cmd in commands) {
fs.copySync(
getPath('commands', cmd, 'windows', 'x64', `${cmd}.exe`),
getPath('dist', 'packages', 'windows', `${appName}-x64`, 'commands', `${cmd}.exe`),
)
}
// copy osmosis
fs.copySync(
getPath('commands', 'osmosis'),
getPath('dist', 'packages', 'windows', `${appName}-x64`, 'commands', 'osmosis'),
)
console.log('[windows] packaging completed')
}
const buildMacOSPackage = async () => {
console.log('[darwin] building darwin packages...')
const binaryNameArm = `${appName}-mac_arm64`
const binaryNameX64 = `${appName}-mac_x64`
const pkg = await fs.readJson(getPath('package.json'))
// remove old app package
console.log('[darwin] removing old packages...')
rimrafSync(getPath('dist', 'packages', 'darwin'))
// create new app package structure
console.log('[darwin] creating package structures...')
await fs.mkdirp(getPath('dist', 'packages', 'darwin', `${appName}-arm64.app`, 'Contents', 'MacOS'))
await fs.mkdirp(getPath('dist', 'packages', 'darwin', `${appName}-arm64.app`, 'Contents', 'Resources'))
await fs.mkdirp(getPath('dist', 'packages', 'darwin', `${appName}-arm64.app`, 'Contents', 'Resources', 'commands'))
await fs.mkdirp(getPath('dist', 'packages', 'darwin', `${appName}-x64.app`, 'Contents', 'MacOS'))
await fs.mkdirp(getPath('dist', 'packages', 'darwin', `${appName}-x64.app`, 'Contents', 'Resources'))
await fs.mkdirp(getPath('dist', 'packages', 'darwin', `${appName}-x64.app`, 'Contents', 'Resources', 'commands'))
// copy the binary to app package
console.log('[darwin] copying binary and resources...')
fs.copySync(
getPath('dist', appName, binaryNameArm),
getPath('dist', 'packages', 'darwin', `${appName}-arm64.app`, 'Contents', 'MacOS', appName),
)
fs.copySync(
getPath('dist', appName, binaryNameX64),
getPath('dist', 'packages', 'darwin', `${appName}-x64.app`, 'Contents', 'MacOS', appName),
)
// copy resources.neu to app package
fs.copySync(
getPath('dist', appName, 'resources.neu'),
getPath('dist', 'packages', 'darwin', `${appName}-arm64.app`, 'Contents', 'Resources', 'resources.neu'),
)
fs.copySync(
getPath('dist', appName, 'resources.neu'),
getPath('dist', 'packages', 'darwin', `${appName}-x64.app`, 'Contents', 'Resources', 'resources.neu'),
)
// copy commands into the app package
for (const cmd in commands) {
fs.copySync(
getPath('commands', cmd, 'darwin', 'arm64', cmd),
getPath('dist', 'packages', 'darwin', `${appName}-arm64.app`, 'Contents', 'Resources', 'commands', cmd),
)
fs.copySync(
getPath('commands', cmd, 'darwin', 'x64', cmd),
getPath('dist', 'packages', 'darwin', `${appName}-x64.app`, 'Contents', 'Resources', 'commands', cmd),
)
}
// copy osmosis
fs.copySync(
getPath('commands', 'osmosis'),
getPath('dist', 'packages', 'darwin', `${appName}-arm64.app`, 'Contents', 'Resources', 'commands', 'osmosis'),
)
fs.copySync(
getPath('commands', 'osmosis'),
getPath('dist', 'packages', 'darwin', `${appName}-x64.app`, 'Contents', 'Resources', 'commands', 'osmosis'),
)
console.log('[darwin] copying the icon...')
fs.copySync(
getPath('gui', 'public', `osmflux-${channel}.icns`),
getPath('dist', 'packages', 'darwin', `${appName}-arm64.app`, 'Contents', 'Resources', 'AppIcon.icns'),
)
fs.copySync(
getPath('gui', 'public', `osmflux-${channel}.icns`),
getPath('dist', 'packages', 'darwin', `${appName}-x64.app`, 'Contents', 'Resources', 'AppIcon.icns'),
)
// add starting script
console.log('[darwin] creating startup script...')
const startupScript = `#!/usr/bin/env bash
SCRIPT_DIR="$( cd -- "$( dirname -- "\${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
CONTENTS_DIR="$(dirname "$SCRIPT_DIR")"
exec "\${SCRIPT_DIR}/${appName}" --path="\${CONTENTS_DIR}/Resources"`
fs.writeFileSync(
getPath('dist', 'packages', 'darwin', `${appName}-arm64.app`, 'Contents', 'MacOS', 'parameterized'),
startupScript,
)
fs.writeFileSync(
getPath('dist', 'packages', 'darwin', `${appName}-x64.app`, 'Contents', 'MacOS', 'parameterized'),
startupScript,
)
// make sure executing permissions
fs.chmodSync(
getPath('dist', 'packages', 'darwin', `${appName}-arm64.app`, 'Contents', 'MacOS', 'parameterized'),
0o755,
)
fs.chmodSync(getPath('dist', 'packages', 'darwin', `${appName}-arm64.app`, 'Contents', 'MacOS', appName), 0o755)
fs.chmodSync(getPath('dist', 'packages', 'darwin', `${appName}-x64.app`, 'Contents', 'MacOS', 'parameterized'), 0o755)
fs.chmodSync(getPath('dist', 'packages', 'darwin', `${appName}-x64.app`, 'Contents', 'MacOS', appName), 0o755)
// create info.plist file
console.log('[darwin] creating info.plist...')
const infoPlist = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSHighResolutionCapable</key>
<true/>
<key>CFBundleExecutable</key>
<string>parameterized</string>
<key>CFBundleGetInfoString</key>
<string>${pkg.name}</string>
<key>CFBundleIconFile</key>
<string>AppIcon.icns</string>
<key>CFBundleIdentifier</key>
<string>${config.applicationId}</string>
<key>CFBundleName</key>
<string>${pkg.name}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>LSMinimumSystemVersion</key>
<string>10.13.0</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>`
fs.writeFileSync(getPath('dist', 'packages', 'darwin', `${appName}-arm64.app`, 'Contents', 'info.plist'), infoPlist)
fs.writeFileSync(getPath('dist', 'packages', 'darwin', `${appName}-x64.app`, 'Contents', 'info.plist'), infoPlist)
console.log('[darwin] packaging completed')
}
const createZipArchives = async () => {
console.log(`[archives] creating zipped archives...`)
rimrafSync(getPath('dist', 'archives'))
fs.mkdirpSync(getPath('dist', 'archives'))
const targets = [
['darwin', 'x64.app', `${appName}.app`],
['darwin', 'arm64.app', `${appName}.app`],
['linux', 'x64', false],
['linux', 'arm64', false],
['windows', 'x64', false],
]
for (const [platform, architecture, destPath] of targets) {
console.log(`[archives] archiving target ${platform}-${architecture}...`)
const output = fs.createWriteStream(getPath('dist', 'archives', `${appName}-${platform}-${architecture}.zip`))
const archive = archiver('zip')
output.on('close', () =>
console.log(`[archives] target ${platform}-${architecture} has written ${archive.pointer()} bytes in total`),
)
archive.on('error', (err) => {
throw err
})
archive.pipe(output)
archive.directory(getPath('dist', 'packages', platform, `${appName}-${architecture}`), destPath)
await archive.finalize()
}
console.log(`[archives] archiving completed`)
}
const generateUpdateManifest = async () => {
const manifest = {
applicationId: applicationId,
version: appVersion,
resourcesURL: `https://static.mogita.com/osmflux/releases/${channel}/latest/resources.neu`,
data: {
commands,
},
}
fs.writeFileSync(getPath('dist', 'update_manifest.json'), JSON.stringify(manifest))
}
const catchAndExit = (err) => {
console.error(err)
process.exit(1)
}
startBuilding()
.then(patchNeutralinoConfig)
.then(buildBaseApp)
.then(buildLinuxPackage)
.then(buildMacOSPackage)
.then(buildWindowsPackage)
.then(createZipArchives)
.then(generateUpdateManifest)
.catch(catchAndExit)