Skip to content

Commit 944d286

Browse files
committed
Feat: added local config for future contributors
1 parent 471632a commit 944d286

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed
File renamed without changes.

lib/getConfig.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ const getConfig = (altPath) => {
1111
const configObject = json.readToObjSync(pathString);
1212
const globalConfig = json.readToObjSync(path.join(homedir, '.sgcrc'));
1313
const packageConfig = json.readToObjSync(path.join(cwd, 'package.json')).sgc;
14-
const sgcrcDefaultConfig = json.readToObjSync(path.join(__dirname, '..', '.sgcrc_default'));
14+
const sgcrcDefaultConfig = json.readToObjSync(path.join(__dirname, '..', '.sgcrc'));
15+
const sgcrcTestDefaultConfig = json.readToObjSync(path.join(__dirname, '..', '.sgcrc_default'));
1516

1617
// priority order (1. highest priority):
1718
// 1. local config
1819
// - 1. .sgcrc
1920
// - 2. (package.json).sgc
2021
// 2. global config
21-
// 3. default config from ../.sgcrc_default
22-
let config = configObject || packageConfig || globalConfig || sgcrcDefaultConfig;
22+
// 3. default config from ../.sgcrc
23+
// 4. In the test case ../.sgcrc is renamed to ../.sgcrc_default
24+
let config = configObject
25+
|| packageConfig
26+
|| globalConfig
27+
|| sgcrcDefaultConfig
28+
|| sgcrcTestDefaultConfig;
2329

2430
// set defaults
2531
const configDefaults = {

test/getConfig.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,24 @@ let globalExist = false;
1717

1818
// rename global .sgcrc
1919
test.before(() => {
20+
// rename global sgcrc
2021
if (fs.existsSync(path.join(homedir, '.sgcrc'))) {
2122
globalExist = true;
2223
fs.renameSync(path.join(homedir, '.sgcrc'), path.join(homedir, `.sgcrc.${randomString}-${datetime}.back`));
2324
}
25+
26+
// rename local sgcrc
27+
fs.renameSync(path.join(cwd, '.sgcrc'), path.join(cwd, '.sgcrc_default'));
2428
});
2529

2630
test.after.always(() => {
31+
// rename global sgrc
2732
if (globalExist) {
2833
fs.renameSync(path.join(homedir, `.sgcrc.${randomString}-${datetime}.back`), path.join(homedir, '.sgcrc'));
2934
}
35+
36+
// rename local sgcrc
37+
fs.renameSync(path.join(cwd, '.sgcrc_default'), path.join(cwd, '.sgcrc'));
3038
});
3139

3240
test('read config from a specific path', (t) => {

0 commit comments

Comments
 (0)