get-paths-sync.js 825 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. /**
  3. * Dependencies
  4. */
  5. const glob = require('glob');
  6. /**
  7. * Get paths (sync)
  8. */
  9. module.exports = function getPathsSync(patterns, config) {
  10. //Extract relevant config
  11. const {ignore, disableGlobs, glob: globConfig, cwd} = config;
  12. //Not using globs?
  13. if (disableGlobs) {
  14. return patterns;
  15. }
  16. //Prepare glob config
  17. const cfg = Object.assign({ignore}, globConfig, {nodir: true});
  18. //Append CWD configuration if given (#56)
  19. //istanbul ignore if
  20. if (cwd) {
  21. cfg.cwd = cwd;
  22. }
  23. //Get paths
  24. const paths = patterns.map(pattern => glob.sync(pattern, cfg));
  25. const flattened = [].concat.apply([], paths);
  26. //Prefix each path with CWD if given (#56)
  27. //istanbul ignore if
  28. if (cwd) {
  29. return flattened.map(path => `${cwd}${path}`);
  30. }
  31. //Return flattened
  32. return flattened;
  33. };