1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | 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; }; }();
|
8 |
|
9 | var _helper = require('./data/redux/helper');
|
10 |
|
11 | var _path = require('path');
|
12 |
|
13 | var _path2 = _interopRequireDefault(_path);
|
14 |
|
15 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
16 |
|
17 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | var ComponentBrowserRegister = function () {
|
25 |
|
26 | |
27 |
|
28 |
|
29 |
|
30 | |
31 |
|
32 |
|
33 | function ComponentBrowserRegister(logger) {
|
34 | _classCallCheck(this, ComponentBrowserRegister);
|
35 |
|
36 | this._logger = logger;
|
37 | this._components = {};
|
38 | }
|
39 |
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | _createClass(ComponentBrowserRegister, [{
|
60 | key: 'reg',
|
61 | value: function reg(vendorName, componentName, data) {
|
62 | if (!this._components.hasOwnProperty(vendorName)) {
|
63 | this._components[vendorName] = {};
|
64 | }
|
65 | if (this._components[vendorName].hasOwnProperty(componentName)) {
|
66 | this._logger.notice('Duplicate component, will be overwritten: ' + vendorName + '.' + componentName);
|
67 | }
|
68 | this._components[vendorName][componentName] = data;
|
69 | }
|
70 |
|
71 | |
72 |
|
73 |
|
74 |
|
75 |
|
76 | }, {
|
77 | key: 'register',
|
78 | value: function register(absoluteRootDir, componentJson) {
|
79 | var isValid = this._validateComponentJson(componentJson);
|
80 | if (!isValid) {
|
81 | this._logger.notice("Invalid component json file: " + _path2.default.join(absoluteRootDir, 'component.json'));
|
82 | return;
|
83 | }
|
84 |
|
85 | if (!this._components.hasOwnProperty(componentJson.vendor)) {
|
86 | this._components[componentJson.vendor] = {};
|
87 | }
|
88 | if (!this._components[componentJson.vendor].hasOwnProperty(componentJson.name)) {
|
89 | this._logger.notice('Duplicate component, will be overwritten: ' + componentJson.vendor + '.' + componentJson.name);
|
90 | }
|
91 |
|
92 | var thumbnailPath = _path2.default.join(absoluteRootDir, componentJson.thumbnail);
|
93 | var testPath = null;
|
94 | if (componentJson.test != null && (0, _helper.isStringDuckType)(componentJson.test) && componentJson.test != '') {
|
95 | testPath = _path2.default.join(absoluteRootDir, componentJson.test);
|
96 | }
|
97 |
|
98 | this._components[componentJson.vendor][componentJson.name] = {
|
99 | thumbnail: thumbnailPath,
|
100 | test: testPath,
|
101 | detail: componentJson
|
102 | };
|
103 | }
|
104 | }, {
|
105 | key: 'getComponents',
|
106 | value: function getComponents() {
|
107 | return this._components;
|
108 | }
|
109 |
|
110 | |
111 |
|
112 |
|
113 |
|
114 |
|
115 | }, {
|
116 | key: '_validateComponentJson',
|
117 | value: function _validateComponentJson(componentJson) {
|
118 | var vendor = componentJson.vendor;
|
119 | var name = componentJson.name;
|
120 | var thumbnail = componentJson.thumbnail;
|
121 |
|
122 | return vendor != null && (0, _helper.isStringDuckType)(vendor) && vendor != '' && name != null && (0, _helper.isStringDuckType)(name) && name != '' && thumbnail != null && (0, _helper.isStringDuckType)(thumbnail) && thumbnail != '';
|
123 | }
|
124 | }]);
|
125 |
|
126 | return ComponentBrowserRegister;
|
127 | }();
|
128 |
|
129 | exports.default = ComponentBrowserRegister;
|
130 |
|
\ | No newline at end of file |