-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile.ts
91 lines (79 loc) · 2.76 KB
/
compile.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
/*
* Copyright (c) 2023-2024, NeKz
*
* SPDX-License-Identifier: MIT
*/
import { join } from 'https://deno.land/std@0.192.0/path/mod.ts';
import { Command } from 'https://deno.land/x/cliffy@v1.0.0-rc.2/command/mod.ts';
import { colors } from 'https://deno.land/x/cliffy@v1.0.0-rc.2/ansi/colors.ts';
const devHostname = 'autorender.portal2.local';
type SupportedTarget = {
target: string;
binaryName: string;
steamappsDir?: string;
};
const supportedTargets: Record<string, SupportedTarget> = {
linux: {
target: 'x86_64-unknown-linux-gnu',
binaryName: 'autorenderclient',
},
windows: {
target: 'x86_64-pc-windows-msvc',
binaryName: 'autorenderclient.exe',
steamappsDir: 'C:\\\\Program Files (x86)\\\\Steam\\\\steamapps',
},
};
export const supportedGames: Record<string, { sourcemod: boolean }> = {
'Portal 2': { sourcemod: false },
'Aperture Tag': { sourcemod: false },
'Thinking with Time Machine': { sourcemod: false },
'Portal Stories Mel': { sourcemod: false },
// 'Portal 2 Community Edition': { sourcemod: false },
'Portal Reloaded': { sourcemod: false },
'Portal 2 Speedrun Mod': { sourcemod: true },
};
const getCompilationOptions = (os: string) => {
const target = supportedTargets[os];
if (!target) {
console.log(colors.red('Operating system not supported'));
Deno.exit(1);
}
return target;
};
const main = async () => {
await new Command()
.name('autorender-compile-tool')
.version('1.0.0')
.description('Command line tool for compiling the autorender client.')
.option('--os <linux|windows>', 'The operating system for this to be compiled to.')
.option('--all', 'Compile for all supported operating systems.')
.option('--release', 'Compile without developer flags.')
.action(async ({ os, all, release }) => {
const systems = all ? ['linux', 'windows'] : [os ?? Deno.build.os];
for (const os of systems) {
const { target, binaryName, steamappsDir } = getCompilationOptions(os);
const developerFlags = release ? '' : `--unsafely-ignore-certificate-errors=${devHostname}`;
const env = {
COMPILATION_TARGET: target,
COMPILATION_BINARY_NAME: binaryName,
COMPILATION_DEVELOPER_FLAGS: developerFlags,
COMPILATION_READ_WRITE_GAME_PATHS: steamappsDir
? ',' + Object.entries(supportedGames)
.map(([gameName, { sourcemod }]) => join(steamappsDir, sourcemod ? 'sourcemods' : 'common', gameName!))
.join(',')
: '',
};
const args = [
'task',
'--cwd',
'src/client',
'compile',
];
await new Deno.Command('deno', { env, args })
.spawn()
.output();
}
})
.parse(Deno.args);
};
await main();