@zenweb/schedule 1.0.0 → 2.3.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.
- package/dist/index.d.ts +4 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/register.d.ts +14 -0
- package/dist/register.js +71 -0
- package/dist/register.js.map +1 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +10 -9
- package/src/index.ts +27 -0
- package/{lib/register.js → src/register.ts} +24 -30
- package/src/types.ts +9 -0
- package/tsconfig.json +21 -0
- package/.eslintrc +0 -14
- package/index.js +0 -29
- package/lib/debug.js +0 -3
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.setup = void 0;
|
|
14
|
+
const globby = require("globby");
|
|
15
|
+
const path = require("path");
|
|
16
|
+
const register_1 = require("./register");
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
function setup(option) {
|
|
19
|
+
return async function schedule(setup) {
|
|
20
|
+
option = Object.assign({
|
|
21
|
+
paths: [path.join(process.cwd(), 'app', 'schedule')],
|
|
22
|
+
}, option);
|
|
23
|
+
setup.debug('option: %o', option);
|
|
24
|
+
const register = new register_1.ScheduleRegister(setup.core, option);
|
|
25
|
+
setup.defineCoreProperty('schedule', { value: register });
|
|
26
|
+
if (option.paths && option.paths.length) {
|
|
27
|
+
for (const d of option.paths) {
|
|
28
|
+
let count = 0;
|
|
29
|
+
for (const m of await globby(d, { cwd: d, absolute: true })) {
|
|
30
|
+
require(m);
|
|
31
|
+
count++;
|
|
32
|
+
}
|
|
33
|
+
setup.debug('load: %s %o files', d, count);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.setup = setup;
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iCAAiC;AAEjC,6BAA8B;AAC9B,yCAA8C;AAE9C,0CAAwB;AAExB,SAAgB,KAAK,CAAC,MAAuB;IAC3C,OAAO,KAAK,UAAU,QAAQ,CAAC,KAAK;QAClC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;YACrB,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;SACrD,EAAE,MAAM,CAAC,CAAC;QACX,KAAK,CAAC,KAAK,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAClC,MAAM,QAAQ,GAAG,IAAI,2BAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC1D,KAAK,CAAC,kBAAkB,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC1D,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE;YACvC,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,EAAE;gBAC5B,IAAI,KAAK,GAAG,CAAC,CAAC;gBACd,KAAK,MAAM,CAAC,IAAI,MAAM,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE;oBAC3D,OAAO,CAAC,CAAC,CAAC,CAAC;oBACX,KAAK,EAAE,CAAC;iBACT;gBACD,KAAK,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;aAC5C;SACF;IACH,CAAC,CAAA;AACH,CAAC;AAnBD,sBAmBC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="koa__router" />
|
|
2
|
+
import '@zenweb/router';
|
|
3
|
+
import schedule = require('node-schedule');
|
|
4
|
+
import { Core } from '@zenweb/core';
|
|
5
|
+
import { RequestCallback, ScheduleOption } from './types';
|
|
6
|
+
import { Router } from '@zenweb/router';
|
|
7
|
+
export declare class ScheduleRegister {
|
|
8
|
+
option: ScheduleOption;
|
|
9
|
+
router: Router;
|
|
10
|
+
callback: RequestCallback;
|
|
11
|
+
private _index;
|
|
12
|
+
constructor(core: Core, option?: ScheduleOption);
|
|
13
|
+
job(...args: any[]): schedule.Job;
|
|
14
|
+
}
|
package/dist/register.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScheduleRegister = void 0;
|
|
4
|
+
require("@zenweb/router");
|
|
5
|
+
const schedule = require("node-schedule");
|
|
6
|
+
const http_1 = require("http");
|
|
7
|
+
const SAFE_IP = '127.0.0.1';
|
|
8
|
+
/**
|
|
9
|
+
* 安全检查,防止外部调用
|
|
10
|
+
*/
|
|
11
|
+
function safeCheck(ctx, next) {
|
|
12
|
+
if (!ctx.req.socket.remoteAddress || !ctx.req.socket.remoteAddress.endsWith(SAFE_IP)) {
|
|
13
|
+
ctx.throw(403);
|
|
14
|
+
}
|
|
15
|
+
return next();
|
|
16
|
+
}
|
|
17
|
+
class ScheduleRegister {
|
|
18
|
+
constructor(core, option) {
|
|
19
|
+
this.option = option || {};
|
|
20
|
+
this.router = core.router;
|
|
21
|
+
this.callback = core.koa.callback();
|
|
22
|
+
this._index = 0;
|
|
23
|
+
}
|
|
24
|
+
job(...args) {
|
|
25
|
+
let name = '';
|
|
26
|
+
let rule;
|
|
27
|
+
if (typeof args[1] === 'string') {
|
|
28
|
+
name = args[0];
|
|
29
|
+
rule = args[1];
|
|
30
|
+
args = args.slice(2);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
rule = args[0];
|
|
34
|
+
args = args.slice(1);
|
|
35
|
+
}
|
|
36
|
+
// 注册到路由
|
|
37
|
+
const path = `/___schedule/job/${this._index++}/${name}`;
|
|
38
|
+
this.router.post(path, safeCheck, ...args);
|
|
39
|
+
// 注册到 scheduleJob
|
|
40
|
+
const callback = () => {
|
|
41
|
+
const request = Object.assign({
|
|
42
|
+
headers: {
|
|
43
|
+
host: '127.0.0.1',
|
|
44
|
+
},
|
|
45
|
+
query: {},
|
|
46
|
+
querystring: '',
|
|
47
|
+
host: '127.0.0.1',
|
|
48
|
+
hostname: '127.0.0.1',
|
|
49
|
+
protocol: 'http',
|
|
50
|
+
secure: 'false',
|
|
51
|
+
method: 'POST',
|
|
52
|
+
url: path,
|
|
53
|
+
path: path,
|
|
54
|
+
socket: {
|
|
55
|
+
remoteAddress: SAFE_IP,
|
|
56
|
+
remotePort: 7001,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
const response = new http_1.ServerResponse(request);
|
|
60
|
+
if (this.option.jobCallback) {
|
|
61
|
+
this.option.jobCallback(request, response, this.callback);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
this.callback(request, response);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return schedule.scheduleJob(name, rule, callback);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.ScheduleRegister = ScheduleRegister;
|
|
71
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":";;;AAAA,0BAAwB;AACxB,0CAA2C;AAC3C,+BAAuD;AAMvD,MAAM,OAAO,GAAG,WAAW,CAAC;AAE5B;;GAEG;AACH,SAAS,SAAS,CAAC,GAAY,EAAE,IAAU;IACzC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACpF,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;KAChB;IACD,OAAO,IAAI,EAAE,CAAC;AAChB,CAAC;AAED,MAAa,gBAAgB;IAM3B,YAAY,IAAU,EAAE,MAAuB;QAC7C,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC;IAED,GAAG,CAAC,GAAG,IAAW;QAChB,IAAI,IAAI,GAAG,EAAE,CAAC;QACd,IAAI,IAAI,CAAC;QAET,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;YAC/B,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YACf,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YACf,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACtB;aAAM;YACL,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YACf,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACtB;QAED,QAAQ;QACR,MAAM,IAAI,GAAG,oBAAoB,IAAI,CAAC,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;QACzD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;QAE3C,kBAAkB;QAClB,MAAM,QAAQ,GAAG,GAAG,EAAE;YACpB,MAAM,OAAO,GAAoB,MAAM,CAAC,MAAM,CAAC;gBAC7C,OAAO,EAAE;oBACP,IAAI,EAAE,WAAW;iBAClB;gBACD,KAAK,EAAE,EAAE;gBACT,WAAW,EAAE,EAAE;gBACf,IAAI,EAAE,WAAW;gBACjB,QAAQ,EAAE,WAAW;gBACrB,QAAQ,EAAE,MAAM;gBAChB,MAAM,EAAE,OAAO;gBACf,MAAM,EAAE,MAAM;gBACd,GAAG,EAAE,IAAI;gBACT,IAAI,EAAE,IAAI;gBACV,MAAM,EAAE;oBACN,aAAa,EAAE,OAAO;oBACtB,UAAU,EAAE,IAAI;iBACjB;aACF,CAAC,CAAC;YACH,MAAM,QAAQ,GAAG,IAAI,qBAAc,CAAC,OAAO,CAAC,CAAC;YAC7C,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;gBAC3B,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;aAC3D;iBAAM;gBACL,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;aAClC;QACH,CAAC,CAAC;QACF,OAAO,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IACpD,CAAC;CACF;AA3DD,4CA2DC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ServerResponse, IncomingMessage } from 'http';
|
|
3
|
+
export declare type RequestCallback = (request: IncomingMessage, response: ServerResponse) => void;
|
|
4
|
+
export declare type JobCallback = (request: IncomingMessage, response: ServerResponse, callback: RequestCallback) => void;
|
|
5
|
+
export interface ScheduleOption {
|
|
6
|
+
paths?: string[];
|
|
7
|
+
jobCallback?: JobCallback;
|
|
8
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenweb/schedule",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Zenweb Schedule module",
|
|
5
|
-
"
|
|
5
|
+
"exports": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
+
"prepublishOnly": "rm -fr dist && tsc"
|
|
8
9
|
},
|
|
9
10
|
"author": {
|
|
10
11
|
"name": "YeFei",
|
|
@@ -28,13 +29,13 @@
|
|
|
28
29
|
"url": "https://github.com/yefei/zenweb-schedule/issues"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"zenweb": "^
|
|
32
|
+
"@types/node-schedule": "^1.3.2",
|
|
33
|
+
"@zenweb/core": "^2.3.2",
|
|
34
|
+
"@zenweb/router": "^2.3.0",
|
|
35
|
+
"zenweb": "^2.3.1"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"node-schedule": "^2.0.0"
|
|
38
|
+
"node-schedule": "^2.0.0",
|
|
39
|
+
"globby": "11.0.4"
|
|
39
40
|
}
|
|
40
41
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as globby from 'globby';
|
|
2
|
+
import { SetupFunction } from '@zenweb/core';
|
|
3
|
+
import path = require('path');
|
|
4
|
+
import { ScheduleRegister } from './register';
|
|
5
|
+
import { ScheduleOption } from './types';
|
|
6
|
+
export * from './types';
|
|
7
|
+
|
|
8
|
+
export function setup(option?: ScheduleOption): SetupFunction {
|
|
9
|
+
return async function schedule(setup) {
|
|
10
|
+
option = Object.assign({
|
|
11
|
+
paths: [path.join(process.cwd(), 'app', 'schedule')],
|
|
12
|
+
}, option);
|
|
13
|
+
setup.debug('option: %o', option);
|
|
14
|
+
const register = new ScheduleRegister(setup.core, option);
|
|
15
|
+
setup.defineCoreProperty('schedule', { value: register });
|
|
16
|
+
if (option.paths && option.paths.length) {
|
|
17
|
+
for (const d of option.paths) {
|
|
18
|
+
let count = 0;
|
|
19
|
+
for (const m of await globby(d, { cwd: d, absolute: true })) {
|
|
20
|
+
require(m);
|
|
21
|
+
count++;
|
|
22
|
+
}
|
|
23
|
+
setup.debug('load: %s %o files', d, count);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import '@zenweb/router';
|
|
2
|
+
import schedule = require('node-schedule');
|
|
3
|
+
import { ServerResponse, IncomingMessage } from 'http';
|
|
4
|
+
import { Context, Next } from 'koa';
|
|
5
|
+
import { Core } from '@zenweb/core';
|
|
6
|
+
import { RequestCallback, ScheduleOption } from './types';
|
|
7
|
+
import { Router } from '@zenweb/router';
|
|
5
8
|
|
|
6
9
|
const SAFE_IP = '127.0.0.1';
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* 安全检查,防止外部调用
|
|
10
|
-
* @param {import('koa').Context} ctx
|
|
11
|
-
* @param {import('koa').Middleware} next
|
|
12
13
|
*/
|
|
13
|
-
function safeCheck(ctx, next) {
|
|
14
|
+
function safeCheck(ctx: Context, next: Next) {
|
|
14
15
|
if (!ctx.req.socket.remoteAddress || !ctx.req.socket.remoteAddress.endsWith(SAFE_IP)) {
|
|
15
16
|
ctx.throw(403);
|
|
16
17
|
}
|
|
17
18
|
return next();
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
class ScheduleRegister {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
constructor(core,
|
|
27
|
-
this.
|
|
21
|
+
export class ScheduleRegister {
|
|
22
|
+
option: ScheduleOption;
|
|
23
|
+
router: Router;
|
|
24
|
+
callback: RequestCallback;
|
|
25
|
+
private _index: number;
|
|
26
|
+
|
|
27
|
+
constructor(core: Core, option?: ScheduleOption) {
|
|
28
|
+
this.option = option || {};
|
|
28
29
|
this.router = core.router;
|
|
29
30
|
this.callback = core.koa.callback();
|
|
30
31
|
this._index = 0;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
job(...args) {
|
|
34
|
+
job(...args: any[]) {
|
|
34
35
|
let name = '';
|
|
35
36
|
let rule;
|
|
36
37
|
|
|
@@ -48,11 +49,8 @@ class ScheduleRegister {
|
|
|
48
49
|
this.router.post(path, safeCheck, ...args);
|
|
49
50
|
|
|
50
51
|
// 注册到 scheduleJob
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
jobArgs.push(rule);
|
|
54
|
-
jobArgs.push(() => {
|
|
55
|
-
const request = {
|
|
52
|
+
const callback = () => {
|
|
53
|
+
const request: IncomingMessage = Object.assign({
|
|
56
54
|
headers: {
|
|
57
55
|
host: '127.0.0.1',
|
|
58
56
|
},
|
|
@@ -69,18 +67,14 @@ class ScheduleRegister {
|
|
|
69
67
|
remoteAddress: SAFE_IP,
|
|
70
68
|
remotePort: 7001,
|
|
71
69
|
},
|
|
72
|
-
};
|
|
70
|
+
});
|
|
73
71
|
const response = new ServerResponse(request);
|
|
74
|
-
if (this.
|
|
75
|
-
this.
|
|
72
|
+
if (this.option.jobCallback) {
|
|
73
|
+
this.option.jobCallback(request, response, this.callback);
|
|
76
74
|
} else {
|
|
77
75
|
this.callback(request, response);
|
|
78
76
|
}
|
|
79
|
-
}
|
|
80
|
-
return schedule.scheduleJob(
|
|
77
|
+
};
|
|
78
|
+
return schedule.scheduleJob(name, rule, callback);
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
|
-
|
|
84
|
-
module.exports = {
|
|
85
|
-
ScheduleRegister,
|
|
86
|
-
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ServerResponse, IncomingMessage } from 'http';
|
|
2
|
+
|
|
3
|
+
export type RequestCallback = (request: IncomingMessage, response: ServerResponse) => void;
|
|
4
|
+
export type JobCallback = (request: IncomingMessage, response: ServerResponse, callback: RequestCallback) => void;
|
|
5
|
+
|
|
6
|
+
export interface ScheduleOption {
|
|
7
|
+
paths?: string[];
|
|
8
|
+
jobCallback?: JobCallback;
|
|
9
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2019",
|
|
4
|
+
"lib": [
|
|
5
|
+
"ES2019"
|
|
6
|
+
],
|
|
7
|
+
"module": "commonjs",
|
|
8
|
+
"noImplicitAny": true,
|
|
9
|
+
"preserveConstEnums": true,
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"outDir": "./dist"
|
|
13
|
+
},
|
|
14
|
+
"exclude": [
|
|
15
|
+
"node_modules",
|
|
16
|
+
"**/*.spec.ts"
|
|
17
|
+
],
|
|
18
|
+
"include": [
|
|
19
|
+
"src/**/*"
|
|
20
|
+
]
|
|
21
|
+
}
|
package/.eslintrc
DELETED
package/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const { discover } = require('@feiye/discover');
|
|
5
|
-
const debug = require('./lib/debug');
|
|
6
|
-
const { ScheduleRegister } = require('./lib/register');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @param {import('@zenweb/core').Core} core
|
|
10
|
-
* @param {*} [options]
|
|
11
|
-
*/
|
|
12
|
-
function setup(core, options) {
|
|
13
|
-
options = Object.assign({
|
|
14
|
-
paths: [path.join(process.cwd(), 'app', 'schedule')],
|
|
15
|
-
}, options);
|
|
16
|
-
debug('options: %o', options);
|
|
17
|
-
const register = new ScheduleRegister(core, options);
|
|
18
|
-
Object.defineProperty(core, 'schedule', { value: register });
|
|
19
|
-
if (options.paths && options.paths.length) {
|
|
20
|
-
options.paths.forEach(path => {
|
|
21
|
-
const count = discover(path);
|
|
22
|
-
debug('load: %s %o files', path, count);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
module.exports = {
|
|
28
|
-
setup,
|
|
29
|
-
};
|
package/lib/debug.js
DELETED