-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.js
75 lines (73 loc) · 2.67 KB
/
index.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
'use strict';
var io = require('./lib/io');
var network = require('./lib/network');
var path = require('path');
var os = require('os')
const RedisClientLib = require('./lib/redisClient');
const EnvTagsReplacer = require('./lib/env-tags-replacer');
module.exports = function(){
let envTagsReplacerInstance = new EnvTagsReplacer();
var ioInstance = io(envTagsReplacerInstance);
var networkInstance = network(ioInstance, envTagsReplacerInstance);
return {
get:function(options,cb){
/**
* load the config from the network and merge with default config
* @param options {target:save location and filename,keys: {key:,secret:},source:default loading target}
* @param callback function(err){}
*/
return networkInstance.get(options,cb)
},
init:function(options, cb){
/**
* initializes the config based on a source config, this must be called first
* @param options {source,targetDir,targetFile}
* @param cb function(err,configpath)
*/
return ioInstance.initConfig(options,cb)
},
load:function(options){
/**
* loads config from source config, defaults to your home directory if you don't specify a source
* @param options {source,hash=1,0}
* @returns {err,config}
*/
options = options || {}
options.source = options.source || path.join(os.homedir(), '.edgemicro', 'config.yaml');
return ioInstance.loadSync(options);
},
save:function(config,target){
/**
* saves the config
* @param config to save
* @param target destination
*/
return ioInstance.saveSync(config,target)
},
setConsoleLogger:function(consoleLogger){
/**
* sets the consoleLogger to ioInstance and networkInstance
* @param consoleLogger to use for console logging
*/
ioInstance.setConsoleLogger(consoleLogger);
networkInstance.setConsoleLogger(consoleLogger);
envTagsReplacerInstance.setConsoleLogger(consoleLogger);
},
getRedisClient:function(config, cb){
/**
* Returns a new redis connection object.
* @param config object with redisHost, redisPort, redisDb and retryEnabled
*/
return new RedisClientLib(config, cb);
},
replaceEnvTags:function(config,options){
/**
* replaces the env tags in config by the env values
* @param config object whose <E></E> tags to be replaced with env values.
* @param options object which has below properties
* disableLogs: boolean value, if 'true' console errors and debug logs will not be displayed.
*/
return envTagsReplacerInstance.replaceEnvTags(config,options)
}
};
}();