Skip to content

Commit d6e45e4

Browse files
committed
fix: fix get global setting file found bug
1 parent 325bfc7 commit d6e45e4

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

git-consistent

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ const getProjectRoot = () => {
2727
}
2828
}
2929

30+
const getFilePath = (rootPath, fileName) => {
31+
let result
32+
33+
result = path.join(rootPath, fileName)
34+
if (fs.existsSync(result)) return result
35+
36+
result = path.join(process.env.HOME, fileName)
37+
if (fs.existsSync(result)) return result
38+
39+
throw new Error(`Not found '${fileName}'.`)
40+
}
41+
3042
const loadDefinitions = (path) => {
3143
return yaml.safeLoad(fs.readFileSync(path, 'utf8'))
3244
}
@@ -66,8 +78,10 @@ try {
6678
} else {
6779
const projectRoot = getProjectRoot()
6880
const rootPath = projectRoot === "" ? process.env.HOME : projectRoot
69-
const templateFilePath = path.join(rootPath, templateFileName)
70-
const definitionsFilePath = path.join(rootPath, definitionsFileName)
81+
82+
const templateFilePath = getFilePath(rootPath, templateFileName)
83+
const definitionsFilePath = getFilePath(rootPath, definitionsFileName)
84+
7185
const template = fs.readFileSync(templateFilePath, 'utf8')
7286
const definitions = loadDefinitions(definitionsFilePath)
7387
const terms = _.keys(definitions)

0 commit comments

Comments
 (0)