diff --git a/lib/getConfig.js b/lib/getConfig.js index 7d68a45e..29538f68 100644 --- a/lib/getConfig.js +++ b/lib/getConfig.js @@ -1,6 +1,7 @@ /* eslint-disable global-require, import/no-dynamic-require */ const path = require('path'); const fs = require('fs'); +const os = require('os'); const signale = require('signale'); const defaults = require('./defaults'); @@ -11,9 +12,7 @@ const configFiles = [ 'changelog.config.json' ]; -const findOverrides = (root) => { - const dir = root || process.cwd(); - +const containConfigFile = (dir) => { for (const file of configFiles) { const filename = path.resolve(dir, file); @@ -22,6 +21,17 @@ const findOverrides = (root) => { } } + return null; +}; + +const findOverrides = (root) => { + const dir = root || process.cwd(); + + const configContent = containConfigFile(dir); + if (configContent !== null) { + return configContent; + } + const parent = path.resolve(dir, '..'); const pkgFilename = path.join(dir, 'package.json'); @@ -33,7 +43,7 @@ const findOverrides = (root) => { if (changelog) { return changelog; } - // eslint-disable-next-line no-empty + // eslint-disable-next-line no-empty } catch (error) {} } @@ -44,8 +54,12 @@ const findOverrides = (root) => { return {}; }; +// eslint-disable-next-line no-process-env +const HOME_DIR = process.env.NODE_ENV === 'test' ? path.resolve(__dirname, '../test') : os.homedir(); + const getConfig = (root) => { - const overrides = findOverrides(root); + const configFolder = path.join(HOME_DIR, '.config'); + const overrides = containConfigFile(configFolder) || findOverrides(root); if (typeof overrides !== 'object') { signale.fatal(new TypeError('Expected changelog config to be an object.')); diff --git a/test/.config/.git-cz.json b/test/.config/.git-cz.json new file mode 100644 index 00000000..ac75f3db --- /dev/null +++ b/test/.config/.git-cz.json @@ -0,0 +1,3 @@ +{ + "disableEmoji": true +} \ No newline at end of file diff --git a/test/getConfig.test.js b/test/getConfig.test.js new file mode 100644 index 00000000..8d3b787c --- /dev/null +++ b/test/getConfig.test.js @@ -0,0 +1,10 @@ +const {expect} = require('chai'); +const getConfig = require('../lib/getConfig'); + +describe('getConfig', () => { + it('should match config with .git-cz.json', () => { + const actual = getConfig(); + // eslint-disable-next-line no-unused-expressions + expect(actual.disableEmoji).to.be.true; + }); +});