This repository was archived by the owner on Jan 22, 2026. It is now read-only.
forked from JPeer264/node-semantic-git-commit-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetConfig.js
More file actions
62 lines (51 loc) · 1.96 KB
/
Copy pathgetConfig.js
File metadata and controls
62 lines (51 loc) · 1.96 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 merge from 'lodash.merge';
import findup from 'findup-sync';
import json from 'json-extra';
import path from 'path';
import os from 'os';
import fs from 'fs';
const cwd = process.cwd();
const homedir = os.homedir();
// eslint-disable-next-line global-require, import/no-dynamic-require
const safeRequire = (jsPath) => fs.existsSync(jsPath) && require(jsPath);
// params just for testing
const getConfig = (altPath, fileName = '.sgcrc') => {
const pathString = findup(fileName, { cwd: altPath || cwd });
const localeConfigJS = safeRequire(findup('sgc.config.js', { cwd }));
const localeConfig = json.readToObjSync(pathString);
const globalConfigJS = safeRequire(path.join(homedir, 'sgc.config.js'));
const globalConfig = json.readToObjSync(path.join(homedir, '.sgcrc'));
const packageConfig = json.readToObjSync(findup('package.json', { cwd })).sgc;
const sgcrcDefaultConfig = json.readToObjSync(path.join(__dirname, '..', '.sgcrc'));
const sgcrcTestDefaultConfig = json.readToObjSync(path.join(__dirname, '..', '.sgcrc_default'));
const sgcrcDefault = sgcrcDefaultConfig || sgcrcTestDefaultConfig;
// priority order (1. highest priority):
// 1. local config
// - 1. sgc.config.js
// - 2. .sgcrc
// - 3. (package.json).sgc
// 2. global config
// 3. default config
// - 1. from ../.sgcrc
// - 2. test case ../.sgcrc is renamed to ../.sgcrc_default
const config = localeConfigJS
|| localeConfig
|| packageConfig
|| globalConfigJS
|| globalConfig
|| 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.initialCommit) {
tempConfig.initialCommit = config.initialCommit;
}
// next will remove "inherit" from the config
const { inherit, ...copiedConfig } = tempConfig;
return copiedConfig;
};
export default getConfig;