ConcatenatedModule.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _lodash = _interopRequireDefault(require("lodash"));
  7. var _Module = _interopRequireDefault(require("./Module"));
  8. var _ContentModule = _interopRequireDefault(require("./ContentModule"));
  9. var _ContentFolder = _interopRequireDefault(require("./ContentFolder"));
  10. var _utils = require("./utils");
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  13. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  14. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  15. class ConcatenatedModule extends _Module.default {
  16. constructor(name, data, parent) {
  17. super(name, data, parent);
  18. this.name += ' (concatenated)';
  19. this.children = Object.create(null);
  20. this.fillContentModules();
  21. }
  22. fillContentModules() {
  23. _lodash.default.each(this.data.modules, moduleData => this.addContentModule(moduleData));
  24. }
  25. addContentModule(moduleData) {
  26. const pathParts = (0, _utils.getModulePathParts)(moduleData);
  27. if (!pathParts) {
  28. return;
  29. }
  30. const [folders, fileName] = [pathParts.slice(0, -1), _lodash.default.last(pathParts)];
  31. let currentFolder = this;
  32. _lodash.default.each(folders, folderName => {
  33. let childFolder = currentFolder.getChild(folderName);
  34. if (!childFolder) {
  35. childFolder = currentFolder.addChildFolder(new _ContentFolder.default(folderName, this));
  36. }
  37. currentFolder = childFolder;
  38. });
  39. const module = new _ContentModule.default(fileName, moduleData, this);
  40. currentFolder.addChildModule(module);
  41. }
  42. getChild(name) {
  43. return this.children[name];
  44. }
  45. addChildModule(module) {
  46. module.parent = this;
  47. this.children[module.name] = module;
  48. }
  49. addChildFolder(folder) {
  50. folder.parent = this;
  51. this.children[folder.name] = folder;
  52. return folder;
  53. }
  54. mergeNestedFolders() {
  55. _lodash.default.invokeMap(this.children, 'mergeNestedFolders');
  56. }
  57. toChartData() {
  58. return _objectSpread({}, super.toChartData(), {
  59. concatenated: true,
  60. groups: _lodash.default.invokeMap(this.children, 'toChartData')
  61. });
  62. }
  63. }
  64. exports.default = ConcatenatedModule;
  65. ;