mm_machine 2.3.1 → 2.3.3

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 (3) hide show
  1. package/index.js +48 -7
  2. package/mod.js +7 -7
  3. 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;
@@ -237,7 +278,7 @@ Manager.prototype.newMod = function (config_file, config, script) {
237
278
  * @param {string} config_file 配置文件路径
238
279
  * @param {object} config 配置项
239
280
  * @param {object} script 模块对象
240
- * @returns {object} 配置项
281
+ * @returns {object} 模块对象
241
282
  */
242
283
  Manager.prototype.register = function (config_file, config = {}, script = {}) {
243
284
  let mod = this.newMod(config_file, config, script);
package/mod.js CHANGED
@@ -336,25 +336,25 @@ Mod.prototype.emitEvent = function (event, ...args) {
336
336
 
337
337
  /**
338
338
  * 运行方法
339
- * @param {string} method 方法名
340
339
  * @param {...any} args 方法参数
341
340
  * @returns {Promise<any>} 方法执行结果
342
341
  */
343
- Mod.prototype.run = async function (method, ...args) {
344
- return this.main(method, ...args);
342
+ Mod.prototype.run = async function (...args) {
343
+ return this.main(...args);
345
344
  };
346
345
 
347
346
  /**
348
- * 主方法
349
- * @param {string} method 方法名
347
+ * 主方法名
350
348
  * @param {...any} args 方法参数
351
349
  * @returns {Promise<any>} 方法执行结果
352
350
  */
353
- Mod.prototype.main = async function (method, ...args) {
351
+ Mod.prototype.main = async function (...args) {
352
+ let method = args[0];
354
353
  if (!this.methods?.[method]) {
355
354
  throw new Error(`方法${method}不存在`);
356
355
  }
357
- return await this.methods[method](...args);
356
+ let params = args.slice(1);
357
+ return await this.methods[method](...params);
358
358
  };
359
359
 
360
360
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
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": {