mm_machine 2.4.2 → 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 +22 -18
  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
 
@@ -296,7 +297,7 @@ Manager.prototype.newMod = function (config_file, config, script) {
296
297
  * @param {object} script 模块对象
297
298
  * @returns {object} 模块对象
298
299
  */
299
- Manager.prototype.register = function (config_file, config = {}, script = {}) {
300
+ Manager.prototype.registerMod = function (config_file, config = {}, script = {}) {
300
301
  let mod = this.newMod(config_file, config, script);
301
302
  this.setMod(mod.config.name, mod);
302
303
  return mod;
@@ -307,7 +308,7 @@ Manager.prototype.register = function (config_file, config = {}, script = {}) {
307
308
  * @param {string} name 模块名
308
309
  * @returns {Promise<any>} 加载结果
309
310
  */
310
- Manager.prototype.load = async function (name) {
311
+ Manager.prototype.loadMod = async function (name) {
311
312
  let mod = this.getMod(name);
312
313
  if (mod) {
313
314
  return await mod.do('load');
@@ -320,7 +321,7 @@ Manager.prototype.load = async function (name) {
320
321
  * @param {string} name 模块名
321
322
  * @returns {Promise<any>} 卸载结果
322
323
  */
323
- Manager.prototype.unload = async function (name) {
324
+ Manager.prototype.unloadMod = async function (name) {
324
325
  let mod = this.getMod(name);
325
326
  if (mod) {
326
327
  return await mod.do('unload');
@@ -333,7 +334,7 @@ Manager.prototype.unload = async function (name) {
333
334
  * @param {string} name 模块名
334
335
  * @returns {Promise<any>} 重载结果
335
336
  */
336
- Manager.prototype.reload = async function (name) {
337
+ Manager.prototype.reloadMod = async function (name) {
337
338
  let mod = this.getMod(name);
338
339
  if (mod) {
339
340
  return await mod.do('reload');
@@ -346,11 +347,11 @@ Manager.prototype.reload = async function (name) {
346
347
  * @param {string} name 模块名
347
348
  * @returns {Promise<any>} 注销结果
348
349
  */
349
- Manager.prototype.unregister = function (name) {
350
+ Manager.prototype.unregisterMod = function (name) {
350
351
  // 卸载模块
351
- this.unload(name);
352
+ this.unloadMod(name);
352
353
  // 删除模块
353
- this.delMod(name);
354
+ let mod = this.delMod(name);
354
355
  return mod;
355
356
  };
356
357
 
@@ -360,16 +361,16 @@ Manager.prototype.unregister = function (name) {
360
361
  * @param {object} config 配置项
361
362
  * @param {object} script 模块对象
362
363
  */
363
- Manager.prototype.batchRegister = function (files, config = {}, script = {}) {
364
+ Manager.prototype.registerMods = function (files, config = {}, script = {}) {
364
365
  for (let file of files) {
365
- this.register(file, config, script);
366
+ this.registerMod(file, config, script);
366
367
  }
367
368
  };
368
369
 
369
370
  /**
370
371
  * 加载所有模块
371
372
  */
372
- Manager.prototype.loads = async function () {
373
+ Manager.prototype.loadMods = async function () {
373
374
  var promises = [];
374
375
  for (let name in this.mods) {
375
376
  let mod = this.mods[name];
@@ -473,7 +474,7 @@ Manager.prototype.update = async function (dir, clear = true) {
473
474
  // 查找所有json文件
474
475
  let files = this._findFiles(dir || this.config.dir);
475
476
  // 批量注册模块
476
- this.batchRegister(files);
477
+ this.registerMods(files);
477
478
  // 更新配置信息
478
479
  this.updateInfo();
479
480
  if (!this.config.lazy_load) {
@@ -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.2",
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": {