forked from streamich/git-cz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 make changelog config customizable
- Loading branch information
Showing
2 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |