push-file.js 970 B

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.build = void 0;
  4. const pushFileFilterAndCount = (filename, _paths, counts, filters) => {
  5. if (filters.every((filter) => filter(filename, false)))
  6. counts.files++;
  7. };
  8. const pushFileFilter = (filename, paths, _counts, filters) => {
  9. if (filters.every((filter) => filter(filename, false)))
  10. paths.push(filename);
  11. };
  12. const pushFileCount = (_filename, _paths, counts, _filters) => {
  13. counts.files++;
  14. };
  15. const pushFile = (filename, paths) => {
  16. paths.push(filename);
  17. };
  18. const empty = () => { };
  19. function build(options) {
  20. const { excludeFiles, filters, onlyCounts } = options;
  21. if (excludeFiles)
  22. return empty;
  23. if (filters && filters.length) {
  24. return onlyCounts ? pushFileFilterAndCount : pushFileFilter;
  25. }
  26. else if (onlyCounts) {
  27. return pushFileCount;
  28. }
  29. else {
  30. return pushFile;
  31. }
  32. }
  33. exports.build = build;