Skip to content

Commit

Permalink
Add support for environment specific local config files
Browse files Browse the repository at this point in the history
  • Loading branch information
iansu committed Jun 14, 2019
1 parent c92aea9 commit c41afd0
Show file tree
Hide file tree
Showing 11 changed files with 581 additions and 444 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build
coverage
node_modules

*.log
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0 (June 14, 2019)

Add support for environment specific local config files

## 1.0.0 (April 11, 2019)

Initial release! :tada:
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Settings from these different sources are merged together into a single config o

1. `config.default.{ts|js}`
1. `config.${NODE_ENV}.{ts|js}`
1. `config.${NODE_ENV}.local.{ts|js}`
1. `config.local.{ts|js}`
1. AWS Secrets Manager
1. Environment variables
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "config-dug",
"version": "1.0.0",
"version": "1.1.0",
"description": "Config loader with support for AWS Secrets Manager",
"author": "Neo Financial Engineering <engineering@neofinancial.com>",
"main": "build/index.js",
Expand All @@ -22,7 +22,7 @@
"lint": "eslint \"**/*.{ts,js}\"",
"format": "prettier --write \"**/*.{ts,js,json,graphql,md}\"",
"format:check": "prettier --debug-check \"**/*.{ts,js,json,graphql,md}\"",
"prepare": "rimraf build && tsc -p tsconfig.build.json"
"prepublishOnly": "rimraf build && tsc -p tsconfig.build.json"
},
"files": [
"/build/**/*.js",
Expand All @@ -37,24 +37,24 @@
],
"dependencies": {
"aws-param-store": "^2.1.0",
"aws-sdk": "^2.437.0",
"aws-sdk": "^2.475.0",
"debug": "^4.1.1",
"lodash": "^4.17.11"
},
"devDependencies": {
"@types/aws-param-store": "^2.1.0",
"@types/debug": "^4.1.3",
"@types/jest": "^24.0.11",
"@types/lodash": "^4.14.123",
"@types/node": "^11.13.2",
"@types/debug": "^4.1.4",
"@types/jest": "^24.0.14",
"@types/lodash": "^4.14.134",
"@types/node": "^12.0.8",
"eslint": "^5.16.0",
"eslint-config-neo": "^0.1.0",
"eslint-config-neo": "^0.3.0",
"husky": "^1.3.1",
"jest": "^24.7.1",
"lint-staged": "^8.1.5",
"prettier": "^1.16.4",
"jest": "^24.8.0",
"lint-staged": "^8.2.1",
"prettier": "^1.18.2",
"rimraf": "^2.6.3",
"ts-jest": "^24.0.2",
"typescript": "^3.4.3"
"typescript": "~3.4.5"
}
}
2 changes: 2 additions & 0 deletions src/__mocks__/get-secret.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/no-restricted-paths */

import awsSecretsManagerResponse from '../../test/fixtures/secrets/aws-secrets-manager-response.json';

function getSecret(_: string, __: string): object {
Expand Down
11 changes: 10 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,17 @@ function loadConfig(configPath = ''): ConfigObject {
const environmentConfig = loadFile(
resolveFile(appDirectory, configPath, `config.${environment}`)
);
const localEnvironmentConfig = loadFile(
resolveFile(appDirectory, configPath, `config.${environment}.local`)
);
const localConfig = loadFile(resolveFile(appDirectory, configPath, 'config.local'));
const fileConfig = Object.assign({}, defaultConfig, environmentConfig, localConfig);
const fileConfig = Object.assign(
{},
defaultConfig,
environmentConfig,
localEnvironmentConfig,
localConfig
);
const config = Object.assign({}, fileConfig, loadSecrets(fileConfig), loadEnvironment());

return config;
Expand Down
5 changes: 4 additions & 1 deletion test/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ test('loading config from environment variable works', (): void => {
KEY_2: true,
KEY_3: true,
KEY_4: 42,
KEY_5: 4.2
KEY_5: 4.2,
KEY_7: 'local key',
KEY_8: 1,
KEY_9: 'bar'
});

delete process.env.KEY_3;
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/javascript/config.development.local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
KEY_10: 'development local key'
}
3 changes: 3 additions & 0 deletions test/fixtures/typescript/config.development.local.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
KEY_10: 'development local key'
}
7 changes: 4 additions & 3 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('loading TypeScript config works', (): void => {
KEY_5: 4.2,
KEY_7: 'local key',
KEY_8: 1,
KEY_9: 'bar'
KEY_9: 'bar',
});
});

Expand All @@ -26,7 +26,7 @@ test('loading JavaScript config works', (): void => {
KEY_5: 4.2,
KEY_7: 'local key',
KEY_8: 1,
KEY_9: 'bar'
KEY_9: 'bar',
});
});

Expand All @@ -44,7 +44,8 @@ test('loading development environment config works', (): void => {
KEY_6: 'development environment key',
KEY_7: 'local key',
KEY_8: 2,
KEY_9: 'bar'
KEY_9: 'bar',
KEY_10: 'development local key'
});

process.env.NODE_ENV = 'test';
Expand Down
Loading

0 comments on commit c41afd0

Please sign in to comment.