Add support for object configs

parent 77102399
...@@ -2,13 +2,19 @@ const { readFileSync } = require('fs'); ...@@ -2,13 +2,19 @@ const { readFileSync } = require('fs');
const { merge } = require('lodash'); const { merge } = require('lodash');
module.exports = function (filenames, logger) { module.exports = function (items, logger) {
const configs = filenames const configs = items
.map(filename =>loadAndParseFile(filename, logger || console)) .map(item => {
.filter(string => string !== null); // Assume that strings are filenames
if (typeof item === 'string') {
return loadAndParseFile(item, logger || console);
}
return item;
})
.filter(item => item !== null);
if (!configs.length) { if (!configs.length) {
throw new Error(`Failed to read each of these config files: ${filenames.join(', ')}`); throw new Error(`Failed to read each of these config files: ${items.join(', ')}`);
} }
return merge(configs[0], ...configs.slice(1)); return merge(configs[0], ...configs.slice(1));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment