You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.3 KiB

4 years ago
  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.absolute) {
  49. entry.path = pathUtil.makeAbsolute(this.options.cwd, entry.path);
  50. }
  51. if (this.options.markDirectories && entry.isDirectory()) {
  52. entry.path += '/';
  53. }
  54. var item = this.options.stats ? entry : entry.path;
  55. if (this.options.transform === null) {
  56. return item;
  57. }
  58. return this.options.transform(item);
  59. };
  60. /**
  61. * Returns true if error has ENOENT code.
  62. */
  63. Reader.prototype.isEnoentCodeError = function (err) {
  64. return err.code === 'ENOENT';
  65. };
  66. return Reader;
  67. }());
  68. exports.default = Reader;