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.

74 lines
2.5 KiB

4 years ago
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var readdir = require("@mrmlnc/readdir-enhanced");
  17. var reader_1 = require("./reader");
  18. var fs_sync_1 = require("../adapters/fs-sync");
  19. var ReaderSync = /** @class */ (function (_super) {
  20. __extends(ReaderSync, _super);
  21. function ReaderSync() {
  22. return _super !== null && _super.apply(this, arguments) || this;
  23. }
  24. Object.defineProperty(ReaderSync.prototype, "fsAdapter", {
  25. /**
  26. * Returns FileSystem adapter.
  27. */
  28. get: function () {
  29. return new fs_sync_1.default(this.options);
  30. },
  31. enumerable: true,
  32. configurable: true
  33. });
  34. /**
  35. * Use sync API to read entries for Task.
  36. */
  37. ReaderSync.prototype.read = function (task) {
  38. var root = this.getRootDirectory(task);
  39. var options = this.getReaderOptions(task);
  40. try {
  41. var entries = this.api(root, task, options);
  42. return entries.map(this.transform, this);
  43. }
  44. catch (err) {
  45. if (this.isEnoentCodeError(err)) {
  46. return [];
  47. }
  48. throw err;
  49. }
  50. };
  51. /**
  52. * Returns founded paths.
  53. */
  54. ReaderSync.prototype.api = function (root, task, options) {
  55. if (task.dynamic) {
  56. return this.dynamicApi(root, options);
  57. }
  58. return this.staticApi(task, options);
  59. };
  60. /**
  61. * Api for dynamic tasks.
  62. */
  63. ReaderSync.prototype.dynamicApi = function (root, options) {
  64. return readdir.readdirSyncStat(root, options);
  65. };
  66. /**
  67. * Api for static tasks.
  68. */
  69. ReaderSync.prototype.staticApi = function (task, options) {
  70. return this.fsAdapter.read(task.patterns, options.filter);
  71. };
  72. return ReaderSync;
  73. }(reader_1.default));
  74. exports.default = ReaderSync;