Extract ConfigReader to @rondo.dev/config pkg
This commit is contained in:
parent
ba45deda4f
commit
1bbc3ed97d
3
package-lock.json
generated
3
package-lock.json
generated
@ -2130,6 +2130,9 @@
|
||||
"@rondo.dev/common": {
|
||||
"version": "file:packages/common"
|
||||
},
|
||||
"@rondo.dev/config": {
|
||||
"version": "file:packages/config"
|
||||
},
|
||||
"@rondo.dev/image-upload": {
|
||||
"version": "file:packages/image-upload"
|
||||
},
|
||||
|
||||
@ -11,7 +11,8 @@
|
||||
"@rondo.dev/jsonrpc": "file:packages/jsonrpc",
|
||||
"@rondo.dev/scripts": "file:packages/scripts",
|
||||
"@rondo.dev/argparse": "file:packages/argparse",
|
||||
"@rondo.dev/logger": "file:packages/logger"
|
||||
"@rondo.dev/logger": "file:packages/logger",
|
||||
"@rondo.dev/config": "file:packages/config"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bcrypt": "^3.0.0",
|
||||
|
||||
2
packages/config/config/default.yml
Normal file
2
packages/config/config/default.yml
Normal file
@ -0,0 +1,2 @@
|
||||
app:
|
||||
name: 'config-test'
|
||||
16
packages/config/jest.config.js
Normal file
16
packages/config/jest.config.js
Normal file
@ -0,0 +1,16 @@
|
||||
module.exports = {
|
||||
roots: [
|
||||
'<rootDir>/src'
|
||||
],
|
||||
transform: {
|
||||
'^.+\\.tsx?$': 'ts-jest'
|
||||
},
|
||||
testRegex: '(/__tests__/.*|\\.(test|spec))\\.tsx?$',
|
||||
moduleFileExtensions: [
|
||||
'ts',
|
||||
'tsx',
|
||||
'js',
|
||||
'jsx'
|
||||
],
|
||||
setupFiles: ['<rootDir>/jest.setup.js']
|
||||
}
|
||||
4
packages/config/jest.setup.js
Normal file
4
packages/config/jest.setup.js
Normal file
@ -0,0 +1,4 @@
|
||||
if (!process.env.LOG) {
|
||||
process.env.LOG = 'sql:warn'
|
||||
}
|
||||
process.chdir(__dirname)
|
||||
4
packages/config/package-lock.json
generated
Normal file
4
packages/config/package-lock.json
generated
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "@rondo.dev/config",
|
||||
"lockfileVersion": 1
|
||||
}
|
||||
13
packages/config/package.json
Normal file
13
packages/config/package.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "@rondo.dev/config",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"lint": "tslint --project .",
|
||||
"compile": "tsc",
|
||||
"clean": "rm -rf lib/"
|
||||
},
|
||||
"dependencies": {},
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts"
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
import YAML from 'js-yaml'
|
||||
import {Config} from './Config'
|
||||
import {findPackageRoot} from '../files/Find'
|
||||
import {join} from 'path'
|
||||
import { readFileSync } from 'fs'
|
||||
import {apiLogger} from '../logger'
|
||||
import YAML from 'js-yaml'
|
||||
import { join } from 'path'
|
||||
import { Config } from './Config'
|
||||
import { findPackageRoot } from './findPackageRoot'
|
||||
import loggerFactory, {ILogger} from '@rondo.dev/logger'
|
||||
|
||||
const isObject = (value: any) => value !== null && typeof value === 'object'
|
||||
|
||||
@ -16,6 +16,7 @@ export class ConfigReader {
|
||||
readonly path: string,
|
||||
readonly cwd: string | undefined = process.cwd(),
|
||||
readonly environment = 'CONFIG',
|
||||
readonly logger: ILogger = loggerFactory.getLogger('config'),
|
||||
) {
|
||||
const packageRoot = path && findPackageRoot(path)
|
||||
this.locations = packageRoot ? [packageRoot] : []
|
||||
@ -41,7 +42,7 @@ export class ConfigReader {
|
||||
}
|
||||
continue
|
||||
}
|
||||
apiLogger.info('config: Found config file: %s', configFilename)
|
||||
this.logger.info('config: Found config file: %s', configFilename)
|
||||
success += 1
|
||||
}
|
||||
}
|
||||
@ -52,12 +53,12 @@ export class ConfigReader {
|
||||
}
|
||||
|
||||
if (filename) {
|
||||
apiLogger.info('config: Reading extra config file: %s', filename)
|
||||
this.logger.info('config: Reading extra config file: %s', filename)
|
||||
this.readFile(filename)
|
||||
}
|
||||
|
||||
if (env) {
|
||||
apiLogger.info('config: Parsing env variable: %s', this.environment)
|
||||
this.logger.info('config: Parsing env variable: %s', this.environment)
|
||||
this.parse(env)
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import {resolve, join} from 'path'
|
||||
import {statSync, Stats} from 'fs'
|
||||
|
||||
export function findNearestDirectory(
|
||||
function findNearestDirectory(
|
||||
dir: string, filename: string,
|
||||
) {
|
||||
let currentDir = dir
|
||||
4
packages/config/src/index.ts
Normal file
4
packages/config/src/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export * from './Config'
|
||||
|
||||
import {ConfigReader} from './ConfigReader'
|
||||
export default ConfigReader
|
||||
10
packages/config/tsconfig.json
Normal file
10
packages/config/tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../tsconfig.common.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "lib",
|
||||
"rootDir": "src"
|
||||
},
|
||||
"references": [
|
||||
{"path": "../logger"}
|
||||
]
|
||||
}
|
||||
10
packages/config/tslint.json
Normal file
10
packages/config/tslint.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": [
|
||||
"../tslint.json"
|
||||
],
|
||||
"linterOptions": {
|
||||
"exclude": [
|
||||
"src/migrations/*.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
import {ConfigReader} from './config/index'
|
||||
import ConfigReader from '@rondo.dev/config'
|
||||
import {IConfig} from './application'
|
||||
import URL from 'url'
|
||||
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
export * from './Config'
|
||||
export * from './ConfigReader'
|
||||
@ -1,5 +1,4 @@
|
||||
export * from './application'
|
||||
export * from './config/index'
|
||||
export * from './database'
|
||||
export * from './entities'
|
||||
export * from './error'
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
"references": [
|
||||
{"path": "../common"},
|
||||
{"path": "../jsonrpc"},
|
||||
{"path": "../logger"}
|
||||
{"path": "../logger"},
|
||||
{"path": "../config"}
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user