mm_os 2.9.8 → 3.0.0

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,259 +1,259 @@
1
- const compressing = require('compressing');
2
- const Index = require('mm_machine').Index;
3
- const Drive = require('./drive');
4
-
5
- /**
6
- * Plugin插件类
7
- * @extends {Index}
8
- * @class
9
- */
10
- class Plugin extends Index {
11
- /**
12
- * 构造函数
13
- * @param {Object} scope 作用域
14
- * @param {String} title 标题
15
- * @constructor
16
- */
17
- constructor(scope, title) {
18
- super(scope, __dirname);
19
- this.Drive = Drive;
20
- this.type = "plugin";
21
- this.title = title;
22
- // 默认启用热更新
23
- this.mode = 3;
24
- }
25
- }
26
-
27
- /**
28
- * 聊天(通过聊天的方式驱动插件, 用于机器人开发)
29
- * @param {String} from_user 发送消息人
30
- * @param {String} to_user 接收消息人
31
- * @param {String} content 内容
32
- * @param {String} group 群组 如果是个人,群组为空
33
- * @param {Number} type 群类型, 1永久会话/群、2临时会话/群
34
- * @param {String} msg_type 消息类型, event事件型、message消息型。默认消息型
35
- * @param {Object} 数据管理器
36
- * @return {String} 回复内容
37
- */
38
- Plugin.prototype.chat = async function(from_user, to_user, group, content, type, msg_type, db) {
39
- var ret = "";
40
- var lt = this.list;
41
- for (var i = 0, o; o = lt[i++];) {
42
- if (o.config.state === 1) {
43
- ret = await o.chat(from_user, to_user, group, content, type, msg_type, db);
44
- if (ret) {
45
- break;
46
- }
47
- }
48
- }
49
- return ret;
50
- };
51
-
52
- /**
53
- * 初始化插件
54
- * @param {Object} option 配置参数
55
- * @return {String} 执行结果
56
- */
57
- Plugin.prototype.init = function(option) {
58
- var ret = "";
59
- var lt = this.list;
60
- for (var i = 0, o; o = lt[i++];) {
61
- ret = o.exec('init', option);
62
- }
63
- return ret;
64
- };
65
-
66
- /**
67
- * 加载插件
68
- * @param {String} path 检索路径
69
- * @param {Boolean} accurate 是否精确路径
70
- */
71
- Plugin.prototype.update_config_all = async function(path, accurate) {
72
- var dir_plugin;
73
- if (accurate) {
74
- dir_plugin = path;
75
- } else {
76
- if (!path) {
77
- path = '/app/' + this.scope;
78
- }
79
- dir_plugin = path + "/plugin/";
80
- }
81
- if (dir_plugin.hasDir()) {
82
- var list_scope = $.dir.get(dir_plugin);
83
- // 遍历目录路径
84
- for (var i = 0, o; o = list_scope[i++];) {
85
- var file = './plugin.json'.fullname(o);
86
- if (file.hasFile()) {
87
- await this.load_file(file, true);
88
- }
89
- }
90
- }
91
- };
92
-
93
- /**
94
- * 压缩插件
95
- * @param {Object} name 插件名称
96
- * @returns {Boolean} 返回压缩路径
97
- */
98
- Plugin.prototype.zip = async function(name) {
99
- var plus = this.get(name);
100
- if (plus) {
101
- return await plus.zip();
102
- }
103
- return null;
104
- }
105
-
106
- /**
107
- * 解压插件
108
- * @param {Object} file 插件压缩文件
109
- * @returns {Boolean} 返回解压结果
110
- */
111
- Plugin.prototype.unzip = async function(file) {
112
- var name = file.basename().left(".");
113
- var dir = `/cache/plugin/${name}`.fullname();
114
- dir.addDir();
115
- var ret;
116
- try {
117
- await compressing.zip.uncompress(file, dir);
118
- ret = {
119
- file,
120
- dir
121
- };
122
- } catch (err) {
123
- $.log.error("插件解压失败!", err);
124
- }
125
- return ret;
126
- }
127
-
128
- /**
129
- * 卸载插件
130
- * @param {String} name 插件名称
131
- * @returns {String} 返回卸载路径
132
- */
133
- Plugin.prototype.uninstall = async function(name) {
134
- var plus = this.get(name);
135
- if (plus) {
136
- await plus.exec('uninstall');
137
- var obj = this.del(name, true);
138
- if (obj) {
139
- var file = obj.filename;
140
- // 删除目录
141
- file.dirname().delDir();
142
- return file
143
- }
144
- }
145
- return null;
146
- }
147
-
148
- /**
149
- * 复制目录
150
- * @param {String} dir_src 原路径
151
- * @param {String} dir 新路径
152
- * @returns {Object} 返回复制结果
153
- */
154
- Plugin.prototype.copy_dir = function(dir_src, dir) {
155
- return new Promise((resolve, reject) => {
156
- $.dir.copy(dir_src, dir, () => {
157
- resolve({
158
- dir_src,
159
- dir
160
- });
161
- });
162
- });
163
- }
164
-
165
- /**
166
- * 安装插件
167
- * @param {String} file 插件压缩文件
168
- * @returns {Object} 返回解压结果
169
- */
170
- Plugin.prototype.install = async function(file) {
171
- var ret = await this.unzip(file);
172
- if (ret) {
173
- var dirs = $.dir.get(ret.dir);
174
- if (dirs.length) {
175
- var dir_src = dirs[0];
176
- var file = "./plugin.json".fullname(dir_src);
177
- var config = file.loadJson();
178
- if (config) {
179
- var app = config.app || 'sys';
180
- var name = config.name;
181
- if (name) {
182
- var dir = `/app/${app}/plugin/${name}`;
183
- await this.copy_dir(dir_src, dir);
184
- var cs = $.pool.plugin[app];
185
- if (cs) {
186
- await cs.update(`/app/${app}/`.fullname());
187
- await cs.exec(name, 'install');
188
- setTimeout(() => {
189
- ret.dir.delDir();
190
- }, 3000)
191
- }
192
- return {
193
- app,
194
- name,
195
- dir_src,
196
- dir
197
- }
198
- }
199
- }
200
- }
201
- }
202
- }
203
-
204
- // /**
205
- // * 更新插件
206
- // * @param {String} name 插件名称
207
- // * @returns {Object} 返回更新结果
208
- // */
209
- // Plugin.prototype.update = async function(name) {
210
- // var plus = this.get(name);
211
- // if (plus) {
212
- // var cg = plus.config;
213
- // // 先将配置缓存
214
- // var file = `/cache/config/${cg.app}_${cg.name}.json`;
215
- // file.saveJson(cg);
216
-
217
- // var dir = plus.filename.dirname();
218
-
219
- // // 判断是否存在git仓库
220
- // if (cg.git) {
221
- // if (dir.hasDir('.git')) {
222
- // // "git fetch";
223
- // // "git reset --hard origin/master"
224
- // }
225
- // }
226
- // } else {
227
- // ret = $.ret.error("更新失败!原因:插件不存在");
228
- // }
229
- // }
230
-
231
- module.exports = Plugin;
232
-
233
-
234
- /**
235
- * 创建全局管理器
236
- */
237
- if (!$.pool.plugin) {
238
- $.pool.plugin = {};
239
- }
240
-
241
- function plugin_admin(scope, title) {
242
- if (!scope) {
243
- scope = $.val.scope + '';
244
- }
245
- var obj = $.pool.plugin[scope];
246
- if (!obj) {
247
- $.pool.plugin[scope] = new Plugin(scope, title);
248
- obj = $.pool.plugin[scope];
249
- }
250
- return obj;
251
- }
252
-
253
- /**
254
- * plugin管理器, 用于管理插件
255
- * @param {string} scope 作用域
256
- * @param {string} title 标题
257
- * @return {Object} 返回一个缓存类
258
- */
1
+ const compressing = require('compressing');
2
+ const Index = require('mm_machine').Index;
3
+ const Drive = require('./drive');
4
+
5
+ /**
6
+ * Plugin插件类
7
+ * @extends {Index}
8
+ * @class
9
+ */
10
+ class Plugin extends Index {
11
+ /**
12
+ * 构造函数
13
+ * @param {Object} scope 作用域
14
+ * @param {String} title 标题
15
+ * @constructor
16
+ */
17
+ constructor(scope, title) {
18
+ super(scope, __dirname);
19
+ this.Drive = Drive;
20
+ this.type = "plugin";
21
+ this.title = title;
22
+ // 默认启用热更新
23
+ this.mode = 3;
24
+ }
25
+ }
26
+
27
+ /**
28
+ * 聊天(通过聊天的方式驱动插件, 用于机器人开发)
29
+ * @param {String} from_user 发送消息人
30
+ * @param {String} to_user 接收消息人
31
+ * @param {String} content 内容
32
+ * @param {String} group 群组 如果是个人,群组为空
33
+ * @param {Number} type 群类型, 1永久会话/群、2临时会话/群
34
+ * @param {String} msg_type 消息类型, event事件型、message消息型。默认消息型
35
+ * @param {Object} 数据管理器
36
+ * @return {String} 回复内容
37
+ */
38
+ Plugin.prototype.chat = async function(from_user, to_user, group, content, type, msg_type, db) {
39
+ var ret = "";
40
+ var lt = this.list;
41
+ for (var i = 0, o; o = lt[i++];) {
42
+ if (o.config.state === 1) {
43
+ ret = await o.chat(from_user, to_user, group, content, type, msg_type, db);
44
+ if (ret) {
45
+ break;
46
+ }
47
+ }
48
+ }
49
+ return ret;
50
+ };
51
+
52
+ /**
53
+ * 初始化插件
54
+ * @param {Object} option 配置参数
55
+ * @return {String} 执行结果
56
+ */
57
+ Plugin.prototype.init = function(option) {
58
+ var ret = "";
59
+ var lt = this.list;
60
+ for (var i = 0, o; o = lt[i++];) {
61
+ ret = o.exec('init', option);
62
+ }
63
+ return ret;
64
+ };
65
+
66
+ /**
67
+ * 加载插件
68
+ * @param {String} path 检索路径
69
+ * @param {Boolean} accurate 是否精确路径
70
+ */
71
+ Plugin.prototype.update_config_all = async function(path, accurate) {
72
+ var dir_plugin;
73
+ if (accurate) {
74
+ dir_plugin = path;
75
+ } else {
76
+ if (!path) {
77
+ path = '/app/' + this.scope;
78
+ }
79
+ dir_plugin = path + "/plugin/";
80
+ }
81
+ if (dir_plugin.hasDir()) {
82
+ var list_scope = $.dir.get(dir_plugin);
83
+ // 遍历目录路径
84
+ for (var i = 0, o; o = list_scope[i++];) {
85
+ var file = './plugin.json'.fullname(o);
86
+ if (file.hasFile()) {
87
+ await this.load_file(file, true);
88
+ }
89
+ }
90
+ }
91
+ };
92
+
93
+ /**
94
+ * 压缩插件
95
+ * @param {Object} name 插件名称
96
+ * @returns {Boolean} 返回压缩路径
97
+ */
98
+ Plugin.prototype.zip = async function(name) {
99
+ var plus = this.get(name);
100
+ if (plus) {
101
+ return await plus.zip();
102
+ }
103
+ return null;
104
+ }
105
+
106
+ /**
107
+ * 解压插件
108
+ * @param {Object} file 插件压缩文件
109
+ * @returns {Boolean} 返回解压结果
110
+ */
111
+ Plugin.prototype.unzip = async function(file) {
112
+ var name = file.basename().left(".");
113
+ var dir = `/cache/plugin/${name}`.fullname();
114
+ dir.addDir();
115
+ var ret;
116
+ try {
117
+ await compressing.zip.uncompress(file, dir);
118
+ ret = {
119
+ file,
120
+ dir
121
+ };
122
+ } catch (err) {
123
+ $.log.error("插件解压失败!", err);
124
+ }
125
+ return ret;
126
+ }
127
+
128
+ /**
129
+ * 卸载插件
130
+ * @param {String} name 插件名称
131
+ * @returns {String} 返回卸载路径
132
+ */
133
+ Plugin.prototype.uninstall = async function(name) {
134
+ var plus = this.get(name);
135
+ if (plus) {
136
+ await plus.exec('uninstall');
137
+ var obj = this.del(name, true);
138
+ if (obj) {
139
+ var file = obj.filename;
140
+ // 删除目录
141
+ file.dirname().delDir();
142
+ return file
143
+ }
144
+ }
145
+ return null;
146
+ }
147
+
148
+ /**
149
+ * 复制目录
150
+ * @param {String} dir_src 原路径
151
+ * @param {String} dir 新路径
152
+ * @returns {Object} 返回复制结果
153
+ */
154
+ Plugin.prototype.copy_dir = function(dir_src, dir) {
155
+ return new Promise((resolve, reject) => {
156
+ $.dir.copy(dir_src, dir, () => {
157
+ resolve({
158
+ dir_src,
159
+ dir
160
+ });
161
+ });
162
+ });
163
+ }
164
+
165
+ /**
166
+ * 安装插件
167
+ * @param {String} file 插件压缩文件
168
+ * @returns {Object} 返回解压结果
169
+ */
170
+ Plugin.prototype.install = async function(file) {
171
+ var ret = await this.unzip(file);
172
+ if (ret) {
173
+ var dirs = $.dir.get(ret.dir);
174
+ if (dirs.length) {
175
+ var dir_src = dirs[0];
176
+ var file = "./plugin.json".fullname(dir_src);
177
+ var config = file.loadJson();
178
+ if (config) {
179
+ var app = config.app || 'sys';
180
+ var name = config.name;
181
+ if (name) {
182
+ var dir = `/app/${app}/plugin/${name}`;
183
+ await this.copy_dir(dir_src, dir);
184
+ var cs = $.pool.plugin[app];
185
+ if (cs) {
186
+ await cs.update(`/app/${app}/`.fullname());
187
+ await cs.exec(name, 'install');
188
+ setTimeout(() => {
189
+ ret.dir.delDir();
190
+ }, 3000)
191
+ }
192
+ return {
193
+ app,
194
+ name,
195
+ dir_src,
196
+ dir
197
+ }
198
+ }
199
+ }
200
+ }
201
+ }
202
+ }
203
+
204
+ // /**
205
+ // * 更新插件
206
+ // * @param {String} name 插件名称
207
+ // * @returns {Object} 返回更新结果
208
+ // */
209
+ // Plugin.prototype.update = async function(name) {
210
+ // var plus = this.get(name);
211
+ // if (plus) {
212
+ // var cg = plus.config;
213
+ // // 先将配置缓存
214
+ // var file = `/cache/config/${cg.app}_${cg.name}.json`;
215
+ // file.saveJson(cg);
216
+
217
+ // var dir = plus.filename.dirname();
218
+
219
+ // // 判断是否存在git仓库
220
+ // if (cg.git) {
221
+ // if (dir.hasDir('.git')) {
222
+ // // "git fetch";
223
+ // // "git reset --hard origin/master"
224
+ // }
225
+ // }
226
+ // } else {
227
+ // ret = $.ret.error("更新失败!原因:插件不存在");
228
+ // }
229
+ // }
230
+
231
+ module.exports = Plugin;
232
+
233
+
234
+ /**
235
+ * 创建全局管理器
236
+ */
237
+ if (!$.pool.plugin) {
238
+ $.pool.plugin = {};
239
+ }
240
+
241
+ function plugin_admin(scope, title) {
242
+ if (!scope) {
243
+ scope = $.val.scope + '';
244
+ }
245
+ var obj = $.pool.plugin[scope];
246
+ if (!obj) {
247
+ $.pool.plugin[scope] = new Plugin(scope, title);
248
+ obj = $.pool.plugin[scope];
249
+ }
250
+ return obj;
251
+ }
252
+
253
+ /**
254
+ * plugin管理器, 用于管理插件
255
+ * @param {string} scope 作用域
256
+ * @param {string} title 标题
257
+ * @return {Object} 返回一个缓存类
258
+ */
259
259
  $.plugin_admin = plugin_admin;
@@ -21,7 +21,7 @@ class Static extends Index {
21
21
  constructor(scope, title) {
22
22
  super(scope, __dirname);
23
23
  this.Drive = Drive;
24
-
24
+
25
25
  // 更新并重载
26
26
  this.mode = 3;
27
27
  this.type = "static";
@@ -91,7 +91,7 @@ class Static extends Index {
91
91
  * @return {Drive} 静态文件驱动类
92
92
  */
93
93
  Static.prototype.getObj = async function(dir) {
94
- var d = join(dir).replace(process.cwd() + $.slash, '/');
94
+ var d = dir;
95
95
  var app = d.between(join('app/'), join('/'));
96
96
  var plugin = d.between(join('/plugin/'), join('/'));
97
97
  var path = '/' + app;
package/index.js CHANGED
@@ -6,8 +6,6 @@ $.redis_admin = require("mm_redis").redis_admin;
6
6
  $.mysql_admin = require('mm_mysql').mysql_admin;
7
7
  const conf = require("mm_config");
8
8
  var Com = require("./lib/com.js");
9
- var App = require("./lib/app.js");
10
- var Game = require("./lib/game.js");
11
9
  var WEB = require("./core/base/web/index.js");
12
10
  var MQTT = require("./core/base/mqtt/index.js");
13
11
 
@@ -81,8 +79,6 @@ class OS {
81
79
  }
82
80
  }
83
81
 
84
- OS.prototype.init_mod = function() {}
85
-
86
82
  /**
87
83
  * 初始化数据
88
84
  * @param {Object} config 配置参数
@@ -94,9 +90,9 @@ OS.prototype.initData = function(config) {
94
90
  } else if (p.substring(p.length - 1) !== $.slash) {
95
91
  config.runPath += $.slash;
96
92
  }
97
-
93
+
98
94
  $.runPath = config.runPath;
99
-
95
+
100
96
  // 初始化公共函数
101
97
  $.func = {};
102
98
 
@@ -127,17 +123,9 @@ OS.prototype.initData = function(config) {
127
123
  */
128
124
  OS.prototype.loadModule = function(cg) {
129
125
  $.com = new Com();
130
- $.app = new App();
131
126
  this.com = $.com;
132
- this.app = $.app;
133
127
 
134
128
  $.task = $.task_admin('sys');
135
- if (cg.sys) {
136
- if (cg.sys.game) {
137
- $.game = new Game();
138
- this.game = $.game;
139
- }
140
- }
141
129
 
142
130
  if (cg.sys) {
143
131
  var cache = cg.sys.cache;
@@ -255,7 +243,9 @@ OS.prototype.main = async function(state) {
255
243
  * @param {String} state 状态
256
244
  */
257
245
  OS.prototype.before = async function(state) {
258
- await this.app.initApp();
246
+ this.app = $.app_admin('sys');
247
+ await this.app.update();
248
+ await this.app.exec(null, 'init');
259
249
  };
260
250
 
261
251
  /**
@@ -263,7 +253,7 @@ OS.prototype.before = async function(state) {
263
253
  * @param {String} state 状态
264
254
  */
265
255
  OS.prototype.after = async function(state) {
266
- this.app.runApp();
256
+ await this.app.run(null, 'start');
267
257
  };
268
258
 
269
259
  /**
package/lib/base.js CHANGED
@@ -60,6 +60,14 @@ Base.prototype.init = function(reset = false) {
60
60
  this.init_after(reset);
61
61
  }
62
62
 
63
+ Base.prototype.start_after = function() {
64
+
65
+ }
66
+
67
+ Base.prototype.start = function() {
68
+ this.start_after();
69
+ }
70
+
63
71
  /**
64
72
  * 获取文件
65
73
  */
package/nodemon.json CHANGED
@@ -6,8 +6,7 @@
6
6
  "cache",
7
7
  "log",
8
8
  "node_modules/**/node_modules",
9
- "game/cache",
10
- "demo/game/cache",
9
+ "**/cache/**",
11
10
  "game/data",
12
11
  "**/conf.json",
13
12
  "*/static/*/*.json",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_os",
3
- "version": "2.9.8",
3
+ "version": "3.0.0",
4
4
  "description": "这是超级美眉服务端框架,用于快速构建应用程序。",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -38,14 +38,14 @@
38
38
  "koa-websocket": "^7.0.0",
39
39
  "mm_check": "^1.4.9",
40
40
  "mm_excel": "^1.2.1",
41
- "mm_expand": "^1.8.0",
41
+ "mm_expand": "^1.8.2",
42
42
  "mm_html": "^1.1.6",
43
43
  "mm_koa_proxy": "^1.0.0",
44
- "mm_logs": "^1.1.7",
44
+ "mm_logs": "^1.1.9",
45
45
  "mm_machine": "^1.9.7",
46
46
  "mm_mongodb": "^1.4.2",
47
47
  "mm_mqtt": "^1.0.6",
48
- "mm_mysql": "^1.9.6",
48
+ "mm_mysql": "^1.9.9",
49
49
  "mm_redis": "^1.4.2",
50
50
  "mm_ret": "^1.4.0",
51
51
  "mm_session": "^1.4.8",
@@ -1,29 +0,0 @@
1
- var WEB = require("./web");
2
- var MQTT = require("./mqtt");
3
-
4
- module.exports = function(cg) {
5
- var middleware = new $.Middleware();
6
- middleware.init();
7
- var mqtt, web;
8
- if (cg.web && cg.web.state) {
9
- web = new WEB(cg.web);
10
- web.list = middleware.list.filter((o) => {
11
- return !o.mode || o.mode == "web"
12
- });
13
- web.init();
14
- }
15
- if (cg.mqtt && cg.mqtt.state) {
16
- mqtt = new MQTT(Object.assign(cg.mqtt, {
17
- redis: cg.redis,
18
- mongodb: cg.mongodb
19
- }));
20
- mqtt.list = middleware.list.filter((o) => {
21
- return o.mode == "mqtt"
22
- });
23
- mqtt.init();
24
- }
25
- return {
26
- mqtt,
27
- web
28
- }
29
- }