UNPKG

4.28 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _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
9var _helper = require('./data/redux/helper');
10
11var _path = require('path');
12
13var _path2 = _interopRequireDefault(_path);
14
15function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
17function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
19/**
20 * Used to register components to use for component browser.
21 *
22 * @SERVER
23 */
24var ComponentBrowserRegister = function () {
25
26 /**
27 * @param {Logger} logger
28 */
29
30 /**
31 * @type {Logger}
32 */
33 function ComponentBrowserRegister(logger) {
34 _classCallCheck(this, ComponentBrowserRegister);
35
36 this._logger = logger;
37 this._components = {};
38 }
39
40 /**
41 * Example:
42 *
43 * {
44 * vendor: {
45 * ComponentName: {
46 * thumbnail: '/.../.../../ComponentNameThumb.js',
47 * test: '/../../../ComponentNameThumb.js',
48 * detail: {
49 * // Component JSON.
50 * }
51 * }
52 * }
53 * }
54 *
55 * @type {{[key: string]: {[key:string]: ComponentJson}}}
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 * @param {string} absoluteRootDir
73 * @param {Object} componentJson
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 * @param {Object} componentJson
112 * @return {boolean}
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
129exports.default = ComponentBrowserRegister;
130//# sourceMappingURL=ComponentBrowserRegister.js.map
\No newline at end of file