diff --git a/command.js b/command.js index 0b70d492c..cc02bcf37 100755 --- a/command.js +++ b/command.js @@ -5,7 +5,6 @@ const { readFileSync } = require('fs') const configPath = findUp.sync(['.versionrc', '.versionrc.json']) const config = configPath ? JSON.parse(readFileSync(configPath)) : {} const spec = require('conventional-changelog-config-spec') -const { START_OF_LAST_RELEASE_PATTERN } = require('./lib/lifecycles/changelog') const yargs = require('yargs') .usage('Usage: $0 [options]') @@ -89,12 +88,12 @@ 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', default: defaults.preset, - describe: 'Commit message guideline preset (default: angular)' + describe: 'Commit message guideline preset' }) .check((argv) => { if (typeof argv.scripts !== 'object' || Array.isArray(argv.scripts)) { @@ -112,20 +111,13 @@ const yargs = require('yargs') .pkgConf('standard-version') .config(config) .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:' }) }) diff --git a/defaults.js b/defaults.js index 202b8f4d4..6d17dc64b 100644 --- a/defaults.js +++ b/defaults.js @@ -23,4 +23,10 @@ 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' + module.exports = defaults diff --git a/index.js b/index.js index e40339887..579160a27 100755 --- a/index.js +++ b/index.js @@ -24,6 +24,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}`) + } + let pkg bump.pkgFiles.forEach((filename) => { if (pkg) return diff --git a/lib/lifecycles/changelog.js b/lib/lifecycles/changelog.js index 689ed382c..4a29be11d 100644 --- a/lib/lifecycles/changelog.js +++ b/lib/lifecycles/changelog.js @@ -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') let oldContentStart = oldContent.search(START_OF_LAST_RELEASE_PATTERN) diff --git a/test.js b/test.js index 02b3279ba..7b7488616 100644 --- a/test.js +++ b/test.js @@ -233,7 +233,7 @@ 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) @@ -241,7 +241,7 @@ describe('cli', function () { 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) @@ -1088,6 +1088,14 @@ describe('standard-version', function () { shell.exec('git log --oneline -n1').should.include('1.1.0 is the version.') }) + it('--header', function () { + fs.writeFileSync('CHANGELOG.md', '', 'utf-8') + commit('feat: first commit') + execCli('--header="# Welcome to our CHANGELOG.md"').code.should.equal(0) + let content = fs.readFileSync('CHANGELOG.md', 'utf-8') + content.should.match(/# Welcome to our CHANGELOG.md/) + }) + it('[LEGACY] supports --message (and single %s replacement)', function () { commit('feat: another commit addresses issue #1') execCli('--message="V:%s"')