Repository navigation
Expand file tree
/
Copy pathcommon.js
More file actions
65 lines (55 loc) · 1.39 KB
/
Copy pathcommon.js
File metadata and controls
65 lines (55 loc) · 1.39 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
var files = require("dir-to-files");
var Util = {
trim:function(string){
return string.replace(/(^\s*)|(\s*$)/g,'');
},
getTemplate:function(currutDir){
var filePaths = files.geFileList(currutDir);
var tmp = [];
for(var i in filePaths){
var regExp = new RegExp(currutDir+"/(.+)");
tmp.push(regExp.exec(filePaths[i].path)[1]);
}
return tmp;
},
execCommand:function(_this,commands){
_this.i = 0;
var unit = function(){
var command = commands[_this.i];
var pos = command.search(/\s/);
var cmd = command,
args = [];
var spawnHanlder = function(code) {
if(code){
_this.done(new Error('code:'+code));
}else{
_this.i++;
if(_this.i < commands.length){
unit();
}else{
_this.done();
}
}
}
if(pos > -1){
cmd = Util.trim(command.substring(0,pos));
args = Util.trim(command.substr(pos)).split(/\s+/);
}
var spawn = _this.spawnCommand(cmd,args);
spawn.on('exit',spawnHanlder);
spawn.on('error',_this.done);
}
unit();
},
copy:function(_this,arr){
var regExp = /json/;
for(var i=0;i<arr.length;i++){
if(arr[i].match(regExp)){
_this.template(arr[i],arr[i]);
}else{
_this.copy(arr[i],arr[i]);
}
}
}
};
module.exports = Util;