Skip to content

Commit 65a37c4

Browse files
committed
feat(changelog-generator): make --version optional when --dry-run is on
This makes the workflow described in: #87 (comment) 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](changelog-generator/v1.5.0...changelog-generator/v0.0.0-placeholder) ### 📖 Documentation - docs(changelog-generator): update project links ([\#94](#94)) [--dry-run] Would write ./CHANGELOG.md 6943 bytes ✨ ```
1 parent 587d61c commit 65a37c4

File tree

1 file changed

+15
-4
lines changed
  • projects/npm-tools/packages/changelog-generator/src

1 file changed

+15
-4
lines changed

projects/npm-tools/packages/changelog-generator/src/index.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ async function normalizeVersion(version, {force}, versionTagPrefix) {
510510
return version;
511511
}
512512

513-
function parseArgs(args) {
513+
async function parseArgs(args) {
514514
const options = {
515515
dryRun: false,
516516
outfile: './CHANGELOG.md',
@@ -595,9 +595,19 @@ function parseArgs(args) {
595595
});
596596

597597
if (!options.version) {
598-
error('Missing required option: --version; see --help for usage');
598+
if (options.dryRun) {
599+
const prefix = await getVersionTagPrefix();
599600

600-
return null;
601+
const version = `${prefix}0.0.0-placeholder`;
602+
603+
info(`Using phony version ${version} during --dry-run`);
604+
605+
options.version = version;
606+
} else {
607+
error('Missing required option: --version; see --help for usage');
608+
609+
return null;
610+
}
601611
}
602612

603613
return options;
@@ -692,7 +702,8 @@ async function getVersionTagPrefix() {
692702
}
693703

694704
async function main(_node, _script, ...args) {
695-
const options = parseArgs(args);
705+
const options = await parseArgs(args);
706+
696707
if (!options) {
697708
process.exit(1);
698709
}

0 commit comments

Comments
 (0)