-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathapp.ts
More file actions
33 lines (28 loc) · 1.11 KB
/
app.ts
File metadata and controls
33 lines (28 loc) · 1.11 KB
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
31
32
33
import { Application } from 'egg';
import { ModuleConfigUtil, ModuleReference } from '@eggjs/tegg-common-util';
import { ModuleScanner } from './lib/ModuleScanner';
export default class App {
private readonly app: Application;
constructor(app: Application) {
this.app = app;
}
configWillLoad() {
const { readModuleOptions } = this.app.config.tegg || {};
const moduleScanner = new ModuleScanner(this.app.baseDir, readModuleOptions);
this.app.moduleReferences = moduleScanner.loadModuleReferences();
this.app.moduleConfigs = {};
for (const reference of this.app.moduleReferences) {
const absoluteRef: ModuleReference = {
path: ModuleConfigUtil.resolveModuleDir(reference.path, this.app.baseDir),
name: reference.name,
optional: reference.optional,
};
const moduleName = ModuleConfigUtil.readModuleNameSync(absoluteRef.path);
this.app.moduleConfigs[moduleName] = {
name: moduleName,
reference: absoluteRef,
config: ModuleConfigUtil.loadModuleConfigSync(absoluteRef.path, undefined, this.app.config.env) || {},
};
}
}
}