版博士V2.0程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

find_config.js 837 B

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