From 65a37c4a31fe49552eaacb9d5352134fbbcab180 Mon Sep 17 00:00:00 2001 From: Greg Hurrell Date: Mon, 5 Oct 2020 12:45:25 +0200 Subject: [PATCH 1/2] feat(changelog-generator): make --version optional when --dry-run is on MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes the workflow described in: https://github.com/liferay/liferay-frontend-projects/issues/87#issuecomment-702644789 a bit easier. Namely, when you are about to cut a release, and you want to preview what will go into the changelog and use that to guide your decision about whether to make this a `--patch`, `--minor` or `--major` (etc) release, you can just run the generator with the `--dry-run` switch, ignoring the usual requirement to pass a `--version`. Test plan: 1. Try running the generator without a `--version` and see it complain: ``` changelog-generator ❯ bin/liferay-changelog-generator.js error: Missing required option: --version; see --help for usage zsh: exit 1 bin/liferay-changelog-generator.js ``` 2. Repeat the test, this time with `--dry-run`, and see this: ``` changelog-generator ❯ bin/liferay-changelog-generator.js --dry-run Using phony version changelog-generator/v0.0.0-placeholder during --dry-run ____________________ (_) ` | | | changelog.js | | ============ | | | | Reporting | | for duty! | | | |__________________| (_)_________________) Fetching remote tags: run with --no-update-tags to skip ## [changelog-generator/v0.0.0-placeholder](https://github.com/liferay/liferay-frontend-projects/tree/changelog-generator/v0.0.0-placeholder) (2020-10-05) [Full changelog](https://github.com/liferay/liferay-frontend-projects/compare/changelog-generator/v1.5.0...changelog-generator/v0.0.0-placeholder) ### :book: Documentation - docs(changelog-generator): update project links ([\#94](https://github.com/liferay/liferay-frontend-projects/pull/94)) [--dry-run] Would write ./CHANGELOG.md 6943 bytes ✨ ``` --- .../packages/changelog-generator/src/index.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/projects/npm-tools/packages/changelog-generator/src/index.js b/projects/npm-tools/packages/changelog-generator/src/index.js index d1c75a7e2b..6094b2d161 100644 --- a/projects/npm-tools/packages/changelog-generator/src/index.js +++ b/projects/npm-tools/packages/changelog-generator/src/index.js @@ -510,7 +510,7 @@ async function normalizeVersion(version, {force}, versionTagPrefix) { return version; } -function parseArgs(args) { +async function parseArgs(args) { const options = { dryRun: false, outfile: './CHANGELOG.md', @@ -595,9 +595,19 @@ function parseArgs(args) { }); if (!options.version) { - error('Missing required option: --version; see --help for usage'); + if (options.dryRun) { + const prefix = await getVersionTagPrefix(); - return null; + const version = `${prefix}0.0.0-placeholder`; + + info(`Using phony version ${version} during --dry-run`); + + options.version = version; + } else { + error('Missing required option: --version; see --help for usage'); + + return null; + } } return options; @@ -692,7 +702,8 @@ async function getVersionTagPrefix() { } async function main(_node, _script, ...args) { - const options = parseArgs(args); + const options = await parseArgs(args); + if (!options) { process.exit(1); } From e9ad08b8d49275af613cec102ee99974ab11c135 Mon Sep 17 00:00:00 2001 From: Greg Hurrell Date: Mon, 5 Oct 2020 12:51:49 +0200 Subject: [PATCH 2/2] refactor(changelog-generator): print banner sooner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So that in the `--dry-run` without `--version` use case, you won't see the "phony version" message before the banner: ``` Using phony version changelog-generator/v0.0.0-placeholder during --dry-run ____________________ (_) ` | | | changelog.js | | ============ | | | | Reporting | | for duty! | | | |__________________| (_)_________________) Fetching remote tags: run with --no-update-tags to skip ``` Note that this does mean that we're showing the banner in some situations where we didn't show it before, but I think that's ok. Example: ``` changelog-generator ❯ bin/liferay-changelog-generator.js --invalid-option ____________________ (_) ` | | | changelog.js | | ============ | | | | Reporting | | for duty! | | | |__________________| (_)_________________) error: Unrecognized argument --invalid-option; see --help for available options error: Missing required option: --version; see --help for usage zsh: exit 1 bin/liferay-changelog-generator.js --invalid-option ``` --- .../packages/changelog-generator/src/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/projects/npm-tools/packages/changelog-generator/src/index.js b/projects/npm-tools/packages/changelog-generator/src/index.js index 6094b2d161..bc3af9e2e7 100644 --- a/projects/npm-tools/packages/changelog-generator/src/index.js +++ b/projects/npm-tools/packages/changelog-generator/src/index.js @@ -702,13 +702,6 @@ async function getVersionTagPrefix() { } async function main(_node, _script, ...args) { - const options = await parseArgs(args); - - if (!options) { - process.exit(1); - } - const {outfile, to, updateTags} = options; - printBanner(` changelog.js ============ @@ -717,6 +710,14 @@ async function main(_node, _script, ...args) { for duty! `); + const options = await parseArgs(args); + + if (!options) { + process.exit(1); + } + + const {outfile, to, updateTags} = options; + if (updateTags) { try { info('Fetching remote tags: run with --no-update-tags to skip');