暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.readdirRecursive = void 0;
  4. const path_1 = require("path");
  5. const fs_extra_1 = require("fs-extra");
  6. const _ = require("lodash");
  7. const minimatch = require("minimatch");
  8. async function readdirRecursiveHelper(options) {
  9. const dirContents = (0, fs_extra_1.readdirSync)(options.path);
  10. const fullPaths = dirContents.map((n) => (0, path_1.join)(options.path, n));
  11. const filteredPaths = fullPaths.filter((p) => !options.filter(p));
  12. const filePromises = [];
  13. for (const p of filteredPaths) {
  14. const fstat = (0, fs_extra_1.statSync)(p);
  15. if (fstat.isFile()) {
  16. filePromises.push(Promise.resolve({ name: p, mode: fstat.mode }));
  17. }
  18. if (!fstat.isDirectory()) {
  19. continue;
  20. }
  21. filePromises.push(readdirRecursiveHelper({ path: p, filter: options.filter }));
  22. }
  23. const files = await Promise.all(filePromises);
  24. let flatFiles = _.flattenDeep(files);
  25. flatFiles = flatFiles.filter((f) => f !== null);
  26. return flatFiles;
  27. }
  28. async function readdirRecursive(options) {
  29. const mmopts = { matchBase: true, dot: true };
  30. const rules = (options.ignore || []).map((glob) => {
  31. return (p) => minimatch(p, glob, mmopts);
  32. });
  33. const filter = (t) => {
  34. return rules.some((rule) => {
  35. return rule(t);
  36. });
  37. };
  38. return readdirRecursiveHelper({
  39. path: options.path,
  40. filter: filter,
  41. });
  42. }
  43. exports.readdirRecursive = readdirRecursive;