Initial commit
[yaffs-website] / node_modules / liftoff / lib / find_config.js
1 const fs = require('fs');
2 const path = require('path');
3 const fileSearch = require('./file_search');
4
5 module.exports = function (opts) {
6   opts = 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
11   if (!configPath) {
12     if (!Array.isArray(searchPaths)) {
13       throw new Error('Please provide an array of paths to search for config in.');
14     }
15     if (!configNameSearch) {
16       throw new Error('Please provide a configNameSearch.');
17     }
18     configPath = fileSearch(configNameSearch, searchPaths);
19   }
20   // confirm the configPath exists and return an absolute path to it
21   if (fs.existsSync(configPath)) {
22     return path.resolve(configPath);
23   }
24   return null;
25 };