From a2df378519c8856647736e8a3ff6af96512ffdd9 Mon Sep 17 00:00:00 2001 From: bcoe Date: Sat, 4 May 2019 22:22:52 -0700 Subject: [PATCH 1/7] chore(release): 6.0.0 --- CHANGELOG.md | 29 ++++++++++++++++++++++++++++- package.json | 2 +- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eeaeacd35..da9edb005 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,34 @@ -# Change Log +# Changelog All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +# [6.0.0](/compare/v5.0.1...v6.0.0) (2019-05-05) + + +### Bug Fixes + +* prevent duplicate headers from being added ([#305](https://github.com/conventional-changelog/standard-version/issues/305)) ([#307](https://github.com/conventional-changelog/standard-version/issues/307)) ([db2c6e5](https://github.com/conventional-changelog/standard-version/commit/db2c6e5)) + + +### Build System + +* add renovate.json ([#273](https://github.com/conventional-changelog/standard-version/issues/273)) ([bf41474](https://github.com/conventional-changelog/standard-version/commit/bf41474)) + + +* feat!: adds configurable conventionalcommits preset (#323) ([4fcd4a7](https://github.com/conventional-changelog/standard-version/commit/4fcd4a7)), closes [#323](https://github.com/conventional-changelog/standard-version/issues/323) + + +### Features + +* update commit msg for when using commitAll ([#320](https://github.com/conventional-changelog/standard-version/issues/320)) ([74a040a](https://github.com/conventional-changelog/standard-version/commit/74a040a)) + + +### BREAKING CHANGES + +* we now use the conventionalcommits preset by default, which directly tracks conventionalcommits.org. + + + ## [5.0.2](https://github.com/conventional-changelog/standard-version/compare/v5.0.1...v5.0.2) (2019-03-16) diff --git a/package.json b/package.json index 5bdcca035..e80b8018f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "standard-version", - "version": "5.0.2", + "version": "6.0.0", "description": "replacement for `npm version` with automatic CHANGELOG generation", "bin": "bin/cli.js", "scripts": { From 09e6573c214db46ff049a600edbfea10ddb4c5c1 Mon Sep 17 00:00:00 2001 From: bcoe Date: Sat, 4 May 2019 22:32:59 -0700 Subject: [PATCH 2/7] feat: allow changelog header to be customized --- CHANGELOG.md | 28 +--------------------------- command.js | 4 ++++ lib/lifecycles/changelog.js | 15 +++++++++++---- test.js | 15 ++++++++++----- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da9edb005..ac7f10649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,33 +1,7 @@ -# Changelog +# Change Log All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. -# [6.0.0](/compare/v5.0.1...v6.0.0) (2019-05-05) - - -### Bug Fixes - -* prevent duplicate headers from being added ([#305](https://github.com/conventional-changelog/standard-version/issues/305)) ([#307](https://github.com/conventional-changelog/standard-version/issues/307)) ([db2c6e5](https://github.com/conventional-changelog/standard-version/commit/db2c6e5)) - - -### Build System - -* add renovate.json ([#273](https://github.com/conventional-changelog/standard-version/issues/273)) ([bf41474](https://github.com/conventional-changelog/standard-version/commit/bf41474)) - - -* feat!: adds configurable conventionalcommits preset (#323) ([4fcd4a7](https://github.com/conventional-changelog/standard-version/commit/4fcd4a7)), closes [#323](https://github.com/conventional-changelog/standard-version/issues/323) - - -### Features - -* update commit msg for when using commitAll ([#320](https://github.com/conventional-changelog/standard-version/issues/320)) ([74a040a](https://github.com/conventional-changelog/standard-version/commit/74a040a)) - - -### BREAKING CHANGES - -* we now use the conventionalcommits preset by default, which directly tracks conventionalcommits.org. - - ## [5.0.2](https://github.com/conventional-changelog/standard-version/compare/v5.0.1...v5.0.2) (2019-03-16) diff --git a/command.js b/command.js index 4ea6c1c3e..2f9bbc77d 100755 --- a/command.js +++ b/command.js @@ -87,6 +87,10 @@ const yargs = require('yargs') type: 'string', describe: 'Only populate commits made under this path' }) + .option('changelogHeader', { + type: 'string', + describe: 'Use a custom header when generating and updating changelog.' + }) .option('preset', { type: 'string', default: defaults.preset, diff --git a/lib/lifecycles/changelog.js b/lib/lifecycles/changelog.js index 43733225d..e0608615a 100644 --- a/lib/lifecycles/changelog.js +++ b/lib/lifecycles/changelog.js @@ -6,7 +6,7 @@ const fs = require('fs') const presetLoader = require('../preset-loader') const runLifecycleScript = require('../run-lifecycle-script') const writeFile = require('../write-file') -const START_OF_LAST_RELEASE_PATTERN = /(^##? (?!Change Log$)| { createIfMissing(args) - var header = '# Change Log\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' - var oldContent = args.dryRun ? '' : fs.readFileSync(args.infile, 'utf-8') - var oldContentStart = oldContent.search(START_OF_LAST_RELEASE_PATTERN) + 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' + + // the header must not match the regex used to find + // the last release. + if (header.search(START_OF_LAST_RELEASE_PATTERN)) { + return reject(Error(`the changelogHeader provided must not match ${START_OF_LAST_RELEASE_PATTERN}`)) + } + + let oldContent = args.dryRun ? '' : fs.readFileSync(args.infile, 'utf-8') + let oldContentStart = oldContent.search(START_OF_LAST_RELEASE_PATTERN) // find the position of the last release and remove header: if (oldContentStart !== -1) { oldContent = oldContent.substring(oldContentStart) diff --git a/test.js b/test.js index 0113bd1e8..96f9608d6 100644 --- a/test.js +++ b/test.js @@ -165,22 +165,27 @@ describe('cli', function () { }) it('appends the new release above the last release, removing the old header (new format)', function () { + // we don't create a package.json, so no {{host}} and {{repo}} tag + // will be populated, let's use a compareUrlFormat without these. + const cliArgs = '--compareUrlFormat=/compare/{{previousTag}}...{{currentTag}}' + commit('feat: first commit') shell.exec('git tag -a v1.0.0 -m "my awesome first release"') commit('fix: patch release') - execCli().code.should.equal(0) - var content = fs.readFileSync('CHANGELOG.md', 'utf-8') + execCli(cliArgs).code.should.equal(0) + let content = fs.readFileSync('CHANGELOG.md', 'utf-8') // remove commit hashes and dates to make testing against a static string easier: content = content.replace(/patch release [0-9a-f]{6,8}/g, 'patch release ABCDEFXY').replace(/\([0-9]{4}-[0-9]{2}-[0-9]{2}\)/g, '(YYYY-MM-DD)') - content.should.equal('# Change Log\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\n## [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n') + content.should.equal('# 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\n## [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n') commit('fix: another patch release') - execCli().code.should.equal(0) + // we've populated no package.json, so no {{host}} and + execCli(cliArgs).code.should.equal(0) content = fs.readFileSync('CHANGELOG.md', 'utf-8') content = content.replace(/patch release [0-9a-f]{6,8}/g, 'patch release ABCDEFXY').replace(/\([0-9]{4}-[0-9]{2}-[0-9]{2}\)/g, '(YYYY-MM-DD)') - content.should.equal('# Change Log\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\n## [1.0.2](/compare/v1.0.1...v1.0.2) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* another patch release ABCDEFXY\n\n\n\n## [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n') + content.should.equal('# 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\n## [1.0.2](/compare/v1.0.1...v1.0.2) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* another patch release ABCDEFXY\n\n\n\n## [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n') }) it('commits all staged files', function () { From 2cdb1311aaf2b0ae6c6096db4e0a33f6a1dc1a35 Mon Sep 17 00:00:00 2001 From: bcoe Date: Sat, 4 May 2019 22:33:40 -0700 Subject: [PATCH 3/7] docs: remove extra line --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac7f10649..eeaeacd35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. - ## [5.0.2](https://github.com/conventional-changelog/standard-version/compare/v5.0.1...v5.0.2) (2019-03-16) From 19bff44562c835d769c1bc406990be4278e3c0d1 Mon Sep 17 00:00:00 2001 From: bcoe Date: Sat, 4 May 2019 22:34:34 -0700 Subject: [PATCH 4/7] chore: fix version # in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e80b8018f..5bdcca035 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "standard-version", - "version": "6.0.0", + "version": "5.0.2", "description": "replacement for `npm version` with automatic CHANGELOG generation", "bin": "bin/cli.js", "scripts": { From 281bba3399d887109884faf3a88867f58ac7bce4 Mon Sep 17 00:00:00 2001 From: bcoe Date: Sat, 4 May 2019 22:58:32 -0700 Subject: [PATCH 5/7] test: ensure custom header doesn't match version search --- command.js | 8 ++++++++ lib/lifecycles/changelog.js | 14 ++++++-------- test.js | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/command.js b/command.js index 2f9bbc77d..32f6ba8ba 100755 --- a/command.js +++ b/command.js @@ -5,6 +5,7 @@ const { readFileSync } = require('fs') const configPath = findUp.sync(['.versionrc', '.version.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]') @@ -112,6 +113,13 @@ const yargs = require('yargs') .pkgConf('standard-version') .config(config) .wrap(97) + .check((args) => { + if (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] diff --git a/lib/lifecycles/changelog.js b/lib/lifecycles/changelog.js index e0608615a..512d63a50 100644 --- a/lib/lifecycles/changelog.js +++ b/lib/lifecycles/changelog.js @@ -8,7 +8,7 @@ const runLifecycleScript = require('../run-lifecycle-script') const writeFile = require('../write-file') const START_OF_LAST_RELEASE_PATTERN = /(^#+ \[?[0-9]+\.[0-9]+\.[0-9]+| { @@ -19,17 +19,15 @@ module.exports = function (args, newVersion) { }) } +Changelog.START_OF_LAST_RELEASE_PATTERN = START_OF_LAST_RELEASE_PATTERN + +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' - - // the header must not match the regex used to find - // the last release. - if (header.search(START_OF_LAST_RELEASE_PATTERN)) { - return reject(Error(`the changelogHeader provided must not match ${START_OF_LAST_RELEASE_PATTERN}`)) - } - + let oldContent = args.dryRun ? '' : fs.readFileSync(args.infile, 'utf-8') let oldContentStart = oldContent.search(START_OF_LAST_RELEASE_PATTERN) // find the position of the last release and remove header: diff --git a/test.js b/test.js index 96f9608d6..6abb63f82 100644 --- a/test.js +++ b/test.js @@ -210,6 +210,20 @@ describe('cli', function () { content.should.match(/1\.0\.1/) content.should.not.match(/legacy header format/) }) + + it('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) + let 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 () { + fs.writeFileSync('CHANGELOG.md', '', 'utf-8') + commit('feat: first commit') + execCli('--changelogHeader="## 3.0.2"').code.should.equal(1) + }) }) describe('with mocked git', function () { From 4cb8cd7a7e1736146653b07b5a9e1b992727b22c Mon Sep 17 00:00:00 2001 From: bcoe Date: Sat, 4 May 2019 23:01:23 -0700 Subject: [PATCH 6/7] fix: don't call search on undefined --- command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command.js b/command.js index 32f6ba8ba..25b0a5abd 100755 --- a/command.js +++ b/command.js @@ -114,7 +114,7 @@ const yargs = require('yargs') .config(config) .wrap(97) .check((args) => { - if (args.changelogHeader.search(START_OF_LAST_RELEASE_PATTERN) !== -1) { + 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 From c3ca12c029937917f47fe3bcb3a8bd17a04a61b8 Mon Sep 17 00:00:00 2001 From: bcoe Date: Sat, 4 May 2019 23:27:58 -0700 Subject: [PATCH 7/7] chore: fix tests --- package.json | 4 ++-- test.js | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 5bdcca035..80b18f8a8 100644 --- a/package.json +++ b/package.json @@ -39,9 +39,9 @@ "homepage": "https://github.com/conventional-changelog/standard-version#readme", "dependencies": { "chalk": "^2.4.1", - "conventional-changelog": "^3.1.2", + "conventional-changelog": "^3.1.8", "conventional-changelog-config-spec": "^1.0.0", - "conventional-recommended-bump": "^4.1.1", + "conventional-recommended-bump": "^5.0.0", "detect-indent": "^5.0.0", "detect-newline": "^2.1.0", "dotgitignore": "^2.1.0", diff --git a/test.js b/test.js index 6abb63f82..84d6ce5b7 100644 --- a/test.js +++ b/test.js @@ -164,6 +164,9 @@ describe('cli', function () { content.should.not.match(/legacy header format/) }) + // TODO: we should use snapshots which are easier to update than large + // string assertions; we should also consider not using the CLI which + // is slower than calling standard-version directly. it('appends the new release above the last release, removing the old header (new format)', function () { // we don't create a package.json, so no {{host}} and {{repo}} tag // will be populated, let's use a compareUrlFormat without these. @@ -178,14 +181,14 @@ describe('cli', function () { // remove commit hashes and dates to make testing against a static string easier: content = content.replace(/patch release [0-9a-f]{6,8}/g, 'patch release ABCDEFXY').replace(/\([0-9]{4}-[0-9]{2}-[0-9]{2}\)/g, '(YYYY-MM-DD)') - content.should.equal('# 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\n## [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n') + content.should.equal('# 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\n### [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n') commit('fix: another patch release') // we've populated no package.json, so no {{host}} and execCli(cliArgs).code.should.equal(0) content = fs.readFileSync('CHANGELOG.md', 'utf-8') content = content.replace(/patch release [0-9a-f]{6,8}/g, 'patch release ABCDEFXY').replace(/\([0-9]{4}-[0-9]{2}-[0-9]{2}\)/g, '(YYYY-MM-DD)') - content.should.equal('# 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\n## [1.0.2](/compare/v1.0.1...v1.0.2) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* another patch release ABCDEFXY\n\n\n\n## [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n') + content.should.equal('# 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\n### [1.0.2](/compare/v1.0.1...v1.0.2) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* another patch release ABCDEFXY\n\n\n\n### [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n') }) it('commits all staged files', function () {