mm_machine 2.4.3 → 2.4.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 (4) hide show
  1. package/drive.js +9 -3
  2. package/index.js +11 -7
  3. package/mod.js +57 -6
  4. package/package.json +1 -1
package/drive.js CHANGED
@@ -3,6 +3,7 @@ require('mm_tpl');
3
3
  let {
4
4
  conf
5
5
  } = require('mm_config');
6
+ // const { Word } = require('./ulits/word.js');
6
7
  const {
7
8
  Mod
8
9
  } = require('./mod');
@@ -617,7 +618,12 @@ Drive.prototype._delArray = function (file, config, name) {
617
618
  * @returns {string} 配置文件名称
618
619
  */
619
620
  Drive.prototype._getName = function (file) {
620
- return file.dirname().basename();
621
+ let name = file.dirname().basename();
622
+ return name;
623
+ // // 提取文件名作为模块名
624
+ // var word = new Word();
625
+ // // 将文件名改为驼峰命名法
626
+ // return word.toCamelCase(name);
621
627
  };
622
628
 
623
629
  /**
@@ -639,8 +645,8 @@ Drive.prototype.loadBefore = function () {
639
645
  * 加载处理
640
646
  */
641
647
  Drive.prototype._loadCore = function () {
642
- this.loadConfig();
643
- this.loadScript();
648
+ // this.loadConfig();
649
+ // this.loadScript();
644
650
  };
645
651
 
646
652
  /**
package/index.js CHANGED
@@ -86,8 +86,9 @@ class Manager extends Mod {
86
86
  * 构造函数
87
87
  * @param {object} config 配置项
88
88
  * @param {object} parent 父项对象
89
+ * @param {object} mods 模块对象列表
89
90
  */
90
- constructor(config, parent) {
91
+ constructor(config, parent, mods = {}) {
91
92
  super({
92
93
  ...Manager.config,
93
94
  ...config
@@ -96,7 +97,7 @@ class Manager extends Mod {
96
97
  // 模块信息列表 { name: '', sort: 0, available: true, enabled: true }
97
98
  this.infos = [];
98
99
  // 模块
99
- this.mods = {};
100
+ this.mods = mods;
100
101
  }
101
102
  }
102
103
 
@@ -614,25 +615,28 @@ Manager.prototype._initManager = function () {
614
615
  /**
615
616
  * 加载资源
616
617
  */
617
- Manager.prototype._loadSources = function () {
618
+ Manager.prototype._loadSources = async function () {
619
+ // 通过更新函数加载资源信息
620
+ await this.call('update');
618
621
  };
619
622
 
620
623
  /**
621
624
  * 初始化资源
622
625
  */
623
- Manager.prototype._initSources = function () {
626
+ Manager.prototype._initSources = async function () {
627
+ // 通过
624
628
  };
625
629
 
626
630
  /**
627
631
  * 初始化公共属性
628
632
  */
629
- Manager.prototype._initCore = function () {
633
+ Manager.prototype._initCore = async function () {
630
634
  // 初始化管理器
631
635
  this._initManager();
632
636
  // 加载资源
633
- this._loadSources();
637
+ await this._loadSources();
634
638
  // 初始化AI客户端
635
- this._initSources();
639
+ await this._initSources();
636
640
  };
637
641
 
638
642
  module.exports = {
package/mod.js CHANGED
@@ -238,11 +238,19 @@ Mod.prototype._onDestroy = async function (ctx) {
238
238
  });
239
239
  };
240
240
 
241
+ /**
242
+ * 加载 - 内部方法
243
+ * @private
244
+ */
245
+ Mod.prototype._load = async function () {
246
+ return this;
247
+ };
248
+
241
249
  /**
242
250
  * 加载
243
251
  */
244
252
  Mod.prototype.load = async function () {
245
-
253
+ return await this._load();
246
254
  };
247
255
 
248
256
  /**
@@ -253,38 +261,65 @@ Mod.prototype._loadCore = async function () {
253
261
  };
254
262
 
255
263
  /**
256
- * 启动
264
+ * 启动 - 内部方法
265
+ * @private
266
+ * @param {...any} args 初始化参数
257
267
  */
258
- Mod.prototype.start = async function () {
268
+ Mod.prototype._start = async function (...args) {
269
+ return this;
270
+ };
259
271
 
272
+ /**
273
+ * 启动
274
+ */
275
+ Mod.prototype.start = async function (...args) {
276
+ return await this._start(...args);
260
277
  };
261
278
 
262
279
  /**
263
280
  * 启动核心
281
+ * @private
264
282
  */
265
283
  Mod.prototype._startCore = async function () {
266
284
 
267
285
  };
268
286
 
287
+ /**
288
+ * 停止 - 内部方法
289
+ * @private
290
+ */
291
+ Mod.prototype._stop = async function () {
292
+ return this;
293
+ };
294
+
269
295
  /**
270
296
  * 停止
271
297
  */
272
298
  Mod.prototype.stop = async function () {
273
-
299
+ return await this._stop();
274
300
  };
275
301
 
276
302
  /**
277
303
  * 停止核心
304
+ * @private
278
305
  */
279
306
  Mod.prototype._stopCore = async function () {
280
307
 
281
308
  };
282
309
 
310
+ /**
311
+ * 卸载 - 内部方法
312
+ * @private
313
+ */
314
+ Mod.prototype._unload = async function () {
315
+ return this;
316
+ };
317
+
283
318
  /**
284
319
  * 卸载
285
320
  */
286
321
  Mod.prototype.unload = async function () {
287
-
322
+ return await this._unload();
288
323
  };
289
324
 
290
325
  /**
@@ -329,13 +364,29 @@ Mod.prototype.end = async function () {
329
364
  await this.do('destroy');
330
365
  };
331
366
 
367
+ /**
368
+ * 获取事件管理器
369
+ * @returns {Eventer|null} 事件管理器
370
+ */
371
+ Mod.prototype.getEventer = function () {
372
+ return this._eventer || $.eventer;
373
+ };
374
+
375
+ /**
376
+ * 设置事件管理器
377
+ * @param {Eventer} eventer 事件管理器
378
+ */
379
+ Mod.prototype.setEventer = function (eventer) {
380
+ this._eventer = eventer;
381
+ };
382
+
332
383
  /**
333
384
  * 触发事件
334
385
  * @param {string} event 事件名
335
386
  * @param {...any} args 事件参数
336
387
  */
337
388
  Mod.prototype.emitEvent = function (event, ...args) {
338
- this._eventer?.emit(event, ...args);
389
+ this.getEventer()?.emit(event, ...args);
339
390
  };
340
391
 
341
392
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "2.4.3",
3
+ "version": "2.4.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": {