mm_machine 2.3.2 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +54 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -49,7 +49,7 @@ class Manager extends Mod {
49
49
  * 类型 script脚本 | json配置 | drive驱动
50
50
  * @type {string}
51
51
  */
52
- type: 'drive',
52
+ mod_type: 'drive',
53
53
  /**
54
54
  * 是否懒加载
55
55
  * @type {boolean}
@@ -108,17 +108,58 @@ Manager.prototype.getInfos = function () {
108
108
  * @param {string} name 模块名
109
109
  * @param {number} sort 排序值
110
110
  * @param {boolean} state 状态
111
+ * @param {string} file 文件名
111
112
  * @returns {object} 模块状态模型
112
113
  */
113
- Manager.prototype.newInfo = function (name, sort, state) {
114
+ Manager.prototype.newInfo = function (name, sort, state, file = '') {
114
115
  return {
115
116
  name,
116
117
  sort,
117
- available: state == true,
118
- enabled: true
118
+ state,
119
+ enabled: true,
120
+ file: file || '',
121
+ get available() {
122
+ return this.state == true && this.enabled;
123
+ }
119
124
  };
120
125
  };
121
126
 
127
+ /**
128
+ * 设置模块信息
129
+ * @param {object} info 模块信息
130
+ */
131
+ Manager.prototype.setInfo = function (info) {
132
+ let has = false;
133
+ for (let i = 0; i < this.infos.length; i++) {
134
+ let o = this.infos[i];
135
+ if (o.name == info.name) {
136
+ this.infos[i] = info;
137
+ has = true;
138
+ break;
139
+ }
140
+ }
141
+ if (!has) {
142
+ this.infos.push(info);
143
+ }
144
+ };
145
+
146
+ /**
147
+ * 获取所有模块对象
148
+ * @returns {object[]} 模块对象数组
149
+ */
150
+ Manager.prototype.getList = function () {
151
+ let list = [];
152
+ for (let i = 0; i < this.infos.length; i++) {
153
+ let info = this.infos[i];
154
+ let mod = this.getMod(info.name);
155
+ if (mod) {
156
+ mod.config.state = info.state;
157
+ }
158
+ list.push(mod);
159
+ }
160
+ return list;
161
+ };
162
+
122
163
  /**
123
164
  * 获取基础目录
124
165
  * @returns {string} 基础目录
@@ -147,7 +188,7 @@ Manager.prototype.updateInfo = function () {
147
188
  this.infos = [];
148
189
  for (let name in this.mods) {
149
190
  let o = this.mods[name];
150
- let info = this.newInfo(name, o.config.sort, o.config.state);
191
+ let info = this.newInfo(name, o.config.sort, o.config.state, o.config_file);
151
192
  this.infos.push(info);
152
193
  }
153
194
  this.sort();
@@ -216,7 +257,7 @@ Manager.prototype.getMods = function () {
216
257
  */
217
258
  Manager.prototype.newMod = function (config_file, config, script) {
218
259
  let mod;
219
- switch (this.config.type) {
260
+ switch (this.config.mod_type) {
220
261
  case 'script':
221
262
  mod = new Mod(config, this);
222
263
  break;
@@ -227,8 +268,12 @@ Manager.prototype.newMod = function (config_file, config, script) {
227
268
  }
228
269
  mod.mode = this.config.mode;
229
270
  mod.loadConfig(config_file);
230
- mod.setMethods(script);
231
- mod.setConfig(config);
271
+ if (script) {
272
+ mod.setMethods(script);
273
+ }
274
+ if (config) {
275
+ mod.setConfig(config);
276
+ }
232
277
  return mod;
233
278
  };
234
279
 
@@ -237,7 +282,7 @@ Manager.prototype.newMod = function (config_file, config, script) {
237
282
  * @param {string} config_file 配置文件路径
238
283
  * @param {object} config 配置项
239
284
  * @param {object} script 模块对象
240
- * @returns {object} 配置项
285
+ * @returns {object} 模块对象
241
286
  */
242
287
  Manager.prototype.register = function (config_file, config = {}, script = {}) {
243
288
  let mod = this.newMod(config_file, config, script);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "2.3.2",
3
+ "version": "2.3.4",
4
4
  "description": "A flexible Node.js plugin mechanism system for dynamic loading, management and execution of modules. Supports hot reload, lifecycle management, and modern JavaScript features.",
5
5
  "main": "index.js",
6
6
  "scripts": {