-
-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathapp.module.ts
More file actions
80 lines (74 loc) · 2.45 KB
/
app.module.ts
File metadata and controls
80 lines (74 loc) · 2.45 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { Inject, Module, OnApplicationBootstrap } from '@nestjs/common';
import { HttpModule, HttpModuleOptions } from '@nestjs/axios';
import { Command } from 'commander';
import { COMMANDER_PROGRAM, LOGGER } from './constants';
import { VersionManagerController } from './controllers/version-manager.controller';
import {
ConfigService,
GeneratorService,
NpmrcService,
PassThroughService,
UIService,
VersionManagerService,
} from './services';
import { Agent } from 'https';
export const httpModuleConfigFactory = async (configService: ConfigService, npmrcService: NpmrcService): Promise<HttpModuleOptions> => {
const strictSsl = configService.useNpmrc() ? npmrcService.getStrictSsl() : true;
const rejectUnauthorized = configService.get('generator-cli.http.rejectUnauthorized', true);
const httpsAgent = !strictSsl || !rejectUnauthorized ? new Agent({
rejectUnauthorized: false,
}) : undefined;
return {
httpsAgent: httpsAgent,
};
};
@Module({
imports: [
HttpModule.registerAsync({
imports: [AppModule],
useFactory: httpModuleConfigFactory,
inject: [ConfigService, NpmrcService],
}),
],
controllers: [VersionManagerController],
exports: [ConfigService, NpmrcService],
providers: [
UIService,
ConfigService,
GeneratorService,
NpmrcService,
PassThroughService,
VersionManagerService,
{
provide: COMMANDER_PROGRAM,
useValue: new Command('openapi-generator-cli')
.helpOption(false)
.usage('<command> [<args>]')
.option(
'--openapitools <openapitools.json>',
'Use the specified openapi-generator-cli configuration file',
),
},
{ 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);
};
}