mm_machine 1.7.1 → 1.7.3
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 +8 -4
- package/demo/test2/index.js +4 -1
- package/demo2/test1/index.js +4 -0
- package/demo2/test2/index.js +3 -0
- package/index.js +33 -16
- package/package.json +1 -1
- package/test.js +5 -1
package/demo/test1/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
1
|
var i = 0;
|
|
2
|
+
|
|
3
3
|
function test() {
|
|
4
|
-
console.log("你好
|
|
4
|
+
console.log("你好123", i++)
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
function main() {
|
|
@@ -11,10 +11,14 @@ function main() {
|
|
|
11
11
|
|
|
12
12
|
exports.main = main;
|
|
13
13
|
|
|
14
|
-
exports.main_before = function(){
|
|
14
|
+
exports.main_before = function() {
|
|
15
15
|
console.log("请求前")
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
exports.main_after = function(ret){
|
|
18
|
+
exports.main_after = async function(ret) {
|
|
19
19
|
console.log("请求后", ret)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.init = function() {
|
|
23
|
+
console.log("初始化test");
|
|
20
24
|
}
|
package/demo/test2/index.js
CHANGED
package/demo2/test1/index.js
CHANGED
package/demo2/test2/index.js
CHANGED
package/index.js
CHANGED
|
@@ -515,28 +515,34 @@ Index.prototype.sort = function() {
|
|
|
515
515
|
/**
|
|
516
516
|
* 更新前
|
|
517
517
|
*/
|
|
518
|
-
Index.prototype.update_before = function(dir) {
|
|
518
|
+
Index.prototype.update_before = async function(dir) {
|
|
519
519
|
// console.log("更新前")
|
|
520
520
|
}
|
|
521
521
|
|
|
522
|
-
|
|
523
522
|
/**
|
|
524
523
|
* 更新后
|
|
525
524
|
*/
|
|
526
|
-
Index.prototype.update_after = function(dir) {
|
|
525
|
+
Index.prototype.update_after = async function(dir) {
|
|
527
526
|
// console.log("更新后")
|
|
528
527
|
}
|
|
529
528
|
|
|
530
529
|
/**
|
|
531
|
-
*
|
|
532
|
-
* @param {String} dir 检索的路径
|
|
530
|
+
* 更新
|
|
533
531
|
*/
|
|
534
|
-
Index.prototype.
|
|
535
|
-
this.update_before(dir);
|
|
532
|
+
Index.prototype.update_main = async function(dir) {
|
|
536
533
|
this.clear();
|
|
537
534
|
this.load(dir);
|
|
538
535
|
this.sort();
|
|
539
|
-
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* 更新配置
|
|
540
|
+
* @param {String} dir 检索的路径
|
|
541
|
+
*/
|
|
542
|
+
Index.prototype.update = async function(dir) {
|
|
543
|
+
await this.update_before(dir);
|
|
544
|
+
await this.update_main(dir);
|
|
545
|
+
await this.update_after(dir);
|
|
540
546
|
};
|
|
541
547
|
|
|
542
548
|
/**
|
|
@@ -740,21 +746,32 @@ Index.prototype.reload = function(name) {
|
|
|
740
746
|
|
|
741
747
|
/**
|
|
742
748
|
* 调用函数
|
|
743
|
-
* @param {String} 模块名
|
|
749
|
+
* @param {String} name 模块名
|
|
744
750
|
* @param {String} method 函数名
|
|
745
751
|
* @param {Object} params 参数集合
|
|
746
752
|
* @return {Object} 执行结果
|
|
747
753
|
*/
|
|
748
754
|
Index.prototype.run = async function(name, method, ...params) {
|
|
749
|
-
var o = await this.get(name);
|
|
750
755
|
var ret;
|
|
751
|
-
if (
|
|
752
|
-
|
|
753
|
-
if (
|
|
754
|
-
ret =
|
|
756
|
+
if (name) {
|
|
757
|
+
var o = await this.get(name);
|
|
758
|
+
if (o) {
|
|
759
|
+
ret = o.run(method, params);
|
|
760
|
+
if (util.types.isPromise(ret)) {
|
|
761
|
+
ret = await ret;
|
|
762
|
+
}
|
|
763
|
+
if (this.mode) {
|
|
764
|
+
o.reload();
|
|
765
|
+
}
|
|
755
766
|
}
|
|
756
|
-
|
|
757
|
-
|
|
767
|
+
} else if (name === null) {
|
|
768
|
+
var lt = this.list;
|
|
769
|
+
for (var i = 0; i < lt.length; i++) {
|
|
770
|
+
var o = lt[i];
|
|
771
|
+
ret = o.run(method, params);
|
|
772
|
+
if (util.types.isPromise(ret)) {
|
|
773
|
+
ret = await ret;
|
|
774
|
+
}
|
|
758
775
|
}
|
|
759
776
|
}
|
|
760
777
|
return ret;
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -26,6 +26,10 @@ async function demo() {
|
|
|
26
26
|
var engine = new Engine();
|
|
27
27
|
console.info("→ 加载mod");
|
|
28
28
|
await engine.update("./".fullname(__dirname));
|
|
29
|
+
|
|
30
|
+
engine.run(null, 'init');
|
|
31
|
+
engine.run(undefined, 'init');
|
|
32
|
+
return
|
|
29
33
|
console.log("模块数", engine.list.length);
|
|
30
34
|
|
|
31
35
|
var i = 0;
|
|
@@ -61,7 +65,7 @@ async function demo() {
|
|
|
61
65
|
text = text.replace("123", "7654321");
|
|
62
66
|
file.saveText(text);
|
|
63
67
|
}, 20000)
|
|
64
|
-
|
|
68
|
+
|
|
65
69
|
setTimeout(() => {
|
|
66
70
|
// 让热重载失效
|
|
67
71
|
console.info("→ 热重载失效");
|