forked from ineedbots/iw3_bot_warfare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
51 lines (40 loc) · 1.38 KB
/
deploy.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
// nodejs 14+
const exec = require('util').promisify(require('child_process').exec)
const repo_name = 'cod4x_bot_warfare'
const repo_url = `https://github.com/ineedbots/${repo_name}`
const deploy_check_rate = 60000
const title = 'CoD4x Bot Warfare Git Deployer'
function printToConsole(what, error = false)
{
log = error ? console.error : console.log
log(`[${new Date().toISOString()}]:`, what)
}
async function doDeploy() {
try {
const { stdout, stderr } = await exec(`cd ${repo_name} && git fetch`)
if (stderr.length <= 0)
return
if (stderr.startsWith('From '))
{
printToConsole('git fetched! Pulling...')
await exec(`cd ${repo_name} && git pull && git submodule update --init --recursive`)
printToConsole('Deploying...')
await exec('deploy.bat')
printToConsole('Deployed!')
}
} catch (e) {
printToConsole(e, true)
if (!e.stderr.startsWith('The system cannot find the path specified'))
return
printToConsole('Cloning repo...')
try {
await exec(`git clone ${repo_url} && cd ${repo_name} && git submodule update --init --recursive`)
printToConsole('Cloned!')
} catch (f) {
printToConsole(f, true)
}
}
}
process.stdout.write(`${String.fromCharCode(27)}]0;${title}${String.fromCharCode(7)}`)
doDeploy()
setInterval(doDeploy, deploy_check_rate)