-
Notifications
You must be signed in to change notification settings - Fork 36
/
release.js
74 lines (62 loc) · 2.27 KB
/
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
// https://github.com/nexe/nexe/issues/702#issuecomment-570746426
const { compile } = require('nexe');
const { resolve } = require('path');
const rcedit = require('rcedit');
const fs = require('fs');
const bufferpack = require('bufferpack');
const package = require('./package.json');
const rc = {
CompanyName: 'pkfln',
ProductName: package.name,
FileDescription: package.description,
FileVersion: package.version,
ProductVersion: package.version,
OriginalFilename: `${package.name}.exe`,
InternalName: package.name,
LegalCopyright: 'Copyright pkfln 2021. MIT license.',
};
(async () => {
try {
const output = resolve(__dirname, './target/mta-discord-rpc.exe');
await compile({
input: resolve(__dirname, './build/src/main.js'),
output,
build: true,
rc,
ico: resolve(__dirname, './mtasa.ico'),
resources: ['./node_modules/gamedig/games.txt', './node_modules/gamedig/protocols/ase.js'],
verbose: true,
target: 'windows-x86-12.18.2',
name: package.name,
patches: [
async (compiler, next) => {
const exePath = compiler.getNodeExecutableLocation();
if ((await fs.promises.stat(exePath)).size > 0) {
await rcedit(exePath, {
'version-string': rc,
'file-version': package.version,
'product-version': package.version,
icon: resolve(__dirname, './mtasa.ico'),
});
}
return next();
},
],
});
// Patch CLI from showing up
const outputHandle = await fs.promises.open(output, 'r+');
const read = async (position, size) => {
const buffer = Buffer.alloc(size);
await outputHandle.read(buffer, 0, size, position);
return buffer;
};
const write = async (position, buffer) => await outputHandle.write(buffer, 0, buffer.length, position);
const [PeHeaderOffset] = Array.from(bufferpack.unpack('<H', await read(0x3c, 2)));
const [PeSignature] = Array.from(bufferpack.unpack('<I', await read(PeHeaderOffset, 4)));
if (PeSignature !== 0x4550) throw new Error('File is missing PE header signature.');
await write(PeHeaderOffset + 0x5c, bufferpack.pack('<H', [0x2]));
await outputHandle.close();
} catch (e) {
console.error(e);
}
})();