Skip to content

Commit

Permalink
Add support for .auto-changelog config
Browse files Browse the repository at this point in the history
Closes #66
  • Loading branch information
cookpete committed Nov 8, 2018
1 parent 17b0926 commit 89c8b44
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ You can also set any option in `package.json` under the `auto-changelog` key, us
}
```

You can also store config options in an `.auto-changelog` file in your project root:

```js
{
"output": "HISTORY.md",
"template": "keepachangelog",
"unreleased": true,
"commitLimit": false
}
```

Note that any options set in `package.json` will take precedence over any set in `.auto-changelog`.

### Requirements

`auto-changelog` is designed to be as flexible as possible, providing a clear changelog for any project. There are only two absolute requirements:
Expand Down
11 changes: 8 additions & 3 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ const DEFAULT_OPTIONS = {
tagPrefix: ''
}

const PACKAGE_FILE = 'package.json'
const PACKAGE_OPTIONS_KEY = 'auto-changelog'
const OPTIONS_DOTFILE = '.auto-changelog'

function getOptions (argv, pkg) {
function getOptions (argv, pkg, dotOptions) {
const options = new Command()
.option('-o, --output [file]', `output file, default: ${DEFAULT_OPTIONS.output}`)
.option('-t, --template [template]', `specify template to use [compact, keepachangelog, json], default: ${DEFAULT_OPTIONS.template}`)
Expand All @@ -44,11 +46,13 @@ function getOptions (argv, pkg) {
}
return {
...DEFAULT_OPTIONS,
...dotOptions,
...options
}
}
return {
...DEFAULT_OPTIONS,
...dotOptions,
...pkg[PACKAGE_OPTIONS_KEY],
...options
}
Expand Down Expand Up @@ -83,8 +87,9 @@ async function getReleases (commits, remote, latestVersion, options) {
}

export default async function run (argv) {
const pkg = await fileExists('package.json') && await readJson('package.json')
const options = getOptions(argv, pkg)
const pkg = await fileExists(PACKAGE_FILE) && await readJson(PACKAGE_FILE)
const dotOptions = await fileExists(OPTIONS_DOTFILE) && await readJson(OPTIONS_DOTFILE)
const options = getOptions(argv, pkg, dotOptions)
const remote = await fetchRemote(options.remote)
const commits = await fetchCommits(remote, options)
const latestVersion = getLatestVersion(options, pkg, commits)
Expand Down

0 comments on commit 89c8b44

Please sign in to comment.