-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from tusharmath/reading-env-variables
Reading env variables
- Loading branch information
Showing
20 changed files
with
309 additions
and
111 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
/** | ||
* Created by tushar on 30/12/17. | ||
*/ | ||
import R = require('ramda') | ||
import {loadCLIConfigs} from './loadCliConfigs' | ||
import {loadFileConfigs} from './loadFileConfigs' | ||
import {replaceWithEnvVar} from './replaceWithEnvVar' | ||
import {mergeFileConfigs} from './mergeFileConfigs' | ||
|
||
/** | ||
* Loads all the configs from files and cli and merges them. | ||
*/ | ||
export const mergeAllConfigs = R.converge(R.mergeDeepRight, [ | ||
R.converge(replaceWithEnvVar, [ | ||
R.compose(mergeFileConfigs, loadFileConfigs), | ||
R.identity | ||
]), | ||
loadCLIConfigs | ||
]) |
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 |
---|---|---|
@@ -1,24 +1,16 @@ | ||
import * as R from 'ramda' | ||
|
||
export type ConfigSources = { | ||
defaultConfig: any | ||
envConfig: any | ||
deploymentConfig: any | ||
userConfig: any | ||
cliConfig: any | ||
} | ||
/** | ||
* Merges the configs in the following order — | ||
* defaultConfig < envConfig < deploymentConfig < userConfig < cliConfig | ||
* @param {ConfigSources} configs | ||
* @return {any} | ||
*/ | ||
|
||
export const mergeConfigs = (configs: ConfigSources) => { | ||
export const mergeFileConfigs = (configs: {[key: string]: any}) => { | ||
return R.reduce(R.mergeDeepRight, configs.defaultConfig, [ | ||
configs.envConfig, | ||
configs.deploymentConfig, | ||
configs.userConfig, | ||
configs.cliConfig | ||
configs.userConfig | ||
]) | ||
} |
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,17 @@ | ||
/** | ||
* Created by tushar on 10/01/18. | ||
*/ | ||
|
||
import * as R from 'ramda' | ||
|
||
const getVarName = R.replace('@@', '') | ||
const hasEnvVar = R.test(/^@@.*$/) | ||
export const replaceWithEnvVar = <T>(baseConfig: T, process: any) => { | ||
const itar: any = R.map((value: any) => { | ||
if (R.is(Object, value)) return itar(value) | ||
if (R.is(String, value) && hasEnvVar(value)) | ||
return process.env[getVarName(value)] | ||
return value | ||
}) | ||
return itar(baseConfig) | ||
} |
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.