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.
- package/demo/test1/demo.json +1 -1
- package/demo/test2/after.js +13 -0
- package/demo/test2/demo.json +37 -3
- package/demo/test2/index.js +1 -0
- package/{demo2/test2/index.js → demo/test2/main.js} +1 -0
- package/demo2/test2/after.js +13 -0
- package/demo2/test2/demo.json +37 -3
- package/demo2/test2/main.js +13 -0
- package/index.js +46 -65
- package/package.json +1 -1
- package/test.js +4 -0
package/demo/test1/demo.json
CHANGED
package/demo/test2/demo.json
CHANGED
|
@@ -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": "./
|
|
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
|
+
}]
|
package/demo/test2/index.js
CHANGED
package/demo2/test2/demo.json
CHANGED
|
@@ -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": "./
|
|
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
|
+
}]
|
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 =
|
|
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
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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(
|
|
468
|
-
|
|
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
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
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