forked from timche/docker-csgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade-mods.ts
76 lines (64 loc) · 2.15 KB
/
upgrade-mods.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
import fs from "fs/promises";
import path from "path";
import got from "got";
import execa from "execa";
const serverSourceModPath = path.resolve(
__dirname,
"sourcemod",
"server_sourcemod.sh"
);
async function upgradeMod(
mod: string,
downloadPageUrl: string,
versionBuildNumberRegExp: RegExp,
versionReplaceRegExp: RegExp,
buildNumberReplaceRegExp: RegExp
) {
const serverSourceModFile = await fs.readFile(serverSourceModPath, "utf-8");
const { body } = await got(downloadPageUrl);
const match = body.match(versionBuildNumberRegExp);
if (match) {
const [_, version, buildNumber] = match;
let changedServerSourceModFile = serverSourceModFile.replace(
versionReplaceRegExp,
`$1${version}$2`
);
changedServerSourceModFile = serverSourceModFile.replace(
buildNumberReplaceRegExp,
`$1${buildNumber}$2`
);
if (serverSourceModFile === changedServerSourceModFile) {
console.log(`no upgrade available for ${mod}`);
} else {
const commitMessage = `upgrade ${mod} to version ${version} build ${buildNumber}`;
await fs.writeFile(serverSourceModPath, changedServerSourceModFile);
if (process.env.CI === "true") {
await execa("git", ["commit", "-am", commitMessage]);
await execa("git", ["push"]);
}
console.log(commitMessage);
}
}
}
async function upgradeMods() {
try {
await upgradeMod(
"sourcemod",
"https://www.sourcemod.net/downloads.php?branch=stable",
/<a class='quick-download download-link' href='https:\/\/sm\.alliedmods\.net\/smdrop\/\d+.\d+\/sourcemod-(\d+.\d+.\d+)-git(\d+)-linux\.tar.gz'>/,
/(\${SOURCEMOD_VERSION-")\d+\.\d+.\d+("}")/,
/(\${SOURCEMOD_BUILD-)\d+(})/
);
await upgradeMod(
"metamod",
"https://www.sourcemm.net/downloads.php?branch=stable",
/<a class='quick-download download-link' href='https:\/\/mms\.alliedmods\.net\/mmsdrop\/\d+.\d+\/mmsource-(\d+.\d+.\d+)-git(\d+)-linux\.tar.gz'>/,
/(\${METAMOD_VERSION-")\d+\.\d+.\d+("}")/,
/(\${METAMOD_BUILD-)\d+(})/
);
} catch (error) {
console.error(error?.message);
process.exit(1);
}
}
upgradeMods();