-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (26 loc) · 746 Bytes
/
server.js
File metadata and controls
30 lines (26 loc) · 746 Bytes
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
const fs = require('fs')
const { exec, spawn } = require('child_process')
exec('git pull && npm install', (_, stdout, __) => { // Install dependencies
console.log('Watching for file changes')
let GithubTimeout = null
function Watch() {
const watcher = fs.watch('./', (evt, file) => {
if (!file.endsWith('.json')) return
watcher.close()
console.log('File changed:', file)
clearTimeout(GithubTimeout)
if (GithubTimeout) clearTimeout(GithubTimeout)
GithubTimeout = setTimeout(() => {
UpdateGithub()
}, 5000)
setTimeout(Watch, 500)
})
}
function UpdateGithub() {
const cmd = 'git add . && git commit -m "Auto Update" && git push'
exec(cmd, (_, stdout, __) => {
console.log(stdout)
})
}
Watch()
})