Skip to content

Commit

Permalink
fix: fix get global setting file found bug
Browse files Browse the repository at this point in the history
  • Loading branch information
isuke committed Mar 17, 2018
1 parent 325bfc7 commit d6e45e4
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions git-consistent
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ const getProjectRoot = () => {
}
}

const getFilePath = (rootPath, fileName) => {
let result

result = path.join(rootPath, fileName)
if (fs.existsSync(result)) return result

result = path.join(process.env.HOME, fileName)
if (fs.existsSync(result)) return result

throw new Error(`Not found '${fileName}'.`)
}

const loadDefinitions = (path) => {
return yaml.safeLoad(fs.readFileSync(path, 'utf8'))
}
Expand Down Expand Up @@ -66,8 +78,10 @@ try {
} else {
const projectRoot = getProjectRoot()
const rootPath = projectRoot === "" ? process.env.HOME : projectRoot
const templateFilePath = path.join(rootPath, templateFileName)
const definitionsFilePath = path.join(rootPath, definitionsFileName)

const templateFilePath = getFilePath(rootPath, templateFileName)
const definitionsFilePath = getFilePath(rootPath, definitionsFileName)

const template = fs.readFileSync(templateFilePath, 'utf8')
const definitions = loadDefinitions(definitionsFilePath)
const terms = _.keys(definitions)
Expand Down

0 comments on commit d6e45e4

Please sign in to comment.