mm_machine 2.9.5 → 2.9.7
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/mod.js +22 -5
- package/package.json +1 -1
package/mod.js
CHANGED
|
@@ -120,12 +120,18 @@ Mod.prototype._loadCore = async function () {
|
|
|
120
120
|
* @private
|
|
121
121
|
*/
|
|
122
122
|
Mod.prototype._initCore = async function () {
|
|
123
|
+
// 如果已初始化,跳过
|
|
124
|
+
if (this.lifecycle_state === 'inited') {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
// 如果是 created 状态,自动加载
|
|
128
|
+
if (this.lifecycle_state === 'created') {
|
|
129
|
+
await this.load();
|
|
130
|
+
}
|
|
123
131
|
if (this.lifecycle_state !== 'loaded') {
|
|
124
132
|
throw new Error('模块未加载,无法初始化');
|
|
125
133
|
}
|
|
126
134
|
|
|
127
|
-
this.emit('init:before');
|
|
128
|
-
|
|
129
135
|
try {
|
|
130
136
|
var init_hook = this.getMethod('_init');
|
|
131
137
|
if (init_hook) {
|
|
@@ -319,7 +325,8 @@ Mod.prototype.isLoaded = function () {
|
|
|
319
325
|
*/
|
|
320
326
|
Mod.prototype.log = function (level, message) {
|
|
321
327
|
var logger = this.getLogger ? this.getLogger() : console;
|
|
322
|
-
var prefix =
|
|
328
|
+
var prefix =
|
|
329
|
+
'[' + (this.constructor.name || 'Mod') + '.' + ((this.config && this.config.name) || '') + ']';
|
|
323
330
|
if (logger[level]) {
|
|
324
331
|
logger[level](prefix + ' ' + message);
|
|
325
332
|
} else {
|
|
@@ -567,7 +574,12 @@ Mod.prototype.saveDatas = function () {
|
|
|
567
574
|
var path = require('path');
|
|
568
575
|
var file = (this.config && this.config.cache_file) || '';
|
|
569
576
|
if (!file) {
|
|
570
|
-
file = path.resolve(
|
|
577
|
+
file = path.resolve(
|
|
578
|
+
process.cwd(),
|
|
579
|
+
'cache',
|
|
580
|
+
(this.config && this.config.name) || 'mod',
|
|
581
|
+
'data.json'
|
|
582
|
+
);
|
|
571
583
|
}
|
|
572
584
|
var dir = path.dirname(file);
|
|
573
585
|
if (!fs.existsSync(dir)) {
|
|
@@ -585,7 +597,12 @@ Mod.prototype.loadDatas = function () {
|
|
|
585
597
|
var path = require('path');
|
|
586
598
|
var file = (this.config && this.config.cache_file) || '';
|
|
587
599
|
if (!file) {
|
|
588
|
-
file = path.resolve(
|
|
600
|
+
file = path.resolve(
|
|
601
|
+
process.cwd(),
|
|
602
|
+
'cache',
|
|
603
|
+
(this.config && this.config.name) || 'mod',
|
|
604
|
+
'data.json'
|
|
605
|
+
);
|
|
589
606
|
}
|
|
590
607
|
try {
|
|
591
608
|
if (fs.existsSync(file)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_machine",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.7",
|
|
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": {
|