-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.js
114 lines (98 loc) · 2.62 KB
/
start.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
let util = require('util');
let exec = require('child_process').exec;
let spawn = require('child_process').spawn;
let process = require('process');
let fs = require('fs');
let vars = require('./vars.json');
function run(command, args, output = null, cwd = undefined, env = undefined) {
return new Promise((resolve, reject) => {
let stdio =
output == 'stream'
? ['ignore', process.stdout, process.stderr]
: output == 'buffer'
? ['ignore', 'pipe', 'pipe']
: 'ignore';
let options = {
shell: true,
stdio: stdio,
cwd: cwd,
env: env
};
let proc = spawn(command, args, options);
if (output == 'buffer') {
let stdout = '';
let stderr = '';
proc.stdout.on('data', data => {
stdout += data.toString();
});
proc.stderr.on('data', data => {
stderr += data.toString();
});
proc.on('close', exit => {
resolve({ exit: exit, stdout: stdout, stderr: stderr });
});
} else {
proc.on('close', exit => {
resolve({ exit: exit });
});
}
});
}
function important(s) {
return `\x1b[30;46m${s}\x1b[0m`;
}
async function main() {
// check if node_modules exists
if (!fs.existsSync(`${vars.source_dir}/node_modules`)) {
console.log(important("• node_modules not present; npm install'ing!"));
await run('npm', ['install'], 'stream');
}
// cleanup server directory
console.log(
important('• cleaning server directory and creating new structure')
);
await run('cmd', [
'/C',
`rmdir ${vars.server_dir} /S /Q & ` +
`mkdir ${vars.server_dir}/resources/${vars.resource_name}/ & ` +
`mklink /J ${vars.server_dir}/resources/${
vars.resource_name
}/node_modules ${vars.source_dir}/node_modules`
]);
// copy files
console.log(important('• copying static files'));
await Promise.all(
[
`robocopy ${vars.source_dir}/client ${vars.server_dir}/resources/${
vars.resource_name
}/client /S`,
`robocopy ${vars.altv_dir} ${vars.server_dir} /S`,
`copy ${vars.source_dir}/resource.cfg ${vars.server_dir}/resources/${
vars.resource_name
} `
].map(copy => run('cmd', ['/C', copy]))
);
// build typescript
console.log(important('• building typescript'));
let build_server = run(
'npx',
[
'tsc',
'--pretty',
`-p ${vars.source_dir}/server/tsconfig.json`,
`--outDir ${vars.server_dir}/resources/${vars.resource_name}/server`
],
'stream'
);
await build_server;
// change port in config
// launch server
console.log(important('• launching server'));
await run(
`chmod +x ${vars.server_dir}/start.sh && chmod +x ${vars.server_dir}/altv-server && sudo ${vars.server_dir}/start.sh`,
[],
'stream',
vars.server_dir
);
}
main();