index.js
1.22 KB
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
var express = require('express');
var router = express.Router();
var exec = require('child_process').exec;
var projects = {};
router.post('/:name', function(req, res, next) {
proc(req,res);
});
/**
* 处理刷新和重启服务
* @param {String} name 服务目录
* @param {Object} req 请求
* @param {Object} res 响应
*/
function proc(req,res) {
var cliArr = [
"cd /Data/code/test/"+req.params.name+"/client/",
"git pull",
"gulp",
"cd /Data/code/test/"+req.params.name+"/",
"make start"
];
console.log(req.body);
if(req.body.ref.indexOf('release')<0) {
res.json({"code":200,"message":"not release,do nothing!"});
return;
}
if(projects[req.params.name].hash === req.body.after) {
res.json({"code":200,"message":"same commits , do nothing!"});
return;
}
//设置当前项目的commits的hash
projects[req.params.name].hash = req.body.after;
//执行命令
exec(cliArr.join(' && '),function(err,out,outerr) {
if(err) {
console.log(err);
console.log(outerr);
res.json({"code":500,"message": err.message});
} else {
console.log(out);
res.json({"code":200,"message":"done!"});
}
});
}
module.exports = router;