mm_os 2.5.9 → 2.6.1
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/core/com/api/drive.js +22 -0
- package/core/com/cmd/drive.js +22 -0
- package/core/com/mqtt/drive.js +21 -0
- package/core/com/plugin/drive.js +56 -0
- package/core/com/plugin/log.js +156 -0
- package/core/com/plugin/script.js +21 -3
- package/core/com/socket/drive.js +22 -0
- package/core/com/task/drive.js +22 -0
- package/demo/app/test/plugin/main/api_demo_client/test/index.js +20 -4
- package/demo/app/test/plugin/main/index.js +14 -2
- package/demo/app/test/{task → plugin/main/task}/demo_task/index.js +1 -1
- package/package.json +3 -3
- package/static/file/image/user/1/2024_12_19_15_52_28.png +0 -0
- package/static/file/image/user/1/2024_12_20_15_51_59.png +0 -0
- package/static/file/image/user/29/2024_12_20_10_16_13.png +0 -0
- package/static/file/image/user/29/2024_12_20_10_19_09.png +0 -0
- package/static/file/image/user/968/2024_12_20_16_18_55.png +0 -0
- /package/demo/app/test/{task → plugin/main/task}/demo_task/task.json +0 -0
package/core/com/api/drive.js
CHANGED
|
@@ -720,4 +720,26 @@ Drive.prototype.runRPC = async function(db, method, query, body) {
|
|
|
720
720
|
return ret;
|
|
721
721
|
};
|
|
722
722
|
|
|
723
|
+
/**
|
|
724
|
+
* 获取插件
|
|
725
|
+
* @param {String} app 应用名称
|
|
726
|
+
* @param {String} name 插件名称
|
|
727
|
+
* @returns {Object} 返回获取到的插件
|
|
728
|
+
*/
|
|
729
|
+
Drive.prototype.plugin = function(app, name) {
|
|
730
|
+
var plus;
|
|
731
|
+
var l = $.slash;
|
|
732
|
+
if (!app) {
|
|
733
|
+
app = this.filename.between("app" + l, l);
|
|
734
|
+
}
|
|
735
|
+
if (!name) {
|
|
736
|
+
name = this.filename.between("plugin" + l, l);
|
|
737
|
+
}
|
|
738
|
+
var plugins = $.pool.plugin[app];
|
|
739
|
+
if (plugins) {
|
|
740
|
+
plus = plugins.get(name);
|
|
741
|
+
}
|
|
742
|
+
return plus
|
|
743
|
+
}
|
|
744
|
+
|
|
723
745
|
module.exports = Drive;
|
package/core/com/cmd/drive.js
CHANGED
|
@@ -519,4 +519,26 @@ Drive.prototype.view = function(msg, db) {
|
|
|
519
519
|
return ret.trim();
|
|
520
520
|
};
|
|
521
521
|
|
|
522
|
+
/**
|
|
523
|
+
* 获取插件
|
|
524
|
+
* @param {String} app 应用名称
|
|
525
|
+
* @param {String} name 插件名称
|
|
526
|
+
* @returns {Object} 返回获取到的插件
|
|
527
|
+
*/
|
|
528
|
+
Drive.prototype.plugin = function(app, name) {
|
|
529
|
+
var plus;
|
|
530
|
+
var l = $.slash;
|
|
531
|
+
if (!app) {
|
|
532
|
+
app = this.filename.between("app" + l, l);
|
|
533
|
+
}
|
|
534
|
+
if (!name) {
|
|
535
|
+
name = this.filename.between("plugin" + l, l);
|
|
536
|
+
}
|
|
537
|
+
var plugins = $.pool.plugin[app];
|
|
538
|
+
if (plugins) {
|
|
539
|
+
plus = plugins.get(name);
|
|
540
|
+
}
|
|
541
|
+
return plus
|
|
542
|
+
}
|
|
543
|
+
|
|
522
544
|
module.exports = Drive;
|
package/core/com/mqtt/drive.js
CHANGED
|
@@ -568,5 +568,26 @@ Drive.prototype.main_after = async function(ret, push_topic, msg, topic, index)
|
|
|
568
568
|
await this.message(push_topic, msg, topic, index);
|
|
569
569
|
};
|
|
570
570
|
|
|
571
|
+
/**
|
|
572
|
+
* 获取插件
|
|
573
|
+
* @param {String} app 应用名称
|
|
574
|
+
* @param {String} name 插件名称
|
|
575
|
+
* @returns {Object} 返回获取到的插件
|
|
576
|
+
*/
|
|
577
|
+
Drive.prototype.plugin = function(app, name) {
|
|
578
|
+
var plus;
|
|
579
|
+
var l = $.slash;
|
|
580
|
+
if (!app) {
|
|
581
|
+
app = this.filename.between("app" + l, l);
|
|
582
|
+
}
|
|
583
|
+
if (!name) {
|
|
584
|
+
name = this.filename.between("plugin" + l, l);
|
|
585
|
+
}
|
|
586
|
+
var plugins = $.pool.plugin[app];
|
|
587
|
+
if (plugins) {
|
|
588
|
+
plus = plugins.get(name);
|
|
589
|
+
}
|
|
590
|
+
return plus
|
|
591
|
+
}
|
|
571
592
|
|
|
572
593
|
module.exports = Drive;
|
package/core/com/plugin/drive.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const Item = require('mm_machine').Item;
|
|
2
|
+
const Log = require('./log.js');
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Plugin插件驱动类
|
|
@@ -66,6 +67,61 @@ class Drive extends Item {
|
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
/**
|
|
71
|
+
* 插件初始化之后
|
|
72
|
+
*/
|
|
73
|
+
Drive.prototype.init_after = function() {
|
|
74
|
+
var file = this.filename;
|
|
75
|
+
var filename = file.replace('app', 'log').replace($.slash + 'plugin', '').replace('json', 'log').replace($
|
|
76
|
+
.slash + 'plugin.log', '.log');
|
|
77
|
+
this.log = new Log({
|
|
78
|
+
filename
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 重启设备
|
|
84
|
+
* @param {Object} option 配置
|
|
85
|
+
*/
|
|
86
|
+
Drive.prototype.restart = function(option) {
|
|
87
|
+
this.stop();
|
|
88
|
+
this.start();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 更新配置
|
|
93
|
+
*/
|
|
94
|
+
Drive.prototype.update_options = function(options = []) {
|
|
95
|
+
var op = this.config.options;
|
|
96
|
+
var list = [];
|
|
97
|
+
for (var i = options.length - 1; i >= 0; i--) {
|
|
98
|
+
var o = options[i];
|
|
99
|
+
var obj = op.get({
|
|
100
|
+
name: o.name
|
|
101
|
+
});
|
|
102
|
+
if (obj) {
|
|
103
|
+
Object.assign(obj, o);
|
|
104
|
+
} else {
|
|
105
|
+
list.push(o);
|
|
106
|
+
// options.splice(i, 1);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (var i = 0; i < options.length; i++) {
|
|
110
|
+
var o = options[i];
|
|
111
|
+
op.push(o);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 更新配置后
|
|
117
|
+
* @param {Object} options
|
|
118
|
+
*/
|
|
119
|
+
Drive.prototype.update_options_after = function(options) {
|
|
120
|
+
// if (this.config.state) {
|
|
121
|
+
// this.restart();
|
|
122
|
+
// }
|
|
123
|
+
}
|
|
124
|
+
|
|
69
125
|
/**
|
|
70
126
|
* 获取配置参数
|
|
71
127
|
* @return {Object} 返回配置参数
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 日志类
|
|
3
|
+
*/
|
|
4
|
+
class Log {
|
|
5
|
+
/**
|
|
6
|
+
* 构造函数
|
|
7
|
+
* @param {Object} config 配置参数
|
|
8
|
+
*/
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = {
|
|
11
|
+
filename: '/log/output.log',
|
|
12
|
+
console: false
|
|
13
|
+
};
|
|
14
|
+
this.init(config);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 初始化
|
|
20
|
+
* @returns {Object} 配置参数
|
|
21
|
+
*/
|
|
22
|
+
Log.prototype.init = function(config) {
|
|
23
|
+
Object.assign(this.config, config);
|
|
24
|
+
this.config.filename.addDir();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 加载日志
|
|
29
|
+
* @returns {String} 返回日志内容
|
|
30
|
+
*/
|
|
31
|
+
Log.prototype.load = function() {
|
|
32
|
+
return this.config.filename.loadText() || "";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 保存日志
|
|
37
|
+
* @param {String} text 日志
|
|
38
|
+
*/
|
|
39
|
+
Log.prototype.save = function(text) {
|
|
40
|
+
return this.config.filename.saveText(text);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 读取日志指定条
|
|
45
|
+
* @param {Number} index 索引,默认为最后一条
|
|
46
|
+
*/
|
|
47
|
+
Log.prototype.read = function(index = -1) {
|
|
48
|
+
var text = this.load();
|
|
49
|
+
var arr = text.split(/\n\[/);
|
|
50
|
+
if (index < 0) {
|
|
51
|
+
index = arr.length - 1;
|
|
52
|
+
}
|
|
53
|
+
var str = arr[index];
|
|
54
|
+
if (index == 0) {
|
|
55
|
+
return str;
|
|
56
|
+
}
|
|
57
|
+
return "[" + str;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 获取日志列表
|
|
62
|
+
* @returns {Array} 返回日志列表
|
|
63
|
+
*/
|
|
64
|
+
Log.prototype.list = function() {
|
|
65
|
+
var text = this.load();
|
|
66
|
+
var arr = text.split(/\n\[/);
|
|
67
|
+
return arr.map((str, i) => {
|
|
68
|
+
if (i == 0) {
|
|
69
|
+
return str;
|
|
70
|
+
}
|
|
71
|
+
return "[" + str;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 添加日志
|
|
77
|
+
* @param {String} type 日志类型
|
|
78
|
+
* @param {String} tag 日志标签
|
|
79
|
+
* @param {Object} arg 其他要输出的信息
|
|
80
|
+
*/
|
|
81
|
+
Log.prototype.add = function(type, tag, ...arg) {
|
|
82
|
+
var now = new Date();
|
|
83
|
+
var datetime = now.toStr('yyyy-MM-dd hh:mm:ss');
|
|
84
|
+
var list = new Array(arg);
|
|
85
|
+
var content = "";
|
|
86
|
+
for (var i = 0; i < list.length; i++) {
|
|
87
|
+
var o = list[i];
|
|
88
|
+
content += " " + o.toString();
|
|
89
|
+
}
|
|
90
|
+
var str = `\n[${datetime}] [${type}] ${tag} -` + content;
|
|
91
|
+
var text = this.load();
|
|
92
|
+
text += str;
|
|
93
|
+
this.save(text.trim());
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @description 信息
|
|
98
|
+
* @param {String} tag 日志标签
|
|
99
|
+
* @param {Object} arg 其他要输出的信息
|
|
100
|
+
*/
|
|
101
|
+
Log.prototype.debug = function(tag, ...arg) {
|
|
102
|
+
if (this.config.console) {
|
|
103
|
+
console.log(tag, ...arg);
|
|
104
|
+
}
|
|
105
|
+
this.add('debug', tag, ...arg);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @description 信息
|
|
110
|
+
* @param {String} tag 日志标签
|
|
111
|
+
* @param {Object} arg 其他要输出的信息
|
|
112
|
+
*/
|
|
113
|
+
Log.prototype.info = function(tag, ...arg) {
|
|
114
|
+
if (this.config.console) {
|
|
115
|
+
console.info(tag.blue, ...arg);
|
|
116
|
+
}
|
|
117
|
+
this.add('info', tag, ...arg);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @description 信息
|
|
122
|
+
* @param {String} tag 日志标签
|
|
123
|
+
* @param {Object} arg 其他要输出的信息
|
|
124
|
+
*/
|
|
125
|
+
Log.prototype.warn = function(tag, ...arg) {
|
|
126
|
+
if (this.config.console) {
|
|
127
|
+
console.warn(tag.yellow, ...arg);
|
|
128
|
+
}
|
|
129
|
+
this.add('warn', tag, ...arg);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @description 信息
|
|
134
|
+
* @param {String} tag 日志标签
|
|
135
|
+
* @param {Object} arg 其他要输出的信息
|
|
136
|
+
*/
|
|
137
|
+
Log.prototype.error = function(tag, ...arg) {
|
|
138
|
+
if (this.config.console) {
|
|
139
|
+
console.error(tag.red, ...arg);
|
|
140
|
+
}
|
|
141
|
+
this.add('error', tag, ...arg);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @description 成功
|
|
146
|
+
* @param {String} tag 日志标签
|
|
147
|
+
* @param {Object} arg 其他要输出的信息
|
|
148
|
+
*/
|
|
149
|
+
Log.prototype.success = function(tag, ...arg) {
|
|
150
|
+
if (this.config.console) {
|
|
151
|
+
console.success(tag.green, ...arg);
|
|
152
|
+
}
|
|
153
|
+
this.add('debug', tag, ...arg);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
module.exports = Log;
|
|
@@ -67,7 +67,17 @@ module.exports = {
|
|
|
67
67
|
var msg = null;
|
|
68
68
|
return msg;
|
|
69
69
|
},
|
|
70
|
-
|
|
70
|
+
/**
|
|
71
|
+
* 重启,如果插件处于开启状态,当配置发生更改时或插件更新时会执行重启
|
|
72
|
+
* @param {Object} option 配置参数
|
|
73
|
+
* @return {String} 成功返回null,否则返回错误提示
|
|
74
|
+
*/
|
|
75
|
+
restart(option) {
|
|
76
|
+
var msg = null;
|
|
77
|
+
this.stop();
|
|
78
|
+
this.start();
|
|
79
|
+
return msg;
|
|
80
|
+
},
|
|
71
81
|
/**
|
|
72
82
|
* 结束
|
|
73
83
|
* @param {Object} opiton 配置参数
|
|
@@ -77,7 +87,15 @@ module.exports = {
|
|
|
77
87
|
var msg = null;
|
|
78
88
|
return msg;
|
|
79
89
|
},
|
|
80
|
-
|
|
90
|
+
/**
|
|
91
|
+
* 更新配置后,当用户在后台更改配置时触发
|
|
92
|
+
* @param {Object} options
|
|
93
|
+
*/
|
|
94
|
+
update_options_after = function(options) {
|
|
95
|
+
if (this.config.state) {
|
|
96
|
+
this.restart();
|
|
97
|
+
}
|
|
98
|
+
},
|
|
81
99
|
/**
|
|
82
100
|
* 插件
|
|
83
101
|
* @param {String} item 插件项
|
|
@@ -141,4 +159,4 @@ module.exports = {
|
|
|
141
159
|
var ret = "";
|
|
142
160
|
return ret;
|
|
143
161
|
}
|
|
144
|
-
};
|
|
162
|
+
};
|
package/core/com/socket/drive.js
CHANGED
|
@@ -379,4 +379,26 @@ Drive.prototype.load_after = function() {
|
|
|
379
379
|
};
|
|
380
380
|
};
|
|
381
381
|
|
|
382
|
+
/**
|
|
383
|
+
* 获取插件
|
|
384
|
+
* @param {String} app 应用名称
|
|
385
|
+
* @param {String} name 插件名称
|
|
386
|
+
* @returns {Object} 返回获取到的插件
|
|
387
|
+
*/
|
|
388
|
+
Drive.prototype.plugin = function(app, name) {
|
|
389
|
+
var plus;
|
|
390
|
+
var l = $.slash;
|
|
391
|
+
if (!app) {
|
|
392
|
+
app = this.filename.between("app" + l, l);
|
|
393
|
+
}
|
|
394
|
+
if (!name) {
|
|
395
|
+
name = this.filename.between("plugin" + l, l);
|
|
396
|
+
}
|
|
397
|
+
var plugins = $.pool.plugin[app];
|
|
398
|
+
if (plugins) {
|
|
399
|
+
plus = plugins.get(name);
|
|
400
|
+
}
|
|
401
|
+
return plus
|
|
402
|
+
}
|
|
403
|
+
|
|
382
404
|
module.exports = Drive;
|
package/core/com/task/drive.js
CHANGED
|
@@ -373,4 +373,26 @@ Drive.prototype.dispose = function() {
|
|
|
373
373
|
this.timeout = undefined;
|
|
374
374
|
};
|
|
375
375
|
|
|
376
|
+
/**
|
|
377
|
+
* 获取插件
|
|
378
|
+
* @param {String} app 应用名称
|
|
379
|
+
* @param {String} name 插件名称
|
|
380
|
+
* @returns {Object} 返回获取到的插件
|
|
381
|
+
*/
|
|
382
|
+
Drive.prototype.plugin = function(app, name) {
|
|
383
|
+
var plus;
|
|
384
|
+
var l = $.slash;
|
|
385
|
+
if (!app) {
|
|
386
|
+
app = this.filename.between("app" + l, l);
|
|
387
|
+
}
|
|
388
|
+
if (!name) {
|
|
389
|
+
name = this.filename.between("plugin" + l, l);
|
|
390
|
+
}
|
|
391
|
+
var plugins = $.pool.plugin[app];
|
|
392
|
+
if (plugins) {
|
|
393
|
+
plus = plugins.get(name);
|
|
394
|
+
}
|
|
395
|
+
return plus
|
|
396
|
+
}
|
|
397
|
+
|
|
376
398
|
module.exports = Drive;
|
|
@@ -5,15 +5,16 @@
|
|
|
5
5
|
* @return {Object} 执行结果
|
|
6
6
|
*/
|
|
7
7
|
async function main(ctx, db) {
|
|
8
|
+
var ret;
|
|
8
9
|
// 获取请求参数
|
|
9
10
|
var req = ctx.request;
|
|
10
11
|
var {
|
|
11
12
|
query,
|
|
12
13
|
body
|
|
13
14
|
} = req;
|
|
14
|
-
|
|
15
|
+
|
|
15
16
|
var user = await this.get_state(ctx, db);
|
|
16
|
-
|
|
17
|
+
|
|
17
18
|
// console.log("用户", user);
|
|
18
19
|
// return "hello world" + JSON.stringify(body);
|
|
19
20
|
|
|
@@ -25,13 +26,28 @@ async function main(ctx, db) {
|
|
|
25
26
|
|
|
26
27
|
} else if (m === "set") {
|
|
27
28
|
|
|
29
|
+
} else if (m === "update") {
|
|
30
|
+
var plus = this.plugin();
|
|
31
|
+
plus.run('update_options', [{
|
|
32
|
+
name: "sandbox",
|
|
33
|
+
value: true
|
|
34
|
+
}]);
|
|
35
|
+
var op = plus.get_options();
|
|
36
|
+
console.log("当前配置", op);
|
|
37
|
+
ret = $.ret.bl(op["sandbox"]);
|
|
28
38
|
} else {
|
|
29
|
-
|
|
39
|
+
// var plugins = $.pool.plugin["test"];
|
|
40
|
+
// var plus = plugins.get("main");
|
|
41
|
+
// console.log("获取插件", plus);
|
|
42
|
+
// plus.log.debug("调用接口", "/api/test");
|
|
43
|
+
var plus = this.plugin();
|
|
44
|
+
console.log("获取插件", plus);
|
|
45
|
+
ret = $.ret.list(plus.log.list());
|
|
30
46
|
}
|
|
31
47
|
// var plus = $.plugin_admin('test');
|
|
32
48
|
// plus.run("main", "start");
|
|
33
49
|
// plus.run("main", "stop");
|
|
34
|
-
var ret = await this.sql.run(query, body, db);
|
|
50
|
+
// var ret = await this.sql.run(query, body, db);
|
|
35
51
|
return ret;
|
|
36
52
|
};
|
|
37
53
|
|
|
@@ -56,7 +56,19 @@ module.exports = {
|
|
|
56
56
|
*/
|
|
57
57
|
start(option) {
|
|
58
58
|
var msg = null;
|
|
59
|
-
|
|
59
|
+
var options = this.get_options();
|
|
60
|
+
console.log("启动了", options);
|
|
61
|
+
this.log.info("启动了", "示例插件", options);
|
|
62
|
+
// try {
|
|
63
|
+
// var a = asr;
|
|
64
|
+
// } catch (error) {
|
|
65
|
+
// this.log.error("执行失败!", error);
|
|
66
|
+
// }
|
|
67
|
+
var list = this.log.list();
|
|
68
|
+
console.log(list.length);
|
|
69
|
+
|
|
70
|
+
var str = this.log.read();
|
|
71
|
+
console.log("打印最后一条输出记录", str);
|
|
60
72
|
return msg;
|
|
61
73
|
},
|
|
62
74
|
|
|
@@ -144,4 +156,4 @@ module.exports = {
|
|
|
144
156
|
var ret = "";
|
|
145
157
|
return ret;
|
|
146
158
|
}
|
|
147
|
-
};
|
|
159
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_os",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "这是超级美眉服务端框架,用于快速构建应用程序。",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"koa-compress": "^5.1.1",
|
|
36
36
|
"koa-send": "^5.0.1",
|
|
37
37
|
"koa-websocket": "^7.0.0",
|
|
38
|
-
"mm_check": "^1.4.
|
|
38
|
+
"mm_check": "^1.4.9",
|
|
39
39
|
"mm_excel": "^1.2.0",
|
|
40
40
|
"mm_expand": "^1.7.7",
|
|
41
41
|
"mm_html": "^1.1.6",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"mm_session": "^1.4.8",
|
|
51
51
|
"mm_statics": "^1.4.8",
|
|
52
52
|
"mm_tpl": "^2.3.9",
|
|
53
|
-
"mm_xml": "^1.1.
|
|
53
|
+
"mm_xml": "^1.1.6",
|
|
54
54
|
"mosca": "^2.8.3",
|
|
55
55
|
"mqtt": "^5.10.3",
|
|
56
56
|
"publish": "^0.6.0"
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|