0.0.6 • Published 5 years ago

@odanado/config-loader v0.0.6

Weekly downloads
6
License
MIT
Repository
-
Last release
5 years ago

config-loader

Build Status Coverage Status

Installation

$ yarn add @odanado/config-loader

Usage

In config directory

// config/index.ts
export interface ConfigScheme {
  RDB_USER: string
  RDB_DB_NAME: string
  RDB_PASSWORD: string
}


// config/development.ts
import { MapPlugin, DefinePlugin } from "@odanado/config-loader"
import { ConfigScheme } from "./"

const mapPlugin: MapPlugin<ConfigScheme> = {
  RDB_DB_NAME: new DefinePlugin('test'),
  RDB_PASSWORD: new DefinePlugin('password'),
  RDB_USER: new DefinePlugin('test_user'),
}
export default mapPlugin



// config/production.ts
import { MapPlugin, DefinePlugin, EnvPlugin } from "@odanado/config-loader"
import { ConfigScheme } from "./"

const mapPlugin: MapPlugin<ConfigScheme> = {
  RDB_DB_NAME: new DefinePlugin('test'),
  RDB_PASSWORD: new EnvPlugin('RDB_PASSWORD'),
  RDB_USER: new DefinePlugin('test_user'),
}
export default mapPlugin

In app.ts

import { ConfigLoader } from "@odanado/config-loader"
import { ConfigScheme } from "./config"


async function main() {
  const path = `${process.cwd()}/config`
  const configLoader = new ConfigLoader<ConfigScheme>(path)
  // if NODE_ENV === 'development'
  await configLoader.load() // -> { RDB_DB_NAME: 'test', RDB_PASSWORD: 'password', RDB_USER: 'test_user' }
  
  
  // if NODE_ENV === 'production' and RDB_PASSWORD === 'abcdef'
  await configLoader.load() // -> { RDB_DB_NAME: 'test', RDB_PASSWORD: 'abcdef', RDB_USER: 'test_user' }
}

main()
0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago