-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunGame.ts
50 lines (40 loc) · 1.26 KB
/
runGame.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
import { fork, spawn } from "child_process";
import * as fs from "fs-extra";
import * as path from "path";
import * as utils from "./utils";
function escape(s: string): string {
return s.replace(/[\\$'"]/g, "\\$&");
}
(async () => {
const projectConfig = utils.fetchProjectConfig();
if (projectConfig.fsGameDir === undefined) {
console.error(`"fsGameDir" is missing from config.json`)
return;
}
if (projectConfig.fsGameBin === undefined) {
console.error(`"fsGameBin" is missing from config.json`)
return;
}
if (projectConfig.launchOptions === undefined) {
projectConfig.launchOptions = new Array<string>();
}
const baseDir = path.resolve(__dirname, "..");
const gamePath = path.resolve(projectConfig.fsGameDir, projectConfig.fsGameBin);
const gameParams = projectConfig.launchOptions.join(" ");
console.log("Launching game...");
const game = spawn(
`Start '${escape(gamePath)}' -ArgumentList '${escape(gameParams)}' -Verb RunAs`,
{
"shell": "powershell.exe",
}
);
game.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
game.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
})
game.on('close', (code) => {
console.log(`Game exited with code: ${code}`);
});
})();