1 const fs = require('fs');
2 const path = require('path');
3 const fileSearch = require('./file_search');
5 module.exports = function (opts) {
7 var configNameSearch = opts.configNameSearch;
8 var configPath = opts.configPath;
9 var searchPaths = opts.searchPaths;
10 // only search for a config if a path to one wasn't explicitly provided
12 if (!Array.isArray(searchPaths)) {
13 throw new Error('Please provide an array of paths to search for config in.');
15 if (!configNameSearch) {
16 throw new Error('Please provide a configNameSearch.');
18 configPath = fileSearch(configNameSearch, searchPaths);
20 // confirm the configPath exists and return an absolute path to it
21 if (fs.existsSync(configPath)) {
22 return path.resolve(configPath);