@x-9lab/xlab 1.5.2 → 1.5.3

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.
@@ -2,6 +2,8 @@
2
2
  interface ICronJob {
3
3
  /**定时任务 */
4
4
  (): void;
5
+ /**定时任务 */
6
+ default?: () => void;
5
7
  /**获取定时任务间隔时间 */
6
8
  getDelay?: () => number;
7
9
  /**获取定时任务开启状态 */
@@ -12,7 +12,6 @@ _export(exports, {
12
12
  on: ()=>on,
13
13
  kill: ()=>kill
14
14
  });
15
- const _common = require("../common");
16
15
  const _utils = require("@x-drive/utils");
17
16
  const _util = require("util");
18
17
  const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
@@ -55,7 +54,11 @@ const config = getSysConfig("cron") || {
55
54
  if (!dont) {
56
55
  JOB_STATUS[name] = true;
57
56
  try {
58
- mod();
57
+ if ((0, _utils.isExecutable)(mod)) {
58
+ mod();
59
+ } else if (mod.default && (0, _utils.isExecutable)(mod.default())) {
60
+ mod.default();
61
+ }
59
62
  } catch (e) {
60
63
  logger.error((0, _util.inspect)(e));
61
64
  }
@@ -103,8 +106,8 @@ const config = getSysConfig("cron") || {
103
106
  var stats = _fs.default.statSync(tmpPath);
104
107
  if (stats.isFile()) {
105
108
  var name = cron.replace(".js", "");
106
- CRON_TIMERS[name] = fetch((0, _common.getRealDefaultMod)(require(_path.default.resolve(tmpPath))), name);
107
- logger.info("\t>>> [ %s ] %s.", name, CRON_TIMERS[name] ? "running" : "disabled");
109
+ CRON_TIMERS[name] = fetch(require(_path.default.resolve(tmpPath)), name);
110
+ logger.info("[ %s ] %s.", name, CRON_TIMERS[name] ? "running" : "disabled");
108
111
  }
109
112
  }
110
113
  }
package/dist/router.js CHANGED
@@ -91,28 +91,31 @@ function _interopRequireDefault(obj) {
91
91
  api = buildApi(api.join("/"));
92
92
  }
93
93
  // 是对象则取对应的字段
94
- if ((0, _utils.isObject)(mod) && ((0, _utils.isFunction)(mod.handler) || (0, _utils.isAsyncFunction)(mod.handler))) {
95
- modName = mod.method || "get";
96
- api = mod.api || api;
97
- apiPart = api.split("/");
98
- if (apiPart[0] !== "") {
99
- apiPart.unshift("");
100
- }
101
- // 保证一定是以 api 开头的
102
- if (!IS_API_REGEXP.test(api)) {
103
- api = buildApi(api);
104
- }
105
- if ((0, _utils.isArray)(mod.middleware)) {
106
- mod = [
107
- api,
108
- ...mod.middleware,
109
- mod.handler
110
- ];
111
- } else {
112
- mod = [
113
- api,
114
- mod.handler
115
- ];
94
+ if ((0, _utils.isObject)(mod)) {
95
+ const subjectMod = mod;
96
+ if ((0, _utils.isFunction)(subjectMod.handler) || (0, _utils.isAsyncFunction)(subjectMod.handler)) {
97
+ modName = subjectMod.method || "get";
98
+ api = subjectMod.api || api;
99
+ apiPart = api.split("/");
100
+ if (apiPart[0] !== "") {
101
+ apiPart.unshift("");
102
+ }
103
+ // 如果没有声明忽略检测则保证接口一定是以 api 开头的
104
+ if (!subjectMod.ignoreApiNameCheck && !IS_API_REGEXP.test(api)) {
105
+ api = buildApi(api);
106
+ }
107
+ if ((0, _utils.isArray)(subjectMod.middleware)) {
108
+ mod = [
109
+ api,
110
+ ...subjectMod.middleware,
111
+ subjectMod.handler
112
+ ];
113
+ } else {
114
+ mod = [
115
+ api,
116
+ subjectMod.handler
117
+ ];
118
+ }
116
119
  }
117
120
  }
118
121
  var dirMws = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-9lab/xlab",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "9lab 服务端模块",
5
5
  "versionDesc": "静态文件服务支持跨域",
6
6
  "scripts": {