mm_machine 2.5.1 → 2.5.2
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.
- package/index.js +9 -1
- package/mod.js +45 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -286,7 +286,15 @@ Manager.prototype.newMod = function (config_file, config, script) {
|
|
|
286
286
|
mod.mode = this.config.mode;
|
|
287
287
|
mod.loadConfig(config_file);
|
|
288
288
|
if (script) {
|
|
289
|
-
|
|
289
|
+
for (let key in script) {
|
|
290
|
+
let obj = script[key];
|
|
291
|
+
if (typeof obj == 'function') {
|
|
292
|
+
mod.setMethod(key, obj);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
mod.setData(key, obj);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
290
298
|
}
|
|
291
299
|
if (config) {
|
|
292
300
|
mod.setConfig(config);
|
package/mod.js
CHANGED
|
@@ -331,8 +331,17 @@ Mod.prototype.unload = async function () {
|
|
|
331
331
|
*/
|
|
332
332
|
Mod.prototype._unloadCore = async function () {
|
|
333
333
|
if (this._methods) {
|
|
334
|
+
for (let key in this._methods) {
|
|
335
|
+
delete this[key];
|
|
336
|
+
}
|
|
334
337
|
this._methods = {};
|
|
335
338
|
}
|
|
339
|
+
if (this._datas) {
|
|
340
|
+
for (let key in this._datas) {
|
|
341
|
+
delete this[key];
|
|
342
|
+
}
|
|
343
|
+
this._datas = {};
|
|
344
|
+
}
|
|
336
345
|
};
|
|
337
346
|
|
|
338
347
|
/**
|
|
@@ -418,6 +427,9 @@ Mod.prototype.setMethods = function (methods) {
|
|
|
418
427
|
this._methods = {};
|
|
419
428
|
}
|
|
420
429
|
Object.assign(this._methods, methods);
|
|
430
|
+
for (let key in this._methods) {
|
|
431
|
+
this[key] = this._methods[key];
|
|
432
|
+
}
|
|
421
433
|
};
|
|
422
434
|
|
|
423
435
|
/**
|
|
@@ -431,6 +443,7 @@ Mod.prototype.setMethod = function (method, func) {
|
|
|
431
443
|
this._methods = {};
|
|
432
444
|
}
|
|
433
445
|
this._methods[method] = func;
|
|
446
|
+
this[method] = this._methods[method];
|
|
434
447
|
};
|
|
435
448
|
|
|
436
449
|
/**
|
|
@@ -446,6 +459,38 @@ Mod.prototype.getMethod = function (method) {
|
|
|
446
459
|
return func;
|
|
447
460
|
};
|
|
448
461
|
|
|
462
|
+
/**
|
|
463
|
+
* 获取数据
|
|
464
|
+
* @returns {object} 数据对象
|
|
465
|
+
*/
|
|
466
|
+
Mod.prototype.getDatas = function () {
|
|
467
|
+
return this._datas;
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* 设置数据
|
|
472
|
+
* @param {object} datas 数据对象
|
|
473
|
+
*/
|
|
474
|
+
Mod.prototype.setDatas = function (datas) {
|
|
475
|
+
if (!this._datas) {
|
|
476
|
+
this._datas = {};
|
|
477
|
+
}
|
|
478
|
+
Object.assign(this._datas, datas);
|
|
479
|
+
for (let key in this._datas) {
|
|
480
|
+
this[key] = this._datas[key];
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* 设置数据
|
|
486
|
+
* @param {string} key 数据键
|
|
487
|
+
* @param {*} value 数据值
|
|
488
|
+
*/
|
|
489
|
+
Mod.prototype.setData = function (key, value) {
|
|
490
|
+
this._datas[key] = value;
|
|
491
|
+
this[key] = value;
|
|
492
|
+
};
|
|
493
|
+
|
|
449
494
|
/**
|
|
450
495
|
* 调用函数(核心执行方法)
|
|
451
496
|
* @param {string} method 函数名
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_machine",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2",
|
|
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": {
|