@@ -12,19 +12,20 @@ var processFile = function(fileName){
12
12
var filePath = cfg_dir + fileName ;
13
13
var fileExt = path . extname ( fileName ) ;
14
14
if ( fileExt != '.json' ) {
15
- return log ( 'Problem with file "' + filePath + '". There must be .json file extension.' ) ;
15
+ return log ( 'Problem with file "' + filePath + '". There must be .json file extension.' , 'runtime' ) ;
16
16
}
17
17
18
18
fs . readFile ( filePath , 'utf-8' , function ( err , data ) {
19
+ var cfg = { } ;
19
20
try {
20
21
if ( err ) throw err ;
21
22
22
- var cfg = JSON . parse ( data ) ;
23
+ cfg = JSON . parse ( data ) ;
23
24
if ( [ cfg . path , cfg . user , cfg . commands ] . indexOf ( undefined ) !== - 1 ) {
24
25
throw new Error ( 'Bad config file "' + filePath + '". It need to be json object with path, user and commands keys.' ) ;
25
26
}
26
27
} catch ( e ) {
27
- return log ( 'Error while processing file "' + filePath + '": ' + e ) ;
28
+ return log ( 'Error while processing file "' + filePath + '": ' + e , 'runtime' ) ;
28
29
}
29
30
//Populate good cfg object to objects map by filename without extension
30
31
return cfg_map [ path . basename ( fileName , fileExt ) ] = cfg ;
@@ -33,14 +34,16 @@ var processFile = function(fileName){
33
34
34
35
// Readfiles to object on server start
35
36
fs . readdir ( cfg_dir , function ( wtf , files ) {
37
+ var watchCallback = function ( prev , next ) {
38
+ processFile ( files [ i ] ) ;
39
+ } ;
40
+
36
41
for ( var i in files ) {
37
42
try {
38
43
processFile ( files [ i ] ) ;
39
- fs . watchFile ( cfg_dir + files [ i ] , function ( prev , next ) {
40
- processFile ( files [ i ] ) ;
41
- } ) ;
44
+ fs . watchFile ( cfg_dir + files [ i ] , watchCallback ) ;
42
45
} catch ( e ) {
43
- log ( e ) ;
46
+ log ( e , 'startup' ) ;
44
47
}
45
48
}
46
49
@@ -89,7 +92,7 @@ http.createServer(function(request, response) {
89
92
}
90
93
91
94
if ( ! fs . readdirSync ( cfg . path ) ) {
92
- return log ( 'Invalid path "' + cfg . path + '" in config "' + request . url + '"' ) ;
95
+ return log ( 'Invalid path "' + cfg . path + '" in config "' + request . url + '"' , request . url + '.error' ) ;
93
96
}
94
97
spawn_options . cwd = cfg . path ;
95
98
@@ -103,15 +106,15 @@ http.createServer(function(request, response) {
103
106
break ;
104
107
}
105
108
}
106
- if ( refNotMatch ) return log ( 'No refs match. Aborting.' ) ;
109
+ if ( refNotMatch ) return log ( 'No refs match. Aborting.' , request . url + '.info' ) ;
107
110
}
108
111
109
112
if ( cfg . commands . length ) {
110
113
var onData = function ( data ) {
111
- log ( 'Command "' + commandString + '" with data: ' + data ) ;
114
+ log ( 'Command "' + commandString + '" with data: ' + data , request . url + '.info' ) ;
112
115
} ;
113
116
var onError = function ( data ) {
114
- log ( 'Error in command "' + commandString + '" with data: ' + data ) ;
117
+ log ( 'Error in command "' + commandString + '" with data: ' + data , request . url + '.error' ) ;
115
118
} ;
116
119
117
120
for ( var i in cfg . commands ) {
@@ -125,7 +128,7 @@ http.createServer(function(request, response) {
125
128
}
126
129
} ) ;
127
130
128
- response . end ( "Deploy in queue!" ) ;
131
+ response . end ( "Process in queue!" ) ;
129
132
} else {
130
133
response . writeHead ( 404 , 'There is nothing.' ) ;
131
134
response . end ( "404;" ) ;
0 commit comments