reader.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var path = require("path");
  4. var deep_1 = require("./filters/deep");
  5. var entry_1 = require("./filters/entry");
  6. var pathUtil = require("../utils/path");
  7. var Reader = /** @class */ (function () {
  8. function Reader(options) {
  9. this.options = options;
  10. this.micromatchOptions = this.getMicromatchOptions();
  11. this.entryFilter = new entry_1.default(options, this.micromatchOptions);
  12. this.deepFilter = new deep_1.default(options, this.micromatchOptions);
  13. }
  14. /**
  15. * Returns root path to scanner.
  16. */
  17. Reader.prototype.getRootDirectory = function (task) {
  18. return path.resolve(this.options.cwd, task.base);
  19. };
  20. /**
  21. * Returns options for reader.
  22. */
  23. Reader.prototype.getReaderOptions = function (task) {
  24. return {
  25. basePath: task.base === '.' ? '' : task.base,
  26. filter: this.entryFilter.getFilter(task.positive, task.negative),
  27. deep: this.deepFilter.getFilter(task.positive, task.negative),
  28. sep: '/'
  29. };
  30. };
  31. /**
  32. * Returns options for micromatch.
  33. */
  34. Reader.prototype.getMicromatchOptions = function () {
  35. return {
  36. dot: this.options.dot,
  37. nobrace: !this.options.brace,
  38. noglobstar: !this.options.globstar,
  39. noext: !this.options.extension,
  40. nocase: !this.options.case,
  41. matchBase: this.options.matchBase
  42. };
  43. };
  44. /**
  45. * Returns transformed entry.
  46. */
  47. Reader.prototype.transform = function (entry) {
  48. if (this.options.markDirectories && entry.isDirectory()) {
  49. entry.path += '/';
  50. }
  51. if (this.options.absolute && !path.isAbsolute(entry.path)) {
  52. entry.path = pathUtil.resolve(this.options.cwd, entry.path);
  53. entry.path = pathUtil.normalize(entry.path);
  54. }
  55. var item = this.options.stats ? entry : entry.path;
  56. if (this.options.transform === null) {
  57. return item;
  58. }
  59. return this.options.transform(item);
  60. };
  61. /**
  62. * Returns true if error has ENOENT code.
  63. */
  64. Reader.prototype.isEnoentCodeError = function (err) {
  65. return err.code === 'ENOENT';
  66. };
  67. return Reader;
  68. }());
  69. exports.default = Reader;