mm_machine 1.9.2 → 1.9.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.
- package/demo/test1/index.js +1 -1
- package/index.js +19 -19
- package/item.js +12 -2
- package/package.json +1 -1
- package/test.js +11 -11
package/demo/test1/index.js
CHANGED
package/index.js
CHANGED
|
@@ -78,10 +78,10 @@ Index.prototype.load_item = async function(dir, cg, file) {
|
|
|
78
78
|
var drive = new this.Drive(dir, this.dir_base.fullname());
|
|
79
79
|
drive.mode = this.mode;
|
|
80
80
|
if (cg) {
|
|
81
|
-
await drive.
|
|
82
|
-
drive.set_config
|
|
81
|
+
await drive.exec('load_config', file, cg.name);
|
|
82
|
+
await drive.exec('set_config', cg);
|
|
83
83
|
} else {
|
|
84
|
-
await drive.
|
|
84
|
+
await drive.exec('load_config', file);
|
|
85
85
|
}
|
|
86
86
|
this.list.push(drive);
|
|
87
87
|
return drive;
|
|
@@ -195,12 +195,12 @@ Index.prototype.update_config_have = async function(dir) {
|
|
|
195
195
|
for (var n = 0; n < lt.length; n++) {
|
|
196
196
|
var cg = lt[n];
|
|
197
197
|
if (cg.name == o.config.name) {
|
|
198
|
-
o.set_config
|
|
198
|
+
await o.exec('set_config', cg);
|
|
199
199
|
continue;
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
} else {
|
|
203
|
-
o.set_config
|
|
203
|
+
await o.exec('set_config', config);
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
}
|
|
@@ -230,7 +230,7 @@ Index.prototype.update_script = async function() {
|
|
|
230
230
|
for (var i = 0; i < list.length; i++) {
|
|
231
231
|
var o = list[i];
|
|
232
232
|
if (o.config.state === 1) {
|
|
233
|
-
await o.
|
|
233
|
+
await o.exec('load');
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
}
|
|
@@ -391,7 +391,7 @@ Index.prototype.load = async function(name) {
|
|
|
391
391
|
var o = this.get(name);
|
|
392
392
|
var file = null;
|
|
393
393
|
if (o) {
|
|
394
|
-
await o.
|
|
394
|
+
await o.exec('load');
|
|
395
395
|
file = o.filename;
|
|
396
396
|
}
|
|
397
397
|
return file;
|
|
@@ -407,7 +407,7 @@ Index.prototype.unload = async function(name, remove) {
|
|
|
407
407
|
var o = this.del(name, remove);
|
|
408
408
|
var file = null;
|
|
409
409
|
if (o) {
|
|
410
|
-
await o.
|
|
410
|
+
await o.exec('unload', remove);
|
|
411
411
|
file = o.filename;
|
|
412
412
|
}
|
|
413
413
|
return file;
|
|
@@ -421,7 +421,7 @@ Index.prototype.unload = async function(name, remove) {
|
|
|
421
421
|
Index.prototype.reload = async function(name) {
|
|
422
422
|
var o = this.get(name);
|
|
423
423
|
if (o) {
|
|
424
|
-
await o.
|
|
424
|
+
await o.exec('reload');
|
|
425
425
|
return o.filename;
|
|
426
426
|
}
|
|
427
427
|
return '没有找到模块';
|
|
@@ -468,14 +468,14 @@ Index.prototype.run = async function(name, method, ...params) {
|
|
|
468
468
|
if (name) {
|
|
469
469
|
var o = await this.get(name);
|
|
470
470
|
if (o && o.config.state === 1) {
|
|
471
|
-
var ret = o.
|
|
471
|
+
var ret = o.exec(method, ...params);
|
|
472
472
|
if (util.types.isPromise(ret)) {
|
|
473
473
|
result = await ret;
|
|
474
474
|
} else {
|
|
475
475
|
result = ret;
|
|
476
476
|
}
|
|
477
477
|
if (this.mode >= 4) {
|
|
478
|
-
o.
|
|
478
|
+
o.exec('reload');
|
|
479
479
|
}
|
|
480
480
|
}
|
|
481
481
|
} else if (name === null) {
|
|
@@ -483,14 +483,14 @@ Index.prototype.run = async function(name, method, ...params) {
|
|
|
483
483
|
for (var i = 0; i < lt.length; i++) {
|
|
484
484
|
var o = lt[i];
|
|
485
485
|
if (o.config.state === 1) {
|
|
486
|
-
var ret = o.
|
|
486
|
+
var ret = o.exec(method, ...params);
|
|
487
487
|
if (util.types.isPromise(ret)) {
|
|
488
488
|
result = await ret;
|
|
489
489
|
} else {
|
|
490
490
|
result = ret;
|
|
491
491
|
}
|
|
492
492
|
if (this.mode >= 4) {
|
|
493
|
-
o.
|
|
493
|
+
o.exec('reload');
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
496
|
}
|
|
@@ -511,16 +511,16 @@ Index.prototype.exec = async function(name, method, ...params) {
|
|
|
511
511
|
var o = await this.get(name);
|
|
512
512
|
if (o) {
|
|
513
513
|
if (!o.complete) {
|
|
514
|
-
await o.
|
|
514
|
+
await o.exec('load');
|
|
515
515
|
}
|
|
516
|
-
var ret = o.
|
|
516
|
+
var ret = o.exec(method, ...params);
|
|
517
517
|
if (util.types.isPromise(ret)) {
|
|
518
518
|
result = await ret;
|
|
519
519
|
} else {
|
|
520
520
|
result = ret;
|
|
521
521
|
}
|
|
522
522
|
if (this.mode >= 4) {
|
|
523
|
-
await o.
|
|
523
|
+
await o.exec('reload');
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
526
|
} else if (name === null) {
|
|
@@ -528,16 +528,16 @@ Index.prototype.exec = async function(name, method, ...params) {
|
|
|
528
528
|
for (var i = 0; i < lt.length; i++) {
|
|
529
529
|
var o = lt[i];
|
|
530
530
|
if (!o.complete) {
|
|
531
|
-
await o.
|
|
531
|
+
await o.exec('load');
|
|
532
532
|
}
|
|
533
|
-
var ret = o.
|
|
533
|
+
var ret = o.exec(method, ...params);
|
|
534
534
|
if (util.types.isPromise(ret)) {
|
|
535
535
|
result = await ret;
|
|
536
536
|
} else {
|
|
537
537
|
result = ret;
|
|
538
538
|
}
|
|
539
539
|
if (this.mode >= 4) {
|
|
540
|
-
await o.
|
|
540
|
+
await o.exec('reload');
|
|
541
541
|
}
|
|
542
542
|
}
|
|
543
543
|
}
|
package/item.js
CHANGED
|
@@ -98,7 +98,6 @@ class Item {
|
|
|
98
98
|
*/
|
|
99
99
|
Item.prototype.set_config = function(config) {
|
|
100
100
|
this.config = conf(Object.assign({}, this.config, config || {}), this.filename);
|
|
101
|
-
this.set_config_after();
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
/**
|
|
@@ -247,6 +246,7 @@ Item.prototype.load_file = function(file, name) {
|
|
|
247
246
|
var o = list[i];
|
|
248
247
|
if (this.config.name === o.name) {
|
|
249
248
|
this.set_config(o);
|
|
249
|
+
this.set_config_after();
|
|
250
250
|
if (this.mode === 3 || this.mode === 4) {
|
|
251
251
|
this.reload_script();
|
|
252
252
|
}
|
|
@@ -255,6 +255,7 @@ Item.prototype.load_file = function(file, name) {
|
|
|
255
255
|
}
|
|
256
256
|
} else {
|
|
257
257
|
this.set_config(conf);
|
|
258
|
+
this.set_config_after();
|
|
258
259
|
if (this.mode === 3 || this.mode === 4) {
|
|
259
260
|
this.reload_script();
|
|
260
261
|
}
|
|
@@ -349,6 +350,7 @@ Item.prototype.load_config = function(cg, name) {
|
|
|
349
350
|
config = this.load_file(this.filename, name);
|
|
350
351
|
}
|
|
351
352
|
this.set_config(config);
|
|
353
|
+
this.set_config_after();
|
|
352
354
|
};
|
|
353
355
|
|
|
354
356
|
/**
|
|
@@ -409,13 +411,21 @@ Item.prototype.main = async function(...params) {
|
|
|
409
411
|
return null;
|
|
410
412
|
};
|
|
411
413
|
|
|
414
|
+
/**
|
|
415
|
+
* 运行
|
|
416
|
+
* @param {Object} params 参数集合
|
|
417
|
+
*/
|
|
418
|
+
Item.prototype.run = async function(...params) {
|
|
419
|
+
return await this.exec("main", ...params);
|
|
420
|
+
}
|
|
421
|
+
|
|
412
422
|
/**
|
|
413
423
|
* 调用函数
|
|
414
424
|
* @param {String} method 函数名
|
|
415
425
|
* @param {Object} params 参数集合
|
|
416
426
|
* @return {Object} 执行结果
|
|
417
427
|
*/
|
|
418
|
-
Item.prototype.
|
|
428
|
+
Item.prototype.exec = async function(method, ...params) {
|
|
419
429
|
if (this[method]) {
|
|
420
430
|
var ret;
|
|
421
431
|
if (this[method + "_before"]) {
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -76,12 +76,12 @@ async function demo() {
|
|
|
76
76
|
console.log("这结果", ret);
|
|
77
77
|
}, 7000)
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
setTimeout(() => {
|
|
80
|
+
var file = "./demo/test2/index.js";
|
|
81
|
+
var text = file.loadText();
|
|
82
|
+
text = text.replace("123", "7654321");
|
|
83
|
+
file.saveText(text);
|
|
84
|
+
}, 11000)
|
|
85
85
|
|
|
86
86
|
setTimeout(async () => {
|
|
87
87
|
// 让热重载失效
|
|
@@ -105,11 +105,11 @@ async function demo() {
|
|
|
105
105
|
if (plug) {
|
|
106
106
|
console.log("查看变化1", plug.config);
|
|
107
107
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
var plug = engine.get("demo3");
|
|
109
|
+
if (plug) {
|
|
110
|
+
var ret = await plug.run();
|
|
111
|
+
console.log("查看变化3", plug.config);
|
|
112
|
+
}
|
|
113
113
|
n++;
|
|
114
114
|
if (n == 6) {
|
|
115
115
|
clearInterval(timer_2);
|