UNPKG

1.13 kBJavaScriptView Raw
1var fs = require('fs'),
2 path = require('path'),
3 extend = require('xtend'),
4 helpers = require('./helpers'),
5 logger = require('./logger')();
6
7module.exports = function(wallboardConfigFilePath, atlasboardConfigFilePath) {
8 if (!wallboardConfigFilePath){
9 wallboardConfigFilePath = path.join(process.cwd(), "/config/atlasboard.json");
10 }
11
12 if (!atlasboardConfigFilePath){
13 atlasboardConfigFilePath = path.join(__dirname, "../config/defaultAtlasboard.json");
14 }
15
16 function doesNotExistsCallback(path){
17 logger.error('\n----------------------\nERROR! Config file does not exist: ' + path + '. Using defaults...\n----------------------');
18 }
19
20 function isInvalidCallback(path){
21 throw 'ERROR! Invalid JSON config file: ' + path;
22 }
23
24 var config = extend(
25 helpers.getJSONFromFile(atlasboardConfigFilePath, {}, null, isInvalidCallback),
26 helpers.getJSONFromFile(wallboardConfigFilePath, {}, doesNotExistsCallback, isInvalidCallback)
27 );
28
29 return {
30 get: function (key){
31 if (config){
32 return config[key];
33 }
34 return null;
35 }
36 };
37};
\No newline at end of file