-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgitserver.js
49 lines (36 loc) · 1.12 KB
/
gitserver.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
'use strict';
var http = require('http');
var express = require('express');
var app = express();
const { spawn } = require('child_process')
var server = http.createServer(app).listen(9877);
let shell = null;
console.log('Starting home-assistant gitwatcher\n\n\n');
app.route('/git').post( (req, res) => {
res.status(200);
console.log('git push detected...');
if (shell !== null) {
console.log('server currently running, attempting to kil...');
try {
shell.kill();
console.log('server process killed successfully!');
} catch (err) {
console.log('error killing process, aborting...');
process.exit(1);
}
}
console.log()
shell = spawn('npm', ['run', 'rebase'], {
shell: true
});
shell.on('exit', function (code, signal) {
console.log(`server.js exited with code ${code} and signal ${signal}`);
});
shell.stdout.on('data', (data) => {
console.log(`child stdout:\n${data}`);
});
shell.on('error', function (err) {
console.log(err);
})
//process.stdin.pipe(shell.stdin)
});