Skip to content

Commit 5c63fce

Browse files
committed
Add getConfig
1 parent 0124b5a commit 5c63fce

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/getConfig.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import path from 'path';
2+
import json from 'json-extra';
3+
4+
const cwd = process.cwd();
5+
6+
const getConfig = (altPath) => {
7+
const pathString = altPath || path.join(cwd, '.sgcrc');
8+
let configObject = json.readToObjSync(pathString);
9+
10+
if (!configObject) {
11+
// package.json .rcs if no other config is found
12+
configObject = json.readToObjSync(path.join(cwd, 'package.json')).sgc;
13+
}
14+
15+
if (!configObject) {
16+
// if no config is available on the users project, the default settings should be used
17+
configObject = json.readToObjSync(path.join(__dirname, '..', '.sgcrc_default'));
18+
}
19+
20+
return configObject;
21+
};
22+
23+
export default getConfig;

0 commit comments

Comments
 (0)