push-directory.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.build = void 0;
  4. function pushDirectoryWithRelativePath(root) {
  5. return function (directoryPath, paths) {
  6. paths.push(directoryPath.substring(root.length) || ".");
  7. };
  8. }
  9. function pushDirectoryFilterWithRelativePath(root) {
  10. return function (directoryPath, paths, filters) {
  11. const relativePath = directoryPath.substring(root.length) || ".";
  12. if (filters.every((filter) => filter(relativePath, true))) {
  13. paths.push(relativePath);
  14. }
  15. };
  16. }
  17. const pushDirectory = (directoryPath, paths) => {
  18. paths.push(directoryPath || ".");
  19. };
  20. const pushDirectoryFilter = (directoryPath, paths, filters) => {
  21. const path = directoryPath || ".";
  22. if (filters.every((filter) => filter(path, true))) {
  23. paths.push(path);
  24. }
  25. };
  26. const empty = () => { };
  27. function build(root, options) {
  28. const { includeDirs, filters, relativePaths } = options;
  29. if (!includeDirs)
  30. return empty;
  31. if (relativePaths)
  32. return filters && filters.length
  33. ? pushDirectoryFilterWithRelativePath(root)
  34. : pushDirectoryWithRelativePath(root);
  35. return filters && filters.length ? pushDirectoryFilter : pushDirectory;
  36. }
  37. exports.build = build;