mm_os 4.3.7 → 5.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.
Files changed (232) hide show
  1. package/README.md +101 -504
  2. package/index.js +26 -19
  3. package/lib/loader.js +787 -0
  4. package/lib/os.js +369 -0
  5. package/package.json +55 -84
  6. package/LICENSE +0 -21
  7. package/README_EN.md +0 -505
  8. package/adapter/adapter.js +0 -484
  9. package/adapter/custom_persistence.js +0 -661
  10. package/adapter/mqtt.js +0 -254
  11. package/adapter/socket.js +0 -244
  12. package/adapter/web.js +0 -92
  13. package/adapter/websocket.js +0 -43
  14. package/ai.js +0 -130
  15. package/com/api/README.md +0 -3
  16. package/com/api/com.json +0 -5
  17. package/com/api/config.tpl.json +0 -41
  18. package/com/api/drive.js +0 -732
  19. package/com/api/index.js +0 -201
  20. package/com/api/oauth.js +0 -200
  21. package/com/api/script.tpl.js +0 -32
  22. package/com/cmd/README.md +0 -11
  23. package/com/cmd/com.json +0 -5
  24. package/com/cmd/config.tpl.json +0 -48
  25. package/com/cmd/drive.js +0 -176
  26. package/com/cmd/index.js +0 -287
  27. package/com/cmd/job/config.json +0 -66
  28. package/com/cmd/job/index.js +0 -241
  29. package/com/cmd/job/test.js +0 -188
  30. package/com/cmd/msg.json +0 -48
  31. package/com/cmd/script.tpl.js +0 -12
  32. package/com/db/README.md +0 -3
  33. package/com/db/com.json +0 -5
  34. package/com/db/drive.js +0 -2206
  35. package/com/db/index.js +0 -241
  36. package/com/event/README.md +0 -4
  37. package/com/event/com.json +0 -5
  38. package/com/event/config.tpl.json +0 -20
  39. package/com/event/drive.js +0 -61
  40. package/com/event/index.js +0 -438
  41. package/com/event/script.tpl.js +0 -23
  42. package/com/mqtt/README.md +0 -47
  43. package/com/mqtt/com.json +0 -5
  44. package/com/mqtt/config.tpl.json +0 -42
  45. package/com/mqtt/drive.js +0 -704
  46. package/com/mqtt/index.js +0 -1052
  47. package/com/mqtt/index.test.js +0 -503
  48. package/com/mqtt/script.tpl.js +0 -719
  49. package/com/nav/README.md +0 -2
  50. package/com/nav/com.json +0 -5
  51. package/com/nav/config.tpl.json +0 -84
  52. package/com/nav/drive.js +0 -702
  53. package/com/nav/index.js +0 -228
  54. package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
  55. package/com/nav/tpl/admin_pc/page_config.vue +0 -280
  56. package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
  57. package/com/nav/tpl/admin_pc/page_default.vue +0 -247
  58. package/com/nav/tpl/admin_pc/page_form.vue +0 -180
  59. package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
  60. package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
  61. package/com/nav/tpl/admin_pc/page_table.vue +0 -296
  62. package/com/nav/tpl/admin_pc/page_type.vue +0 -321
  63. package/com/nav/tpl/admin_pc/page_view.vue +0 -124
  64. package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
  65. package/com/nav/tpl/dev_pc/page_config.vue +0 -253
  66. package/com/nav/tpl/dev_pc/page_default.vue +0 -247
  67. package/com/nav/tpl/dev_pc/page_form.vue +0 -162
  68. package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
  69. package/com/nav/tpl/dev_pc/page_table.vue +0 -247
  70. package/com/nav/tpl/dev_pc/page_type.vue +0 -313
  71. package/com/nav/tpl/home_pc/page_channel.vue +0 -234
  72. package/com/nav/tpl/home_pc/page_default.vue +0 -234
  73. package/com/nav/tpl/home_pc/page_form.vue +0 -137
  74. package/com/nav/tpl/home_pc/page_list.vue +0 -234
  75. package/com/nav/tpl/home_pc/page_nav.vue +0 -221
  76. package/com/nav/tpl/home_pc/page_type.vue +0 -234
  77. package/com/nav/tpl/home_pc/page_view.vue +0 -125
  78. package/com/nav/tpl/home_phone/page_channel.vue +0 -234
  79. package/com/nav/tpl/home_phone/page_default.vue +0 -234
  80. package/com/nav/tpl/home_phone/page_form.vue +0 -137
  81. package/com/nav/tpl/home_phone/page_list.vue +0 -234
  82. package/com/nav/tpl/home_phone/page_nav.vue +0 -237
  83. package/com/nav/tpl/home_phone/page_type.vue +0 -234
  84. package/com/nav/tpl/home_phone/page_view.vue +0 -125
  85. package/com/nav/viewmodel.js +0 -446
  86. package/com/param/README.md +0 -2
  87. package/com/param/com.json +0 -5
  88. package/com/param/config.tpl.json +0 -136
  89. package/com/param/drive.js +0 -502
  90. package/com/param/index.js +0 -158
  91. package/com/param/script.tpl.js +0 -12
  92. package/com/pendant/README.md +0 -3
  93. package/com/pendant/com.json +0 -5
  94. package/com/pendant/config.tpl.json +0 -32
  95. package/com/pendant/drive.js +0 -204
  96. package/com/pendant/index.js +0 -467
  97. package/com/pendant/pendant.html +0 -16
  98. package/com/pendant/script.tpl.js +0 -18
  99. package/com/socket/README.md +0 -47
  100. package/com/socket/com.json +0 -5
  101. package/com/socket/config.tpl.json +0 -12
  102. package/com/socket/drive.js +0 -679
  103. package/com/socket/index.js +0 -402
  104. package/com/socket/script.tpl.js +0 -41
  105. package/com/sql/README.md +0 -3
  106. package/com/sql/com.json +0 -5
  107. package/com/sql/config.tpl.json +0 -74
  108. package/com/sql/drive.js +0 -1328
  109. package/com/sql/index.js +0 -152
  110. package/com/sql/script.tpl.js +0 -47
  111. package/com/static/README.md +0 -2
  112. package/com/static/com.json +0 -5
  113. package/com/static/config.tpl.json +0 -24
  114. package/com/static/drive.js +0 -194
  115. package/com/static/index.js +0 -237
  116. package/com/static/script.tpl.js +0 -28
  117. package/com/task/README.md +0 -3
  118. package/com/task/com.json +0 -5
  119. package/com/task/config.tpl.json +0 -24
  120. package/com/task/drive.js +0 -428
  121. package/com/task/index.js +0 -159
  122. package/com/task/script.tpl.js +0 -40
  123. package/com/template/com.json +0 -5
  124. package/com/template/config.tpl.json +0 -16
  125. package/com/template/drive.js +0 -81
  126. package/com/template/index.js +0 -141
  127. package/com.js +0 -237
  128. package/common/README.md +0 -2
  129. package/common/middleware/web_after/index.js +0 -26
  130. package/common/middleware/web_after/middleware.json +0 -9
  131. package/common/middleware/web_base/index.js +0 -113
  132. package/common/middleware/web_base/middleware.json +0 -19
  133. package/common/middleware/web_before/index.js +0 -33
  134. package/common/middleware/web_before/middleware.json +0 -9
  135. package/common/middleware/web_cors/index.js +0 -87
  136. package/common/middleware/web_cors/middleware.json +0 -24
  137. package/common/middleware/web_error/index.js +0 -131
  138. package/common/middleware/web_error/middleware.json +0 -19
  139. package/common/middleware/web_ip/index.js +0 -15
  140. package/common/middleware/web_ip/middleware.json +0 -14
  141. package/common/middleware/web_logger/index.js +0 -156
  142. package/common/middleware/web_logger/middleware.json +0 -14
  143. package/common/middleware/web_main/index.js +0 -26
  144. package/common/middleware/web_main/middleware.json +0 -9
  145. package/common/middleware/web_static/index.js +0 -73
  146. package/common/middleware/web_static/middleware.json +0 -54
  147. package/common/middleware/web_waf/index.js +0 -395
  148. package/common/middleware/web_waf/middleware.json +0 -13
  149. package/core/app/config.tpl.json +0 -67
  150. package/core/app/index.js +0 -711
  151. package/core/app/script.tpl.js +0 -52
  152. package/core/channel/index.js +0 -899
  153. package/core/channel/matcher.js +0 -585
  154. package/core/com/config.tpl.json +0 -16
  155. package/core/com/index.js +0 -77
  156. package/core/com/script.tpl.js +0 -5
  157. package/core/component/component.js +0 -42
  158. package/core/component/config.tpl.json +0 -63
  159. package/core/component/index.js +0 -273
  160. package/core/component/script.tpl.js +0 -19
  161. package/core/controller/config.tpl.json +0 -14
  162. package/core/controller/index.js +0 -371
  163. package/core/controller/script.tpl.js +0 -27
  164. package/core/factory/config.tpl.json +0 -14
  165. package/core/factory/entity.js +0 -275
  166. package/core/factory/index.js +0 -241
  167. package/core/factory/script.tpl.js +0 -16
  168. package/core/game/bat/index.js +0 -137
  169. package/core/game/bat/world.js +0 -622
  170. package/core/game/config.tpl.json +0 -16
  171. package/core/game/entity_admin.js +0 -230
  172. package/core/game/index.js +0 -186
  173. package/core/handler/config.tpl.json +0 -22
  174. package/core/handler/index.js +0 -181
  175. package/core/handler/script.tpl.js +0 -23
  176. package/core/logic/config.tpl.json +0 -14
  177. package/core/logic/index.js +0 -59
  178. package/core/logic/script.tpl.js +0 -19
  179. package/core/middleware/config.tpl.json +0 -16
  180. package/core/middleware/index.js +0 -117
  181. package/core/middleware/script.tpl.js +0 -37
  182. package/core/mod/config.tpl.json +0 -22
  183. package/core/mod/index.js +0 -136
  184. package/core/mod/script.tpl.js +0 -34
  185. package/core/model/config.tpl.json +0 -219
  186. package/core/model/index.js +0 -272
  187. package/core/model/model.js +0 -27
  188. package/core/model/script.tpl.js +0 -20
  189. package/core/notifier/config.tpl.json +0 -14
  190. package/core/notifier/index.js +0 -77
  191. package/core/notifier/script.tpl.js +0 -20
  192. package/core/plugin/config.tpl.json +0 -36
  193. package/core/plugin/index.js +0 -267
  194. package/core/plugin/script.tpl.js +0 -51
  195. package/core/pusher/config.tpl.json +0 -14
  196. package/core/pusher/index.js +0 -158
  197. package/core/pusher/script.tpl.js +0 -20
  198. package/core/room/bat/index.js +0 -170
  199. package/core/room/bat/room.js +0 -524
  200. package/core/room/config.tpl.json +0 -20
  201. package/core/room/index.js +0 -249
  202. package/core/room/room.js +0 -61
  203. package/core/scene/config.tpl.json +0 -14
  204. package/core/scene/index.js +0 -467
  205. package/core/scene/loop.js +0 -1306
  206. package/core/scene/map.js +0 -28
  207. package/core/scene/script.tpl.js +0 -22
  208. package/core/sender/config.tpl.json +0 -14
  209. package/core/sender/index.js +0 -79
  210. package/core/sender/script.tpl.js +0 -20
  211. package/core/service/config.tpl.json +0 -14
  212. package/core/service/index.js +0 -100
  213. package/core/service/script.tpl.js +0 -25
  214. package/core/store/config.tpl.json +0 -26
  215. package/core/store/index.js +0 -1794
  216. package/core/store/script.tpl.js +0 -22
  217. package/core/system/config.tpl.json +0 -18
  218. package/core/system/index.js +0 -312
  219. package/core/system/script.tpl.js +0 -77
  220. package/core/view/config.tpl.json +0 -14
  221. package/core/view/index.js +0 -91
  222. package/core/view/script.tpl.js +0 -20
  223. package/core/zone/bat/index.js +0 -744
  224. package/core/zone/config.tpl.json +0 -54
  225. package/core/zone/index.js +0 -655
  226. package/core/zone/script.tpl.js +0 -10
  227. package/core/zone/zone_bat.js +0 -136
  228. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
  229. package/os.js +0 -53
  230. package/server.js +0 -602
  231. package/ulits/id_gen.js +0 -134
  232. package/ulits/word.js +0 -206
@@ -1,24 +0,0 @@
1
- {
2
- // 任务名称,用于动态增删改查
3
- "name": "${name || 'demo'}",
4
- // 任务标题
5
- "title": "${title || '任务'}",
6
- // 任务描述
7
- "description": "${description || '描述任务使用方法'}",
8
- // 状态 0未启用,1启用
9
- "state": 1,
10
- // 任务执行次数,执行次数达标后不再执行。0为不限次数,一直执行
11
- "num": 2,
12
- // 任务间隔时长,单位:毫秒
13
- "interval": 1000,
14
- // 任务启动等待时长,单位:毫秒
15
- "wait": 0,
16
- // 任务触发的时间,可设置的格式分别为: yyyy-MM-dd hh:mm:ss, MM-dd hh:mm:ss, dd hh:mm:ss, hh:mm:ss, hh:mm, mm 例如: 08:00, 则为每天8点触发
17
- "time": "",
18
- // 任务开始日期,例如:2020-10-01开始执行,为空则不限制
19
- "date_start": "",
20
- // 任务结束日期,例如:2020-10-07不再执行,为空则不限制
21
- "date_end": "",
22
- // 任务排序,决定多个任务的执行优先顺序
23
- "sort": 100
24
- }
package/com/task/drive.js DELETED
@@ -1,428 +0,0 @@
1
- const Item = require("mm_machine").Drive;
2
-
3
- /**
4
- * 延迟
5
- * @param {number} milli_seconds 毫秒
6
- */
7
- function sleep(milli_seconds) {
8
- var end_time = new Date().getTime() + milli_seconds;
9
- while (new Date().getTime() < end_time) {}
10
- }
11
-
12
- /**
13
- * 计算时间差
14
- * @param {string} start_time 开始时间
15
- * @param {string} end_time 结束时间
16
- * @returns {number} 返回间隔时长
17
- */
18
- function span(start_time, end_time) {
19
- var stime = Date.parse(start_time);
20
- var etime = Date.parse(end_time);
21
- return etime - stime;
22
- }
23
-
24
- /**
25
- * 转为时间
26
- * @param {string} time_str 时间字符串
27
- * @returns {Date} 时间类型
28
- */
29
- function toTime(time_str) {
30
- var str = time_str
31
- .replace("T", " ")
32
- .replace("Z", "")
33
- .replaceAll(".", "/")
34
- .replaceAll("-", "/");
35
- return new Date(str);
36
- }
37
-
38
- /**
39
- * 定时器类函数
40
- */
41
- class Drive extends Item {
42
- static config = {
43
- // 任务名称,用于动态增删改查
44
- name: "",
45
- // 任务标题
46
- title: "",
47
- // 任务描述
48
- description: "",
49
- // 状态 0未启用,1启用
50
- state: 1,
51
- // 执行次数
52
- num: 10,
53
- // 时间间隔(毫秒ms)
54
- interval: 1000,
55
- // 等待时长(毫秒ms)
56
- wait: 0,
57
- // 执行时间
58
- time: "",
59
- // 执行开始日期
60
- date_start: "",
61
- // 执行结束日期
62
- date_end: "",
63
- };
64
-
65
- /**
66
- * 构造函数
67
- * @param {object} config 配置参数
68
- * @param {object} parent 父对象
69
- * @class
70
- */
71
- constructor(config, parent) {
72
- super({ ...Drive.config, ...config }, parent);
73
-
74
- // 更新配置并重载脚本
75
- this.mode = 3;
76
- }
77
- }
78
-
79
- /**
80
- * 预设
81
- */
82
- Drive.prototype._preset = function () {
83
- /// 状态
84
- this.state = "start";
85
- /// 等候器
86
- this.timeout;
87
- /// 定时执行器
88
- this.interval;
89
- /// 当前执行次数
90
- this.num = 1;
91
- };
92
-
93
- /**
94
- * 设置等待执行
95
- * @param {Function} func 回调函数
96
- */
97
- Drive.prototype.setTimeout = function (func) {
98
- if (func) {
99
- if (this.timeout) {
100
- clearTimeout(this.timeout);
101
- }
102
- this.timeout = setTimeout(func, this.config.wait);
103
- }
104
- };
105
-
106
- /**
107
- * 设置间隔执行
108
- * @param {Function} func 回调函数
109
- */
110
- Drive.prototype.setInterval = async function (func) {
111
- await sleep(this.config.wait);
112
- if (this.interval) {
113
- clearInterval(this.interval);
114
- }
115
- this.interval = setInterval(func, this.config.interval);
116
- };
117
-
118
- /**
119
- * 创建时间匹配函数
120
- * @param {string} time 时间字符串
121
- * @param {Function} func 回调函数
122
- * @returns {Function} 时间匹配函数
123
- */
124
- Drive.prototype._createTimeFn = function (time, func) {
125
- if (!time) return func;
126
- if (time.indexOf(" ") !== -1) {
127
- return this._createDateTimeFn(time, func);
128
- }
129
- return this._createTimeOnlyFn(time, func);
130
- };
131
-
132
- /**
133
- * 创建日期时间匹配函数
134
- * @param {string} time 时间字符串
135
- * @param {Function} func 回调函数
136
- * @returns {Function} 时间匹配函数
137
- */
138
- Drive.prototype._createDateTimeFn = function (time, func) {
139
- if (time.indexOf("-") !== -1) {
140
- var arr = time.split("-");
141
- var fmt = arr.length > 2 ? "yyyy-MM-dd hh:mm:ss" : "MM-dd hh:mm:ss";
142
- return function () {
143
- if (new Date().toStr(fmt) === time) func();
144
- };
145
- }
146
- var arr = time.split(":");
147
- var fmt =
148
- arr.length == 3 ? "dd hh:mm:ss" : arr.length == 2 ? "dd hh:mm" : "dd hh";
149
- return function () {
150
- if (new Date().toStr(fmt) === time) func();
151
- };
152
- };
153
-
154
- /**
155
- * 创建仅时间匹配函数
156
- * @param {string} time 时间字符串
157
- * @param {Function} func 回调函数
158
- * @returns {Function} 时间匹配函数
159
- */
160
- Drive.prototype._createTimeOnlyFn = function (time, func) {
161
- var arr = time.split(":");
162
- var fmt = arr.length == 3 ? "hh:mm:ss" : arr.length == 2 ? "hh:mm" : "mm";
163
- return function () {
164
- if (new Date().toStr(fmt) === time) func();
165
- };
166
- };
167
-
168
- /**
169
- * 创建带开始时间的执行函数
170
- * @param {Function} fn 原始函数
171
- * @param {number} start 开始时间
172
- * @param {number} end 结束时间
173
- * @returns {Function} 执行函数
174
- */
175
- Drive.prototype._createStartFn = function (fn, start, end) {
176
- var _this = this;
177
- if (end) {
178
- return function () {
179
- var now = new Date();
180
- if (span(now, end) >= 0 && span(now, start) <= 0) fn();
181
- else if (span(now, end) < 0) {
182
- _this.clearSub();
183
- _this.notify(_this.config.name, "time_end");
184
- }
185
- };
186
- }
187
- return function () {
188
- if (span(new Date(), start) <= 0) fn();
189
- };
190
- };
191
-
192
- /**
193
- * 创建带结束时间的执行函数
194
- * @param {Function} fn 原始函数
195
- * @param {number} end 结束时间
196
- * @returns {Function} 执行函数
197
- */
198
- Drive.prototype._createEndFn = function (fn, end) {
199
- var _this = this;
200
- return function () {
201
- if (span(new Date(), end) >= 0) fn();
202
- else {
203
- _this.clearSub();
204
- _this.notify(_this.config.name, "time_end");
205
- }
206
- };
207
- };
208
-
209
- /**
210
- * 设置时期执行
211
- * @param {Function} func 回调函数
212
- * @returns {object} 执行结果
213
- */
214
- Drive.prototype.setPeriod = function (func) {
215
- var cg = this.config;
216
- var fn = this._createTimeFn(cg.time, func);
217
- if (cg.date_start) {
218
- return this._createStartFn(
219
- fn,
220
- toTime(cg.date_start),
221
- cg.date_end ? toTime(cg.date_end) : null,
222
- );
223
- }
224
- if (cg.date_end) {
225
- return this._createEndFn(fn, toTime(cg.date_end));
226
- }
227
- return fn;
228
- };
229
-
230
- /**
231
- * 设置按次数执行
232
- * @param {Function} func 回调函数
233
- * @returns {object} 执行结果
234
- */
235
- Drive.prototype.setNum = function (func) {
236
- var _this = this;
237
- return function () {
238
- if (_this.state === "start") {
239
- try {
240
- if (_this.config.num < 1) {
241
- func();
242
- } else if (_this.num < _this.config.num) {
243
- func();
244
- _this.num += 1;
245
- } else {
246
- func();
247
- _this.clear();
248
- _this.notify(_this.config.name, "completed");
249
- }
250
- } catch (err) {
251
- _this.log("error", "定时任务执行失败!", _this.config.name, err);
252
- }
253
- }
254
- };
255
- };
256
-
257
- /**
258
- * 结束定时器
259
- */
260
- Drive.prototype.end = function () {
261
- // 当前状态为结束
262
- this.state = "end";
263
- this.notify(this.config.name, "suspend");
264
- this.clear();
265
- };
266
-
267
- /**
268
- * 清除定时器(子函数)
269
- */
270
- Drive.prototype.clearSub = function () {
271
- if (this.interval) {
272
- clearInterval(this.interval);
273
- }
274
- if (this.timeout) {
275
- clearTimeout(this.timeout);
276
- }
277
- };
278
-
279
- /**
280
- * 清除定时器
281
- * @param {number} millisecond 时间间隔, 单位: 毫秒
282
- */
283
- Drive.prototype.clear = function (millisecond) {
284
- if (millisecond) {
285
- var _this = this;
286
- setTimeout(() => {
287
- _this.clearSub();
288
- }, millisecond);
289
- } else {
290
- this.clearSub();
291
- }
292
- };
293
-
294
- /**
295
- * 执行线程
296
- * @returns {object} 当前类
297
- */
298
- Drive.prototype.main = async function () {
299
- this.log("debug", "定时任务(默认), 执行中...");
300
- };
301
-
302
- /**
303
- * 执行线程
304
- * @param {Function} func 回调函数
305
- * @returns {object} 当前类
306
- */
307
- Drive.prototype.run = async function (func) {
308
- this.init();
309
- if (func) {
310
- await this.setInterval(this.setPeriod(this.setNum(func)));
311
- } else {
312
- await this.setInterval(
313
- this.setPeriod(
314
- this.setNum(() => {
315
- this.main();
316
- }),
317
- ),
318
- );
319
- }
320
- return this;
321
- };
322
-
323
- /**
324
- * 初始化定时器
325
- */
326
- Drive.prototype.init = function () {
327
- // 当前执行次数
328
- this.num = 1;
329
- // 当前状态为开启
330
- this.state = "start";
331
- this.notify(this.config.name, "init");
332
- };
333
-
334
- /**
335
- * 启动定时器
336
- */
337
- Drive.prototype.start = function () {
338
- // 当前状态为开启
339
- this.state = "start";
340
- this.notify(this.config.name, "start");
341
- };
342
-
343
- /**
344
- * 暂停定时器
345
- */
346
- Drive.prototype.stop = function () {
347
- // 当前状态为开启
348
- this.state = "stop";
349
- this.notify(this.config.name, "stop");
350
- };
351
-
352
- /**
353
- * 通知函数, 当定时器执行完最后一次时, 会调用通知函数
354
- * @param {string} name 名称
355
- * @param {string} state 状态
356
- */
357
- Drive.prototype.notify = function (name, state) {
358
- // switch (state) {
359
- // case "init":
360
- // this.log('debug', '初始化');
361
- // break;
362
- // case "start":
363
- // this.log('debug', '开始执行');
364
- // break;
365
- // case "stop":
366
- // this.log('debug', '已暂停');
367
- // break;
368
- // case "suspend":
369
- // // 主动中断
370
- // this.log('debug', '已中断');
371
- // break;
372
- // case "time_end":
373
- // this.log('debug', '已到期');
374
- // break;
375
- // case "completed":
376
- // this.log('debug', '已完成');
377
- // break;
378
- // default:
379
- // break;
380
- // }
381
- };
382
-
383
- /**
384
- * 销毁资源
385
- */
386
- Drive.prototype.dispose = function () {
387
- this.clearSub();
388
- this.interval = undefined;
389
- this.timeout = undefined;
390
- };
391
-
392
- /**
393
- * 获取插件
394
- * @param {string} app 应用名称
395
- * @param {string} name 插件名称
396
- * @returns {object} 返回获取到的插件
397
- */
398
- Drive.prototype.plugin = function (app, name) {
399
- var l = $.slash;
400
- var app_name = app || this.config_file.between("app" + l, l);
401
- var plugin_name = name || this.config_file.between("plugin" + l, l);
402
- var plus;
403
- var plugins = $.pool.plugin[app_name];
404
- if (plugins) {
405
- plus = plugins.get(plugin_name);
406
- }
407
- return plus;
408
- };
409
-
410
- /**
411
- * 获取模型
412
- * @param {string} type 模型类型
413
- * @returns {object} 返回获取到的模型
414
- */
415
- Drive.prototype.getModel = function (type) {
416
- let model = { ...this.config };
417
- let dir = this.getDir();
418
- let l = $.slash;
419
- let app_name = dir.between("app" + l, l);
420
- let plugin_name = dir.between("plugin" + l, l);
421
- let name = dir.basename();
422
- model.app = app_name;
423
- model.plugin = plugin_name;
424
- model.name = model.name || app_name + "_" + name;
425
- return model;
426
- };
427
-
428
- module.exports = Drive;
package/com/task/index.js DELETED
@@ -1,159 +0,0 @@
1
- const Manager = require("mm_machine").Manager;
2
- const Drive = require("./drive");
3
-
4
- /**
5
- * 任务类
6
- * @augments {Manager}
7
- * @class
8
- */
9
- class Task extends Manager {
10
- /**
11
- * 配置参数
12
- * @type {object}
13
- */
14
- static config = {
15
- /**
16
- * 名称
17
- * @type {string}
18
- */
19
- name: "",
20
- /**
21
- * 标题
22
- * @type {string}
23
- */
24
- title: "任务管理器",
25
- /**
26
- * 描述
27
- * @type {string}
28
- */
29
- description: "这是任务管理器",
30
- /**
31
- * 检索文件名
32
- * @type {string}
33
- */
34
- filename: "task.json",
35
- /**
36
- * 模板目录
37
- * @type {string}
38
- */
39
- tpl_dir: __dirname,
40
- /**
41
- * 基础目录
42
- * @type {string}
43
- */
44
- base_dir: "../common/task".fullname(__dirname),
45
- /**
46
- * 自定义目录,加载项目自定义资源
47
- * @type {string}
48
- */
49
- dir: "./app".fullname(),
50
- /**
51
- * 搜索模式 dir按目录搜索 | file按文件名搜索
52
- * @type {string}
53
- */
54
- search_way: "file",
55
- /**
56
- * 是否懒加载
57
- * @type {boolean}
58
- */
59
- lazy_load: false,
60
- /**
61
- * 模式
62
- * 1.生产模式,改变文件不会重新加载
63
- * 2.热更新模式,改变配置文件会重新加载配置,不重新加载脚本
64
- * 3.热重载模式,改变配置文件都会加载配置和脚本
65
- * 4.重载模式,执行完后重新加载脚本,避免变量污染
66
- * 5.热更新+重载模式,改变配置文件重新加载配置和脚本,执行完后重新加载脚本
67
- * @type {number}
68
- */
69
- mode: process.env.NODE_ENV === "production" ? 1 : 3,
70
- /**
71
- * 最大深度
72
- * @type {number}
73
- */
74
- max_depth: 6
75
- };
76
-
77
- /**
78
- * 构造函数
79
- * @param {object} config 配置参数
80
- * @param {object} parent 父级模块
81
- */
82
- constructor(config, parent) {
83
- super({ ...Task.config, ...config }, parent);
84
- }
85
- }
86
-
87
- /**
88
- * 任务驱动类
89
- * @type {Drive}
90
- */
91
- Task.prototype.Drive = Drive;
92
-
93
- /**
94
- * 执行任务
95
- * @param {string} name 要执行的名称
96
- */
97
- Task.prototype.run = async function (name) {
98
- if (name) {
99
- let mod = this.getMod(name);
100
- if (mod) {
101
- if (!mod.isLoaded()) {
102
- await mod.do("load");
103
- }
104
- await mod.run();
105
- }
106
- } else {
107
- let infos = this.getInfos();
108
- for (var i = 0, info; (info = infos[i++]);) {
109
- if (info.state === 1) {
110
- try {
111
- let mod = this.getMod(info.name);
112
- if (mod) {
113
- if (!mod.isLoaded()) {
114
- await mod.do("load");
115
- }
116
- await mod.run();
117
- }
118
- } catch (error) {
119
- this.log("error", "定时任务错误", info.name, error);
120
- }
121
- }
122
- }
123
- }
124
- };
125
-
126
- exports.Task = Task;
127
-
128
- /**
129
- * Task模板池
130
- */
131
- if (!$.pool.task) {
132
- $.pool.task = {};
133
- }
134
-
135
- /**
136
- * Task管理器,用于创建缓存
137
- * @param {string} scope 作用域
138
- * @param {string} title 标题
139
- * @returns {object} 返回一个缓存类
140
- */
141
- function taskAdmin(scope, title) {
142
- var sc = scope || $.val.scope + "";
143
- var obj = $.pool.task[sc];
144
- if (!obj) {
145
- $.pool.task[sc] = new Task({
146
- name: sc,
147
- title: title,
148
- });
149
- obj = $.pool.task[sc];
150
- }
151
- return obj;
152
- }
153
-
154
- /**
155
- * @module 导出Task管理器
156
- */
157
- if ($.admin) {
158
- $.admin.task = taskAdmin;
159
- }
@@ -1,40 +0,0 @@
1
-
2
- module.exports = {
3
- /**
4
- * 定时任务函数
5
- */
6
- async main() {
7
- this.log('debug', '定时任务, 执行中...');
8
- },
9
-
10
- /**
11
- * 执行结果通知
12
- * @param {string} name 任务名称
13
- * @param {string} state 状态
14
- */
15
- async notify(name, state) {
16
- switch (state) {
17
- case 'init':
18
- this.log('debug', '任务-初始化');
19
- break;
20
- case 'start':
21
- this.log('debug', '任务-开始执行');
22
- break;
23
- case 'stop':
24
- this.log('debug', '任务-已暂停');
25
- break;
26
- case 'suspend':
27
- // 主动中断
28
- this.log('debug', '任务-已中断');
29
- break;
30
- case 'time_end':
31
- this.log('debug', '任务-已到期');
32
- break;
33
- case 'completed':
34
- this.log('debug', '任务-已完成');
35
- break;
36
- default:
37
- break;
38
- }
39
- }
40
- };
@@ -1,5 +0,0 @@
1
- {
2
- "name": "模板管理器",
3
- "script": "./index.js",
4
- "state": 1
5
- }
@@ -1,16 +0,0 @@
1
- {
2
- // 模板名称
3
- "name": "",
4
- // 模板标题
5
- "title": "",
6
- // 描述
7
- "description": "",
8
- // 版本号
9
- "version": "1.0.0",
10
- // 预览图片
11
- "preview": "",
12
- // 预览图片(大图)
13
- "preview_large": "",
14
- // git仓库地址
15
- "git": ""
16
- }