-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportService.js
76 lines (71 loc) · 2 KB
/
exportService.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
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
var redis = require('redis').createClient(6479,'192.168.16.128'),
prefix = require('./utils/prefix.js').redis,
utils = require('./utils/common.js');
const TYPE_JS = 0,
TYPE_GENERIC = 1,
TYPE_JAVA = 2,
TYPE_WRAPPED_JS = 10;
if(process.argv.length < 4){
console.log('Missing service file to export!');
console.log('Usage: node exportService.js serviceFile.js');
process.exit(1);
}
if(process.argv[2] == '-c'){
var services = utils.getConfigFromFileSync(process.argv[3]),
errCount = 0,
sucCount = 0,
notExp = 0;
var end = function(){
if(errCount + sucCount + notExp == utils.length(services)){
console.log('\n' + sucCount + ' services successfully exported');
console.log(errCount + ' services unsuccessfully exported');
console.log(notExp + ' services not exported');
console.log(' on total of ' + utils.length(services) + ' services');
process.exit(0);
}
}
console.log('\nTotal services: ' + utils.length(services));
for(var i in services){
console.log('\tService ' + i + ' type: ' + services[i].worker.config.procType);
switch(services[i].worker.config.procType){
case TYPE_WRAPPED_JS:
saveService_wrappedJs(services[i].worker.config.file, i, function(err, res){
if(err){
errCount++;
console.log(err);
}else{
sucCount++;
}
end();
});
break;
default:
notExp++;
end();
break;
}
}
}else{
saveService(process.argv[2], process.argv[3]);
}
function saveService_wrappedJs(name, id, callback){
var service = require(name),
fn = [];
for(var i in service)
if(typeof(service[i]) == 'function')
fn.push(i);
console.log(prefix.service + id + ':' + prefix.func)
redis.sadd(prefix.service + id + ':' + prefix.func, fn, function(err, res){
if(err){
callback(err, null);
}
if(res == 0){
console.log('Service "' + id + '" already up to date!');
}else{
console.log('Service "' + id + '" successfully exported!');
console.log(res + ' functions');
console.log(' ', fn);
}
callback();
});
}