forked from yafyz/nitrsnip_deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
51 lines (44 loc) · 1.37 KB
/
main.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
const giturl = "https://github.com/yafyz/nitrsnip";
const fs = require("fs");
const chp = require("child_process");
var child = null;
function execasync(cmd) {
return new Promise((res, rej)=>{
chp.exec(cmd, (err, stdout, _)=>{
if (err)
return rej(err);
res(stdout);
})
});
}
function fork_child() {
child = chp.fork("src/main.js");
child.on("exit", ()=>{
console.log("Child has exited, restarting");
fork_child();
});
}
(async ()=>{
if (process.env.is_heroku != undefined)
await execasync("ln /app/.apt/usr/bin/x86_64-linux-gnu-g++-10 /app/.apt/usr/bin/g++");
if (!fs.existsSync("src")) {
console.log("Cloning...");
await execasync(`git clone ${giturl} src`);
console.log("Installing dependencies");
await execasync("cd src && npm install");
}
setInterval(async ()=>{
let ret = await execasync("cd src && git pull");
if (ret.trim() == "Already up to date.")
console.log("Repo is up to date");
else {
console.log("Pulled new commits")
console.log(ret);
console.log("Installing dependencies");
await execasync("cd src && npm install");
console.log("Restarting nitrsnip");
child.kill();
}
}, 60000)
fork_child();
})();