Module.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  6. var _lodash = require('lodash');
  7. var _lodash2 = _interopRequireDefault(_lodash);
  8. var _gzipSize = require('gzip-size');
  9. var _gzipSize2 = _interopRequireDefault(_gzipSize);
  10. var _Node2 = require('./Node');
  11. var _Node3 = _interopRequireDefault(_Node2);
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  15. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  16. var Module = function (_Node) {
  17. _inherits(Module, _Node);
  18. function Module(name, data, parent) {
  19. _classCallCheck(this, Module);
  20. var _this = _possibleConstructorReturn(this, (Module.__proto__ || Object.getPrototypeOf(Module)).call(this, name, parent));
  21. _this.data = data;
  22. return _this;
  23. }
  24. _createClass(Module, [{
  25. key: 'mergeData',
  26. value: function mergeData(data) {
  27. if (data.size) {
  28. this.size += data.size;
  29. }
  30. if (data.parsedSrc) {
  31. this.src = (this.src || '') + data.parsedSrc;
  32. }
  33. }
  34. }, {
  35. key: 'toChartData',
  36. value: function toChartData() {
  37. return {
  38. id: this.data.id,
  39. label: this.name,
  40. path: this.path,
  41. statSize: this.size,
  42. parsedSize: this.parsedSize,
  43. gzipSize: this.gzipSize
  44. };
  45. }
  46. }, {
  47. key: 'src',
  48. get: function get() {
  49. return this.data.parsedSrc;
  50. },
  51. set: function set(value) {
  52. this.data.parsedSrc = value;
  53. delete this._gzipSize;
  54. }
  55. }, {
  56. key: 'size',
  57. get: function get() {
  58. return this.data.size;
  59. },
  60. set: function set(value) {
  61. this.data.size = value;
  62. }
  63. }, {
  64. key: 'parsedSize',
  65. get: function get() {
  66. return this.src ? this.src.length : undefined;
  67. }
  68. }, {
  69. key: 'gzipSize',
  70. get: function get() {
  71. if (!_lodash2.default.has(this, '_gzipSize')) {
  72. this._gzipSize = this.src ? _gzipSize2.default.sync(this.src) : undefined;
  73. }
  74. return this._gzipSize;
  75. }
  76. }]);
  77. return Module;
  78. }(_Node3.default);
  79. exports.default = Module;
  80. ;