-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
67 lines (60 loc) · 1.59 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as dotenv from 'dotenv';
//#if _MATBAS_BUILD == 'debug'
dotenv.config();
//#endif
import { Module } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { Exit } from './exit';
import { Translator } from './translator';
import { Config, Argv, Env } from './config';
import { ConsoleHost } from './host';
import { Editor } from './editor';
import { Executor } from './executor';
async function exit(code: number) {
process.exit(code);
}
function configFactory(argv: Argv, env: Env) {
try {
return Config.load(argv, env);
} catch (err) {
// Normally we would count on the Translator to handle these sorts of
// errors. In this case, the error is thrown before the Translator is
// stood up, so we have to special case it here.
if (err instanceof Exit) {
if (err.message.length) {
console.log(err.message);
}
process.exit(err.exitCode);
}
throw err;
}
}
@Module({
providers: [
{ provide: 'argv', useValue: process.argv.slice(2) },
{ provide: 'env', useValue: process.env },
{ provide: 'exitFn', useValue: exit },
{
provide: Config,
useFactory: configFactory,
inject: ['argv', 'env'],
},
{
provide: 'Host',
useClass: ConsoleHost,
},
Editor,
Executor,
Translator,
],
})
export class Container {}
export async function main(): Promise<void> {
const deps = await NestFactory.createApplicationContext(Container, {
//#if _MATBAS_BUILD != 'debug'
logger: false,
//#endif
});
const translator = deps.get(Translator);
await translator.start();
}