mm_machine 1.7.8 → 1.8.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 (3) hide show
  1. package/index.js +18 -6
  2. package/package.json +35 -35
  3. package/test.js +4 -3
package/index.js CHANGED
@@ -324,14 +324,27 @@ Item.prototype.main = async function(...params) {
324
324
  Item.prototype.run = async function(method, ...params) {
325
325
  if (this[method]) {
326
326
  if (this[method + "_before"]) {
327
- this[method + "_before"](...params);
327
+ try {
328
+ this[method + "_before"](...params);
329
+ } catch (err) {
330
+ $.log.error("执行前失败!", err);
331
+ }
332
+ }
333
+ var ret;
334
+ try {
335
+ ret = this[method](...params);
336
+ } catch (err) {
337
+ $.log.error("执行时失败!", err);
328
338
  }
329
- var ret = this[method](...params);
330
339
  if (util.types.isPromise(ret)) {
331
340
  ret = await ret;
332
341
  }
333
342
  if (this[method + "_after"]) {
334
- ret = this[method + "_after"](ret, ...params) || ret;
343
+ try {
344
+ ret = this[method + "_after"](ret, ...params) || ret;
345
+ } catch (err) {
346
+ $.log.error("执行后失败!", err);
347
+ }
335
348
  }
336
349
  if (util.types.isPromise(ret)) {
337
350
  ret = await ret;
@@ -345,7 +358,7 @@ Item.prototype.run = async function(method, ...params) {
345
358
  * @param {Number} state 状态 0为不可以,1为可用
346
359
  * @param {Array} ...params 参数集合
347
360
  */
348
- Item.prototype.run_cmd = function(state, ...params) {
361
+ Item.prototype.run_cmd = async function(state, ...params) {
349
362
  return null;
350
363
  };
351
364
 
@@ -355,7 +368,6 @@ Item.prototype.run_cmd = function(state, ...params) {
355
368
  * @param {Array} ...params 参数集合
356
369
  */
357
370
  Item.prototype.cmd = function(state, ...params) {
358
- this.config.state = state;
359
371
  return this.run_cmd(state, ...param);
360
372
  }
361
373
 
@@ -572,7 +584,7 @@ Index.prototype.cmd = async function(name, state, ...params) {
572
584
  if (!obj) {
573
585
  return "error: program does not exist";
574
586
  }
575
- return await obj.cmd(name, ...params);
587
+ return await obj.run("cmd", state, ...params);
576
588
  }
577
589
 
578
590
  /**
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
1
  {
2
- "name": "mm_machine",
3
- "version": "1.7.8",
4
- "description": "这是超级美眉框架机制构建辅助模块,用于快速构建一个机制",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "node ./test.js",
8
- "dev": "nodemon ./test.js"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/qiuwenwu/mm_machine.git"
13
- },
14
- "keywords": [
15
- "common",
16
- "com",
17
- "run",
18
- "cmd",
19
- "load",
20
- "save",
21
- "get",
22
- "set",
23
- "add",
24
- "del"
25
- ],
26
- "author": "邱文武",
27
- "license": "ISC",
28
- "bugs": {
29
- "url": "https://github.com/qiuwenwu/mm_machine/issues"
30
- },
31
- "homepage": "https://github.com/qiuwenwu/mm_machine#readme",
32
- "dependencies": {
33
- "mm_config": "^1.1.3",
34
- "mm_hot_reload": "^1.0.1"
35
- }
36
- }
2
+ "name": "mm_machine",
3
+ "version": "1.8.0",
4
+ "description": "这是超级美眉框架机制构建辅助模块,用于快速构建一个机制",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "node ./test.js",
8
+ "dev": "nodemon ./test.js"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/qiuwenwu/mm_machine.git"
13
+ },
14
+ "keywords": [
15
+ "common",
16
+ "com",
17
+ "run",
18
+ "cmd",
19
+ "load",
20
+ "save",
21
+ "get",
22
+ "set",
23
+ "add",
24
+ "del"
25
+ ],
26
+ "author": "邱文武",
27
+ "license": "ISC",
28
+ "bugs": {
29
+ "url": "https://github.com/qiuwenwu/mm_machine/issues"
30
+ },
31
+ "homepage": "https://github.com/qiuwenwu/mm_machine#readme",
32
+ "dependencies": {
33
+ "mm_config": "^1.1.3",
34
+ "mm_hot_reload": "^1.0.1"
35
+ }
36
+ }
package/test.js CHANGED
@@ -26,9 +26,10 @@ async function demo() {
26
26
  var engine = new Engine();
27
27
  console.info("→ 加载mod");
28
28
  await engine.update("./".fullname(__dirname));
29
- engine.run('demo1', 'init');
30
- engine.exec('demo1', 'init');
31
- // engine.run(null, 'init');
29
+ await engine.run('demo1', 'init');
30
+ await engine.exec('demo1', 'init');
31
+ await engine.run(null, 'main');
32
+ await engine.exec(null, 'main');
32
33
  // console.log("模块数", engine.list.length);
33
34
 
34
35
  // var i = 0;