Skip to content

Commit

Permalink
feat: introduce changelog customization using config file
Browse files Browse the repository at this point in the history
  • Loading branch information
lekterable committed Apr 25, 2020
1 parent faee480 commit e66d617
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 70 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

## Fixes

- stop adding empty line at the end of the file on --root faee4801
- stop adding Latest when not applicable c64fa467

# 1.0.0
Expand Down
13 changes: 11 additions & 2 deletions bin/perfekt.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
#!/usr/bin/env node

const { program } = require('commander')
const { changelog, release, initialize } = require('../dist')
const { changelog, release, initialize, defaultConfig } = require('../dist')
const { version } = require('../package.json')
const { cosmiconfig } = require('cosmiconfig')

program
.command('changelog [version]')
.description('generate package changelog')
.option('--write', 'write the output to file')
.option('--root', 'generate changelog for the entire history')
.action((version, options) => changelog(version, options))
.action(async (version, options) => {
const cosmiConfig = (await cosmiconfig('perfekt').search()) || {}
const config = {
...defaultConfig,
...cosmiConfig.config
}

changelog(version, options, config)
})

program
.command('init')
Expand Down
112 changes: 63 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"license": "MIT",
"dependencies": {
"commander": "^5.0.0",
"cosmiconfig": "^6.0.0",
"inquirer": "^7.1.0",
"semver": "^7.3.2"
},
Expand Down
7 changes: 3 additions & 4 deletions src/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import {
groupCommits
} from './utils'

export const changelog = async (version, options) => {
export const changelog = async (version, options, config) => {
const latestTag = !options.root && (await getLatestTag())
const commits = await getCommits(latestTag)
const grouped = groupCommits(commits)
const changelog = generateChangelog(version, grouped)

const changelog = generateChangelog(version, grouped, config)
if (!options || !options.write) return process.stdout.write(changelog)

const released = latestTag && (await generateReleased(latestTag))
const released = latestTag && (await generateReleased(latestTag, config))

const newChangelog = released
? changelog + released
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export * from './changelog'
export * from './initialize'
export * from './release'

export const defaultConfig = {
unreleasedFormat: '# Latest',
releaseFormat: '# %version%',
lineFormat: '- %message% %hash%'
}
Loading

0 comments on commit e66d617

Please sign in to comment.