mm_machine 1.8.5 → 1.8.8

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.
@@ -10,7 +10,7 @@
10
10
  /**
11
11
  * 描述, 用于描述该有什么用的
12
12
  */
13
- "description": "用于测试动态加载、更新、卸载、删除脚本",
13
+ "description": "用于测试动态加载、更新、卸载、删除脚本22",
14
14
  /**
15
15
  * 文件路径, 当调用函数不存在时,会先从文件中加载
16
16
  */
@@ -0,0 +1,13 @@
1
+ class Demo {
2
+ constructor() {}
3
+ }
4
+ var i = 0;
5
+ Demo.prototype.main = function() {
6
+ console.log("我很好123", i++);
7
+ return i;
8
+ }
9
+ Demo.prototype.init = function(){
10
+ console.log("初始化test2");
11
+ }
12
+
13
+ module.exports = new Demo();
@@ -1,4 +1,4 @@
1
- {
1
+ [{
2
2
  /**
3
3
  * 名称, 由中英文和下“_”组成, 用于卸载接口 例如: demo
4
4
  */
@@ -14,7 +14,7 @@
14
14
  /**
15
15
  * 文件路径, 当调用函数不存在时,会先从文件中加载
16
16
  */
17
- "func_file": "./index.js",
17
+ "func_file": "./main.js",
18
18
  /**
19
19
  * 回调函数名 用于决定调用脚本的哪个函数
20
20
  */
@@ -31,4 +31,38 @@
31
31
  * 显示, 0表示不显示, 1表示显示
32
32
  */
33
33
  "show": 0
34
- }
34
+ },
35
+ {
36
+ /**
37
+ * 名称, 由中英文和下“_”组成, 用于卸载接口 例如: demo
38
+ */
39
+ "name": "demo3",
40
+ /**
41
+ * 标题, 介绍作用
42
+ */
43
+ "title": "示例脚本3",
44
+ /**
45
+ * 描述, 用于描述该有什么用的
46
+ */
47
+ "description": "用于测试动态加载、更新、卸载、删除脚本",
48
+ /**
49
+ * 文件路径, 当调用函数不存在时,会先从文件中加载
50
+ */
51
+ "func_file": "./after.js",
52
+ /**
53
+ * 回调函数名 用于决定调用脚本的哪个函数
54
+ */
55
+ "func_name": "main",
56
+ /**
57
+ * 排序
58
+ */
59
+ "sort": 10,
60
+ /**
61
+ * 状态, 0表示未启用, 1表示启用
62
+ */
63
+ "state": 1,
64
+ /**
65
+ * 显示, 0表示不显示, 1表示显示
66
+ */
67
+ "show": 0
68
+ }]
@@ -4,6 +4,7 @@ class Demo {
4
4
  var i = 0;
5
5
  Demo.prototype.main = function() {
6
6
  console.log("我很好123", i++);
7
+ return i;
7
8
  }
8
9
  Demo.prototype.init = function(){
9
10
  console.log("初始化test2");
@@ -5,6 +5,7 @@ var i = 0;
5
5
  Demo.prototype.main = function() {
6
6
  console.log("我很好123", i++);
7
7
  }
8
+
8
9
  Demo.prototype.init = function(){
9
10
  console.log("初始化test2");
10
11
  }
@@ -0,0 +1,13 @@
1
+ class Demo {
2
+ constructor() {}
3
+ }
4
+ var i = 0;
5
+ Demo.prototype.main = function() {
6
+ console.log("我很好123", i++);
7
+ return i;
8
+ }
9
+ Demo.prototype.init = function(){
10
+ console.log("初始化test2");
11
+ }
12
+
13
+ module.exports = new Demo();
@@ -1,4 +1,4 @@
1
- {
1
+ [{
2
2
  /**
3
3
  * 名称, 由中英文和下“_”组成, 用于卸载接口 例如: demo
4
4
  */
@@ -14,7 +14,7 @@
14
14
  /**
15
15
  * 文件路径, 当调用函数不存在时,会先从文件中加载
16
16
  */
17
- "func_file": "./index.js",
17
+ "func_file": "./main.js",
18
18
  /**
19
19
  * 回调函数名 用于决定调用脚本的哪个函数
20
20
  */
@@ -31,4 +31,38 @@
31
31
  * 显示, 0表示不显示, 1表示显示
32
32
  */
33
33
  "show": 0
34
- }
34
+ },
35
+ {
36
+ /**
37
+ * 名称, 由中英文和下“_”组成, 用于卸载接口 例如: demo
38
+ */
39
+ "name": "demo3",
40
+ /**
41
+ * 标题, 介绍作用
42
+ */
43
+ "title": "示例脚本3",
44
+ /**
45
+ * 描述, 用于描述该有什么用的
46
+ */
47
+ "description": "用于测试动态加载、更新、卸载、删除脚本",
48
+ /**
49
+ * 文件路径, 当调用函数不存在时,会先从文件中加载
50
+ */
51
+ "func_file": "./after.js",
52
+ /**
53
+ * 回调函数名 用于决定调用脚本的哪个函数
54
+ */
55
+ "func_name": "main",
56
+ /**
57
+ * 排序
58
+ */
59
+ "sort": 10,
60
+ /**
61
+ * 状态, 0表示未启用, 1表示启用
62
+ */
63
+ "state": 1,
64
+ /**
65
+ * 显示, 0表示不显示, 1表示显示
66
+ */
67
+ "show": 0
68
+ }]
@@ -0,0 +1,13 @@
1
+ class Demo {
2
+ constructor() {}
3
+ }
4
+ var i = 0;
5
+ Demo.prototype.main = function() {
6
+ console.log("我很好123", i++);
7
+ }
8
+
9
+ Demo.prototype.init = function(){
10
+ console.log("初始化test2");
11
+ }
12
+
13
+ module.exports = new Demo();
package/index.js CHANGED
@@ -99,7 +99,7 @@ Item.prototype.set_config = function(config) {
99
99
  * 设置配置后
100
100
  */
101
101
  Item.prototype.set_config_after = function() {
102
-
102
+
103
103
  };
104
104
 
105
105
  /**
@@ -211,15 +211,15 @@ Item.prototype.loadFile = function(file) {
211
211
  var text = f.loadText();
212
212
  if (!text) {
213
213
  this.new_config(f);
214
- text = f.loadText();
215
214
  }
216
215
  if (text) {
217
216
  obj = $.loadJson(f, (mod) => {
218
- if (mod) {
217
+ if (mod && !Array.isArray(mod)) {
219
218
  this.set_config(mod);
220
219
  }
221
220
  });
222
221
  }
222
+ this.dir = f.dirname();
223
223
  this.filename = f;
224
224
  return obj;
225
225
  };
@@ -428,7 +428,7 @@ class Index {
428
428
  /**
429
429
  * 模式 0生产模式,1开发模式,2热重载模式
430
430
  */
431
- this.mode = 0;
431
+ this.mode = 2;
432
432
  }
433
433
  }
434
434
 
@@ -451,10 +451,30 @@ Index.prototype.Drive = Item;
451
451
  * @param {String} file 配置文件
452
452
  */
453
453
  Index.prototype.load_item = function(dir, cg, file) {
454
- var drive = new this.Drive(dir);
455
- drive.filename = file;
456
- drive.loadObj(cg);
457
- this.list.push(drive);
454
+ if (this.Drive) {
455
+ var drive = new this.Drive(dir);
456
+ if (cg) {
457
+ drive.file = file;
458
+ drive.loadObj(cg);
459
+ } else {
460
+ drive.load(file);
461
+ }
462
+ this.list.push(drive);
463
+ return drive;
464
+ } else {
465
+ var json = file.loadJson();
466
+ if (!json) {
467
+ var fl = this.dir_base + "/config.tpl.json";
468
+ if (fl.hasFile()) {
469
+ fl.copyFile(file);
470
+ json = file.loadJson();
471
+ }
472
+ }
473
+ if (json) {
474
+ this.list.push(json);
475
+ }
476
+ return json;
477
+ }
458
478
  };
459
479
 
460
480
  /**
@@ -462,44 +482,9 @@ Index.prototype.load_item = function(dir, cg, file) {
462
482
  * @param {Array} list 文件列表
463
483
  */
464
484
  Index.prototype.load_list = function(list) {
465
- var _this = this;
466
485
  // 遍历文件路径
467
- list.map(function(file) {
468
- var dir = file.dirname();
469
- // 载入文件
470
- var obj;
471
- if (_this.mode) {
472
- obj = $.loadJson(file, function(config) {
473
- if (config.name) {
474
- var plug = _this.get(config.name);
475
- if (plug) {
476
- plug.set_config(config);
477
- }
478
- }
479
- });
480
- } else {
481
- obj = file.loadJson(dir)
482
- }
483
- if (obj) {
484
- if (obj.constructor == Array) {
485
- obj.map(function(o) {
486
- // 实例化一个驱动
487
- _this.load_item(dir, o, file);
488
- });
489
- } else {
490
- _this.load_item(dir, obj, file);
491
- }
492
- } else {
493
- if (_this.Drive) {
494
- var drive = new _this.Drive();
495
- drive.new_config(file);
496
- } else {
497
- var fl = _this.dir_base + "/config.tpl.json";
498
- if (fl.hasFile()) {
499
- fl.copyFile(file);
500
- }
501
- }
502
- }
486
+ list.map((file) => {
487
+ this.load_file(file, true);
503
488
  });
504
489
  };
505
490
 
@@ -526,8 +511,7 @@ Index.prototype.load = function(path, accurate) {
526
511
  search_dir = this.type;
527
512
  }
528
513
  list_scope = $.dir.getAll(path, search_dir);
529
- }
530
- else {
514
+ } else {
531
515
  list_scope = $.dir.getAll(path);
532
516
  }
533
517
 
@@ -742,28 +726,25 @@ Index.prototype.unload = function(name, remove) {
742
726
  /**
743
727
  * 通过文件加载配置
744
728
  * @param {String} file 文件名
729
+ * @param {Boolean} create 不存在则进行创建
745
730
  * @return {String} 加载失败返回错误提示,加载成功返回null
746
731
  */
747
- Index.prototype.load_file = function(file) {
748
- if (file.hasFile()) {
749
- var obj = file.loadJson();
750
- if (obj) {
751
- var dir = file.dirname();
752
- var _this = this;
753
- if (obj.constructor == Array) {
754
- obj.map(function(o) {
755
- if (!_this.get(o.name)) {
756
- _this.load_item(dir, o, file);
757
- }
758
- });
759
- } else {
760
- if (!_this.get(obj.name)) {
761
- _this.load_item(dir, obj, file);
762
- }
763
- }
732
+ Index.prototype.load_file = function(file, create = false) {
733
+ var _this = this;
734
+ var dir = file.dirname();
735
+ // 载入文件
736
+ var obj = file.loadJson();
737
+ if (obj) {
738
+ if (obj.constructor == Array) {
739
+ obj.map(function(o) {
740
+ // 实例化一个驱动
741
+ _this.load_item(dir, o, file);
742
+ });
764
743
  } else {
765
- return "配置文件格式错误";
744
+ return _this.load_item(dir, null, file);
766
745
  }
746
+ } else if (create) {
747
+ return _this.load_item(dir, null, file);
767
748
  } else {
768
749
  return file + "文件不存在";
769
750
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "1.8.5",
3
+ "version": "1.8.8",
4
4
  "description": "这是超级美眉框架机制构建辅助模块,用于快速构建一个机制",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test.js CHANGED
@@ -35,6 +35,10 @@ async function demo() {
35
35
  if (plug) {
36
36
  plug.loadFile(plug.filename);
37
37
  }
38
+
39
+ var i = await engine.run('demo3', 'main');
40
+ console.log("指明回调demo3", i);
41
+
38
42
  // console.log("模块数", engine.list.length);
39
43
 
40
44
  // var i = 0;