Skip to content

feat: support reading config files from .config folder by default #669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions lib/getConfig.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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);

Expand All @@ -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');
Expand All @@ -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) {}
}

Expand All @@ -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.'));
Expand Down
3 changes: 3 additions & 0 deletions test/.config/.git-cz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"disableEmoji": true
}
10 changes: 10 additions & 0 deletions test/getConfig.test.js
Original file line number Diff line number Diff line change
@@ -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;
});
});