Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
feat: 🎸 make changelog config customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed May 23, 2018
1 parent abab6cd commit 1758b94
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions src/getConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable global-require, import/no-dynamic-require */
const path = require('path');
const defaults = require('./defaults');

const configFiles = [
'changelog.config.js',
'changelog.config.json'
];

const findOverrides = () => {
const dir = process.cwd();

for (const file of configFiles) {
try {
return require(path.join(dir, file));
// eslint-disable-next-line no-empty
} catch (error) {}
}

try {
const {changelog} = require(path.join(dir, 'package.json'));

if (changelog) {
return changelog;
}
// eslint-disable-next-line no-empty
} catch (error) {}

return {};
};

const getConfig = () => {
const overrides = findOverrides();

if (typeof overrides !== 'object') {
console.log(new TypeError('Expected changelog config to be an object.'));

// eslint-disable-next-line no-process-exit
process.exit(1);
}

return {
...defaults,
...overrides
};
};

module.exports = getConfig;
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const createPrompter = require('./createPrompter');
const config = require('./defaults');
const getConfig = require('./getConfig');

module.exports = createPrompter(config);
module.exports = createPrompter(getConfig());

0 comments on commit 1758b94

Please sign in to comment.