Skip to content

Commit a4c4fb7

Browse files
committed
fix: first functionnal release
1 parent 3b9d498 commit a4c4fb7

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/_common/backend-initializer/config.initializer.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,25 @@ import path from 'path';
88
import { Logger } from '@nestjs/common';
99
import { validateOrReject } from 'class-validator';
1010

11-
export default async function configInitializer(backendsPath: string) {
11+
const backendsConfig: BackendConfigDto[] = [];
12+
13+
export default async function configInitializer(backendsPath: string): Promise<BackendConfigDto[]> {
14+
/**
15+
* If backendsConfig is not empty, it cached in memory, return it
16+
*/
17+
if (backendsConfig.length) return backendsConfig;
18+
1219
const logger = new Logger(configInitializer.name);
1320
logger.log('load backends config');
1421

15-
const backendsConfig = [];
16-
const crawler = new fdir().withBasePath().filter((path) => path.endsWith('.yml'));
22+
const crawler = new fdir().withBasePath().filter((path: string) => path.endsWith('.yml'));
1723
const files = crawler.crawl(backendsPath).sync().sort();
1824

1925
for await (const file of files) {
2026
logger.log('Load ' + file);
2127
const data = fs.readFileSync(file, 'utf8');
2228
const config = YAML.parse(data);
29+
2330
try {
2431
config.path = path.dirname(file);
2532
const schema = plainToInstance(BackendConfigDto, config);

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NestFactory } from '@nestjs/core';
22
import { AppModule } from './app.module';
33
import { LogLevel } from '@nestjs/common';
4-
import ConfigInstance from './config';
4+
import configInstance from './config';
55

66
declare const module: any;
77
(async (): Promise<void> => {
@@ -17,8 +17,8 @@ declare const module: any;
1717

1818
async function setLogLevel(): Promise<LogLevel[]> {
1919
let loggerOptions: LogLevel[] = ['error', 'warn', 'fatal'];
20-
const configInstance = await ConfigInstance();
21-
switch (configInstance['logLevel']) {
20+
const config = await configInstance();
21+
switch (config['logLevel']) {
2222
case 'fatal':
2323
loggerOptions = ['fatal'];
2424
break;

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"module": "CommonJS",
44
"moduleResolution": "Node",
5+
"lib": ["ESNext"],
56
"declaration": true,
67
"removeComments": true,
78
"skipLibCheck": true,

0 commit comments

Comments
 (0)