forked from JPeer264/node-semantic-git-commit-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
62 lines (48 loc) · 1.73 KB
/
Copy pathconfig.js
File metadata and controls
62 lines (48 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import json from 'json-extra';
import merge from 'lodash.merge';
import os from 'os';
import path from 'path';
const cwd = process.cwd();
const homedir = os.homedir();
class Config {
constructor(altPath) {
this.altPath = altPath;
}
chooseConfigFile() {
const pathString = this.altPath || path.join(cwd, '.sgcrc');
const configObject = json.readToObjSync(pathString);
const globalConfig = json.readToObjSync(path.join(homedir, '.sgcrc'));
const packageConfig = json.readToObjSync(path.join(cwd, 'package.json')).sgc;
// priority order (1. highest priority):
// 1. local config
// - 1. .sgcrc
// - 2. (package.json).sgc
// 2. global config
// 3. default config
// - 1. from ../.sgcrc
// - 2. test case ../.sgcrc is renamed to ../.sgcrc_default
const config = configObject || packageConfig || globalConfig;
return config;
}
getConfig() {
const sgcrcDefaultConfig = json.readToObjSync(path.join(__dirname, '..', '.sgcrc'));
const sgcrcTestDefaultConfig = json.readToObjSync(path.join(__dirname, '..', '.sgcrc_default'));
const sgcrcDefault = sgcrcDefaultConfig || sgcrcTestDefaultConfig;
const config = this.chooseConfigFile() || sgcrcDefault;
// set defaults which are necessary
const tempConfig = merge({}, sgcrcDefault, config);
// do not merge types
// so return them to their set default
if (config.types) {
tempConfig.types = config.types;
}
if (config['initial-commit']) {
tempConfig['initial-commit'] = config['initial-commit'];
}
// next will remove "inherit" from the config
// eslint-disable-next-line
const { inherit, ...copiedConfig } = tempConfig;
return copiedConfig;
}
}
export default Config;