-
-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathapp.module.ts
52 lines (43 loc) · 1.52 KB
/
app.module.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {Inject, Module, OnApplicationBootstrap} from '@nestjs/common';
import {HttpModule} from '@nestjs/axios';
import {Command} from 'commander';
import {COMMANDER_PROGRAM, LOGGER} from './constants';
import {VersionManagerController} from './controllers/version-manager.controller';
import {ConfigService, GeneratorService, PassThroughService, UIService, VersionManagerService} from './services';
@Module({
imports: [HttpModule],
controllers: [
VersionManagerController
],
providers: [
UIService,
ConfigService,
GeneratorService,
PassThroughService,
VersionManagerService,
{
provide: COMMANDER_PROGRAM,
useValue: new Command('openapi-generator-cli').helpOption(false).usage('<command> [<args>]')
},
{provide: LOGGER, useValue: console}
]
})
export class AppModule implements OnApplicationBootstrap {
constructor(
@Inject(COMMANDER_PROGRAM) private readonly program: Command,
private readonly versionManager: VersionManagerService,
private readonly passThroughService: PassThroughService
) {
}
onApplicationBootstrap = async () => {
let selectedVersion = this.versionManager.getSelectedVersion();
if (!selectedVersion) {
const [{version}] = await this.versionManager.search(['latest']).toPromise();
await this.versionManager.setSelectedVersion(version);
selectedVersion = version;
}
await this.versionManager.downloadIfNeeded(selectedVersion);
await this.passThroughService.init();
this.program.parse(process.argv);
};
}