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.
@@ -1,7 +1,7 @@
1
-
2
1
  var i = 0;
2
+
3
3
  function test() {
4
- console.log("你好7654321", i++)
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
  }
@@ -3,7 +3,10 @@ class Demo {
3
3
  }
4
4
  var i = 0;
5
5
  Demo.prototype.main = function() {
6
- console.log("我很好7654321", i++);
6
+ console.log("我很好123", i++);
7
+ }
8
+ Demo.prototype.init = function(){
9
+ console.log("初始化test2");
7
10
  }
8
11
 
9
12
  module.exports = new Demo();
@@ -17,4 +17,8 @@ exports.main_before = function() {
17
17
 
18
18
  exports.main_after = async function(ret) {
19
19
  console.log("请求后", ret)
20
+ }
21
+
22
+ exports.init = function() {
23
+ console.log("初始化test");
20
24
  }
@@ -5,5 +5,8 @@ var i = 0;
5
5
  Demo.prototype.main = function() {
6
6
  console.log("我很好123", i++);
7
7
  }
8
+ Demo.prototype.init = function(){
9
+ console.log("初始化test2");
10
+ }
8
11
 
9
12
  module.exports = new Demo();
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.update = function(dir) {
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
- this.update_after(dir);
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 (o) {
752
- ret = o.run(method, params);
753
- if (util.types.isPromise(ret)) {
754
- ret = await 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
- if (this.mode) {
757
- o.reload();
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "1.7.1",
3
+ "version": "1.7.3",
4
4
  "description": "这是超级美眉框架机制构建辅助模块,用于快速构建一个机制",
5
5
  "main": "index.js",
6
6
  "scripts": {
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("→ 热重载失效");