-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathagent.ts
30 lines (26 loc) · 1015 Bytes
/
agent.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import * as path from 'path';
import { Agent } from 'egg';
import { genAPISDKByPath } from './lib/meta/gen_sdk';
export default (agent: Agent) => {
const config = agent.config.controller;
if (config.genSDK.enable) {
let { enable, filter, ...rest } = config.genSDK;
if (!rest.sdkDir) {
throw new Error(`[egg-controller] NEED 'SDKDir' in config!`);
}
const ctrlDir = ([] as string[]).concat(config.ctrlDir).map(dir => {
return path.isAbsolute(dir) ? dir : path.join(agent.baseDir, dir);
});
rest.sdkDir = path.isAbsolute(rest.sdkDir)
? rest.sdkDir
: path.join(agent.baseDir, rest.sdkDir);
console.log('[egg-controller] gen api sdk.');
genAPISDKByPath(ctrlDir, filter, rest, agent.config, config.fork);
ctrlDir.forEach(dir => {
(agent as any).watcher.watch(dir, (file: any) => {
console.log('[egg-controller] file changed', file.path);
genAPISDKByPath(ctrlDir, filter, rest, agent.config, config.fork);
});
});
}
};