Skip to content

Commit

Permalink
鈾伙笍 Extract getFile function for configuration vault
Browse files Browse the repository at this point in the history
  • Loading branch information
carloscuesta committed Sep 29, 2022
1 parent 2c13df3 commit 3dc0b23
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/utils/configurationVault/getConfiguration.js
Expand Up @@ -24,21 +24,27 @@ const LOCAL_CONFIGURATION: typeof Conf = new Conf({
}
})

const getFile = (path: string): Buffer | void => {
try {
return JSON.parse(readFileSync(path))
} catch (error) {
return
}
}

const getConfiguration = (): { get: Function, set: Function } => {
const loadConfig = (): {
[$Values<typeof CONFIG>]: string | boolean
} => {
const packageJson = `${cwd()}/package.json`
const configurationFile = `${cwd()}/.gitmojirc.json`

if (pathExistsSync(packageJson)) {
const config = JSON.parse(readFileSync(packageJson))?.gitmoji
if (config) return config
if (pathExistsSync(packageJson) && getFile(packageJson)?.gitmoji) {
return getFile(packageJson)?.gitmoji
}

if (pathExistsSync(configurationFile)) {
const config = JSON.parse(readFileSync(configurationFile))
if (config) return config
if (pathExistsSync(configurationFile) && getFile(configurationFile)) {
return getFile(configurationFile)
}

return LOCAL_CONFIGURATION.store
Expand Down

0 comments on commit 3dc0b23

Please sign in to comment.