Skip to content

Commit

Permalink
Add development configuration loader
Browse files Browse the repository at this point in the history
  • Loading branch information
jlpereira committed Aug 28, 2023
1 parent 8fb3b8c commit e091cad
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/utils/loadConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,31 @@ import glob from 'glob'
import defaultConfig from '../constants/defaultConfig'

export const loadConfiguration = (appPath) => {
const filePaths = glob.sync(appPath + '/config/*.yml', {})
const jsonConfig = filePaths.map((filepath) =>
yaml.load(fs.readFileSync(filepath, 'utf8'))
)
const isProd = process.env.NODE_ENV === 'production'
const filePaths = glob.sync(appPath + '/config/*.yml')
const configurationPaths = splitFilePathsByEnv(filePaths)

const jsonConfig = [
...configurationPaths.prod,
...(!isProd ? configurationPaths.dev : [])
].map((filepath) => yaml.load(fs.readFileSync(filepath, 'utf8')))

return Object.assign({}, defaultConfig, ...jsonConfig)
}

function splitFilePathsByEnv(filepaths) {
const devExtension = '.development.yml'

return filepaths.reduce(
(acc, current) => {
if (current.includes(devExtension)) {
acc.dev.push(current)
} else {
acc.prod.push(current)
}

return acc
},
{ dev: [], prod: [] }
)
}

0 comments on commit e091cad

Please sign in to comment.