-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconfig.js
More file actions
219 lines (178 loc) · 7.48 KB
/
config.js
File metadata and controls
219 lines (178 loc) · 7.48 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
var path = require('path'),
http = require('https'),
fs = require('fs'),
timeLoop = require('./timers'),
network,
instruments;
var env = process.env.NODE_ENV || 'development';
var appDir = path.dirname(require.main.filename);
var app_json_path = path.join(appDir, 'node-offline-debug-' + env + '.json');
var package_json_path = path.join(__dirname, '../config', env + '.json');
var config = JSON.parse(fs.readFileSync(package_json_path));
// copy app_config configurations over package configurations
function merge_config(top_config, base_config)
{
for (var option in top_config)
{
if (Array.isArray(top_config[option])) // handle array elements in the same order
{
if (!Array.isArray(base_config[option]))
base_config[option] = top_config[option];
else
{
for(var i=0;i<top_config[option].length;i++)
{
if (base_config[option].length <= i)
base_config[option].push(top_config[option][i]);
else
merge_config(top_config[option][i],base_config[option][i]);
}
}
}
else if (typeof top_config[option] === "Object") // recurseively handle complex configurations
{
if (base_config[option] === undefined)
base_config[option] = top_config[option];
else
merge_config(top_config[option], base_config[option]);
}
else
base_config[option] = top_config[option];
}
}
if (fs.existsSync(app_json_path))
{
var app_config = JSON.parse(fs.readFileSync(app_json_path));
if (app_config && Object.keys(app_config))
merge_config(app_config,config);
}
config.reloadPublicConfigDataEvery = 60000; // Reload public config file every 60 seconds
config.public_configuration_file = config.public_configuration_file || '';
// These two methods must reside here to enable loading configuration
config.refreshPublicConfig = function (values) {
var hasAutoCheckConfigurationChanged = false;
config.useGivenNames = values.useGivenNames;
if (!config.autoCheckConfiguration) {
config.autoCheckConfiguration = {};
} else {
hasAutoCheckConfigurationChanged = (config.autoCheckConfiguration.once !== values.autoCheckConfiguration.once);
}
config.autoCheckConfiguration.once = values.autoCheckConfiguration.once;
config.autoCheckConfiguration.every = values.autoCheckConfiguration.every;
// If the configuration should be loaded ensure it is restarted
if (hasAutoCheckConfigurationChanged) {
if (config.autoCheckConfiguration.once === true) {
timeLoop.logic(function() { return; }, this);
} else {
if ((config.autoCheckConfiguration.once === false) && (config.autoCheckConfiguration.every > 0)) {
config.initIntervaling();
}
}
}
};
config.public_configuration_file_reload = function () {
var publicConfigFile = path.join(__dirname, config.public_configuration_file);
var publicConfig = JSON.parse(fs.readFileSync(publicConfigFile));
config.refreshPublicConfig(publicConfig);
};
config.public_configuration_file_loop = function () {
var configReload = setInterval(config.public_configuration_file_reload, config.reloadPublicConfigDataEvery);
};
config.public_configuration_file_loop();
/* START default values of configuration */
config.status = "init";
config.exclude = config.exclude || [];
config.useGivenNames = config.useGivenNames || false;
if (config.logging)
config.globalLogLevel = config.logging.globalLogLevel;
config.globalLogLevel = config.globalLogLevel || 'info';
config.createTempCopyOfInstrumention = config.createTempCopyOfInstrumention || false;
config.methodSignatureSeparator = '&&~\%\%';
config.compressPosts = config.compressPosts || false;
config.active_debug_service_type = config.active_debug_service_type || 'file';
config.public_configuration_file_reload();
config.debug_services = config.debug_services;
if (config.debug_services && config.debug_services.length > 0) {
for(var i = 0; i < config.debug_services.length; i++) {
if (config.debug_services[i].type === config.active_debug_service_type)
config.debug_service = config.debug_services[i];
}
}
config.debug_service = config.debug_service ||
JSON.parse('{"type": "file","path": "../config/debug_configuration.json","outputLog": "debug"}');
if (config.debug_service.type === 'service') {
config.debug_service.username = process.env.HPAPPDEBUG_USERNAME || config.debug_service.username;
config.debug_service.password = process.env.HPAPPDEBUG_PASSWORD || config.debug_service.password;
}
/* END default values of configuration */
config.initIntervaling = function () {
if (config.autoCheckConfiguration) {
if (config.autoCheckConfiguration.once === false) {
timeLoop.logic(config.reload, this);
if (!instruments) { instruments = require('./instruments'); }
if (config.debug_service.type === 'file') {
if (instruments.isLoggerSet() === false) {
instruments.setLoggerWithConfiguration();
}
if (config.logging.debug.logToConsole === true) {
instruments.setLoggerLevel(config.logging.globalLogLevel);
}
}
timeLoop.interval(config.autoCheckConfiguration.every);
timeLoop();
}
}
};
config.reload = function (){
if (this.debug_service && this.debug_service.type)
{
config.status = "loading";
if (this.debug_service.type === 'file') {
this.debug_configuration_file_reload();
this.public_configuration_file_reload();
} else if (this.debug_service.type === 'service') {
this.debug_configuration_service_reload();
}
}
};
config.debug_configuration_file_reload = function (){
var debug_config = path.join(__dirname, this.debug_service.path);
this.lookup = JSON.parse(fs.readFileSync(debug_config)).functionList;
this.refreshLookupSet();
config.status = "done";
};
config.debug_configuration_service_reload = function () {
if (!network) {
network = require('./network');
network.setSettings(config);
}
network.updateLookup(config, true);
};
config.refreshLookupSet = function () {
if (config.lookup) {
if (!instruments) {
instruments = require('./instruments');
}
config.lookup.forEach(function (trackedMethod) {
var methodLookup = instruments.getFunctionUniqueID(trackedMethod.sourceFile, trackedMethod.line);
if (typeof instruments.lookupMap[methodLookup] !== "undefined") {
if (trackedMethod.selected === false) {
delete instruments.lookupMap[methodLookup];
}
else
instruments.lookupMap[methodLookup] = trackedMethod;
}
else // lookupMap doesn't have the trackedMethod
{
if (trackedMethod.selected === true)
{
instruments.lookupMap[methodLookup] = trackedMethod;
}
// if the trackedMethod is not selected, there is no need to track it
// and since it's also not in the lookupMap, all is well
}
});
}
};
config.env = env;
module.exports = config;