-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
83 lines (76 loc) · 1.71 KB
/
deploy.js
File metadata and controls
83 lines (76 loc) · 1.71 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* @type {array} 命令行输入命令数组
*/
var argv = process.argv;
let fs = require('fs');
let EventEmitter = require('events').EventEmitter;
let event = new EventEmitter();
/**
* @type {Array} 获取命令行输入参数
*/
let com = argv.splice(2);
var doex = require('child_process').exec;
/**
* @type {Array} 事件队列
*/
let eventList = [];
/**
* @type {Boolean} 事件执行标志
*/
let hasEventDo = false;
if(com.toString()){
com.forEach(function (str){
eventList.push(str);
})
}else{
['hexo clean', 'hexo generate', 'gulp', 'hexo deploy'].forEach(
function(str){
eventList.push(str);
}
)
}
event.emit('exec');
/**
* 执行命令行
* @param {string} com 执行的命令参数
*/
function exec (com){
hasEventDo = true;
doex(com, function(err,stdout,stderr){
if(err) {
log('! has some error:'+stderr);
} else {
log(stdout);
hasEventDo = false;
event.emit('exec');
}
});
}
/**
* 将数据打印到控制台
* @param {*} str 打印数据
*/
function log() {
console.log.apply(null, arguments);
}
// log(process);
event.on('exec', function(delayNnm = 0) {
if(hasEventDo){
// 如果已有事物执行则延迟五秒
if(delayNum > 1){
// 已循环一次后则认为有问题,结束调用
log("已有事件占用太长时间");
return -1;
}
setTimeout(function(){
event.emit('exec', delayNum++);
},5000);
}
if(eventList.length){
let eventName = eventList.shift();
exec(eventName);
return;
} else {
log("exec EventList is empty");
}
});