Skip to content
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

feat: Adds support for header (--header) configuration based on the spec. #364

Merged
merged 2 commits into from Dec 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 2 additions & 10 deletions command.js
@@ -1,7 +1,6 @@
const spec = require('conventional-changelog-config-spec')
const { getConfiguration } = require('./lib/configuration')
const defaults = require('./defaults')
const { START_OF_LAST_RELEASE_PATTERN } = require('./lib/lifecycles/changelog')

const yargs = require('yargs')
.usage('Usage: $0 [options]')
Expand Down Expand Up @@ -93,7 +92,7 @@ const yargs = require('yargs')
})
.option('changelogHeader', {
type: 'string',
describe: 'Use a custom header when generating and updating changelog.'
describe: '[DEPRECATED] Use a custom header when generating and updating changelog.\nThis option will be removed in the next major version, please use --header.'
})
.option('preset', {
type: 'string',
Expand All @@ -116,20 +115,13 @@ const yargs = require('yargs')
.pkgConf('standard-version')
.config(getConfiguration())
.wrap(97)
.check((args) => {
if (args.changelogHeader && args.changelogHeader.search(START_OF_LAST_RELEASE_PATTERN) !== -1) {
throw Error(`custom changelog header must not match ${START_OF_LAST_RELEASE_PATTERN}`)
} else {
return true
}
})

Object.keys(spec.properties).forEach(propertyKey => {
const property = spec.properties[propertyKey]
yargs.option(propertyKey, {
type: property.type,
describe: property.description,
default: property.default,
default: defaults[propertyKey] ? defaults[propertyKey] : property.default,
group: 'Preset Configuration:'
})
})
Expand Down
6 changes: 6 additions & 0 deletions defaults.js
Expand Up @@ -23,6 +23,12 @@ Object.keys(spec.properties).forEach(propertyKey => {
defaults[propertyKey] = property.default
})

/**
* Sets the default for `header` (provided by the spec) for backwards
* compatibility. This should be removed in the next major version.
*/
defaults.header = '# Changelog\n\nAll notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n'

defaults.packageFiles = [
'package.json',
'bower.json',
Expand Down
11 changes: 11 additions & 0 deletions index.js
Expand Up @@ -26,6 +26,17 @@ module.exports = function standardVersion (argv) {
}
}

if (argv.changelogHeader) {
argv.header = argv.changelogHeader
if (!argv.silent) {
console.warn('[standard-version]: --changelogHeader will be removed in the next major release. Use --header.')
}
}

if (argv.header && argv.header.search(changelog.START_OF_LAST_RELEASE_PATTERN) !== -1) {
throw Error(`custom changelog header must not match ${changelog.START_OF_LAST_RELEASE_PATTERN}`)
}

const args = Object.assign({}, defaults, argv)
let pkg
args.packageFiles.forEach((packageFile) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/lifecycles/changelog.js
Expand Up @@ -26,7 +26,7 @@ module.exports = Changelog
function outputChangelog (args, newVersion) {
return new Promise((resolve, reject) => {
createIfMissing(args)
const header = args.changelogHeader || '# Changelog\n\nAll notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n'
const header = args.header

let oldContent = args.dryRun ? '' : fs.readFileSync(args.infile, 'utf-8')
const oldContentStart = oldContent.search(START_OF_LAST_RELEASE_PATTERN)
Expand Down
12 changes: 10 additions & 2 deletions test.js
Expand Up @@ -233,15 +233,15 @@ describe('cli', function () {
content.should.not.match(/legacy header format/)
})

it('allows for a custom changelog header', function () {
it('[DEPRECATED] (--changelogHeader) allows for a custom changelog header', function () {
fs.writeFileSync('CHANGELOG.md', '', 'utf-8')
commit('feat: first commit')
execCli('--changelogHeader="# Pork Chop Log"').code.should.equal(0)
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.match(/# Pork Chop Log/)
})

it('exits with error if changelog header matches last version search regex', function () {
it('[DEPRECATED] (--changelogHeader) exits with error if changelog header matches last version search regex', function () {
fs.writeFileSync('CHANGELOG.md', '', 'utf-8')
commit('feat: first commit')
execCli('--changelogHeader="## 3.0.2"').code.should.equal(1)
Expand Down Expand Up @@ -1262,6 +1262,14 @@ describe('standard-version', function () {
content.should.include('http://www.foo.com/ABC-1')
})

it('--header', function () {
fs.writeFileSync('CHANGELOG.md', '', 'utf-8')
commit('feat: first commit')
execCli('--header="# Welcome to our CHANGELOG.md"').code.should.equal(0)
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.match(/# Welcome to our CHANGELOG.md/)
})

it('--issuePrefixes and --issueUrlFormat', function () {
commit('feat: another commit addresses issue ABC-1')
execCli('--issuePrefixes="ABC-" --issueUrlFormat="http://www.foo.com/{{prefix}}{{id}}"')
Expand Down