item.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.createItemFromDescriptor = createItemFromDescriptor;
  6. exports.createConfigItem = createConfigItem;
  7. exports.getItemDescriptor = getItemDescriptor;
  8. function _path() {
  9. const data = _interopRequireDefault(require("path"));
  10. _path = function () {
  11. return data;
  12. };
  13. return data;
  14. }
  15. var _configDescriptors = require("./config-descriptors");
  16. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  17. function createItemFromDescriptor(desc) {
  18. return new ConfigItem(desc);
  19. }
  20. function createConfigItem(value, {
  21. dirname = ".",
  22. type
  23. } = {}) {
  24. const descriptor = (0, _configDescriptors.createDescriptor)(value, _path().default.resolve(dirname), {
  25. type,
  26. alias: "programmatic item"
  27. });
  28. return createItemFromDescriptor(descriptor);
  29. }
  30. function getItemDescriptor(item) {
  31. if (item instanceof ConfigItem) {
  32. return item._descriptor;
  33. }
  34. return undefined;
  35. }
  36. class ConfigItem {
  37. constructor(descriptor) {
  38. this._descriptor = void 0;
  39. this.value = void 0;
  40. this.options = void 0;
  41. this.dirname = void 0;
  42. this.name = void 0;
  43. this.file = void 0;
  44. this._descriptor = descriptor;
  45. Object.defineProperty(this, "_descriptor", {
  46. enumerable: false
  47. });
  48. this.value = this._descriptor.value;
  49. this.options = this._descriptor.options;
  50. this.dirname = this._descriptor.dirname;
  51. this.name = this._descriptor.name;
  52. this.file = this._descriptor.file ? {
  53. request: this._descriptor.file.request,
  54. resolved: this._descriptor.file.resolved
  55. } : undefined;
  56. Object.freeze(this);
  57. }
  58. }
  59. Object.freeze(ConfigItem.prototype);