-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds js-yaml and updated from PR feedback
- Loading branch information
Showing
20 changed files
with
169 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
port: '4001' | ||
mode: 'git' | ||
local-path: '..\\..\\files\\test' | ||
log-level: 'debug' | ||
apollo-path: '/lib' | ||
graphql-playground: 'true' | ||
|
||
git-repos: | ||
- user-1: | ||
repo-url: 'https://github.com/isomorphic-git/lightning-fs' | ||
- user-2: | ||
repo-url: 'https://github.com/isomorphic-git/lightning-fs' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export type ConfigValues = { | ||
'port': number; | ||
'local-path': string; | ||
'mode': string; | ||
'log-level': string; | ||
'apollo-path': string; | ||
'graphql-playground': string; | ||
'git-repos': {[key: string]: GitRepo}[]; | ||
}; | ||
|
||
export type GitRepo = { | ||
'repo-url': string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Global, Module } from '@nestjs/common'; | ||
import Config from './config.service.js'; | ||
import * as nestConfig from '@nestjs/config'; | ||
|
||
@Global() | ||
@Module({ | ||
imports: [nestConfig.ConfigModule.forRoot({ isGlobal: true })], | ||
providers: [ | ||
{ | ||
provide: Config, | ||
useFactory: async (envConfigservice: nestConfig.ConfigService) => { | ||
const confPath = envConfigservice.get<string>('LIBMS_CONFIG_PATH'); | ||
const config = new Config(); | ||
await config.loadConfig(confPath); | ||
return config; | ||
}, | ||
inject: [nestConfig.ConfigService], | ||
}, | ||
], | ||
exports: [Config], | ||
}) | ||
export class ConfigModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { readFileSync } from 'fs'; | ||
import * as yaml from 'js-yaml'; | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import {ConfigValues, GitRepo } from './config.model.js'; | ||
import resolveFile from './util.js'; | ||
|
||
@Injectable() | ||
export default class Config { | ||
private configValues: ConfigValues; | ||
private logger: Logger; | ||
|
||
constructor() { | ||
this.logger = new Logger(Config.name); | ||
} | ||
|
||
async loadConfig(configPath: string): Promise<void> { | ||
if (configPath !== undefined) { | ||
this.configValues = yaml.load( | ||
readFileSync(resolveFile(configPath), 'utf8'), | ||
) as ConfigValues; | ||
} | ||
this.logger.log('Config loaded', this.configValues); | ||
|
||
} | ||
|
||
getLocalPath(): string { | ||
return this.configValues['local-path']; | ||
} | ||
|
||
getApolloPath(): string { | ||
return this.configValues['apollo-path']; | ||
} | ||
|
||
getMode(): string { | ||
return this.configValues['mode']; | ||
} | ||
|
||
getPort(): number { | ||
return this.configValues['port']; | ||
} | ||
getLogLevel(): string { | ||
return this.configValues['log-level']; | ||
} | ||
getGraphqlPlayground(): string { | ||
return this.configValues['graphql-playground']; | ||
} | ||
getGitRepos(): {[key: string]: GitRepo}[] { | ||
return this.configValues['git-repos']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import path from 'node:path'; | ||
|
||
export default function resolveFile(name: string): string { | ||
return path.resolve(name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.