From 91922892100e385f1c0be1d68864b62b0bb6d797 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Tue, 20 Apr 2021 10:49:13 -0230 Subject: [PATCH] Move `update` to sub-command The "update" action has been moved to a sub-command, in preparation for adding more commands in later PRs. Specifying a command has been made mandatory. The `update-changelog` npm script has been renamed to `changelog`, to reflect that it will soon be used for more than just updates. --- README.md | 4 ++-- package.json | 2 +- src/cli.js | 25 ++++++++++++++++--------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9c7a37b..740edf3 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,11 @@ or To update the 'Unreleased' section of the changelog: -`npx @metamask/auto-changelog ` +`npx @metamask/auto-changelog update` To update the current release section of the changelog: -`npx @metamask/auto-changelog --rc` +`npx @metamask/auto-changelog update --rc` ## API Usage diff --git a/package.json b/package.json index e716c1e..63bbdbb 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "lint:json": "prettier '**/*.json' --ignore-path .gitignore", "lint": "yarn lint:eslint && yarn lint:json --check", "lint:fix": "yarn lint:eslint --fix && yarn lint:json --write", - "update-changelog": "node ./src/cli.js" + "changelog": "node ./src/cli.js" }, "dependencies": { "cross-spawn": "^7.0.3", diff --git a/src/cli.js b/src/cli.js index 4826cd3..7f9a707 100644 --- a/src/cli.js +++ b/src/cli.js @@ -8,7 +8,7 @@ const { hideBin } = require('yargs/helpers'); const { updateChangelog } = require('./updateChangelog'); const { unreleased } = require('./constants'); -const epilog = `New commits will be added to the "${unreleased}" section (or \ +const updateEpilog = `New commits will be added to the "${unreleased}" section (or \ to the section for the current release if the '--rc' flag is used) in reverse \ chronological order. Any commits for PRs that are represented already in the \ changelog will be ignored. @@ -23,17 +23,24 @@ const npmPackageRepositoryUrl = process.env.npm_package_repository_url; async function main() { const { argv } = yargs(hideBin(process.argv)) - .option('rc', { - default: false, - description: `Add new changes to the current release header, rather than to the '${unreleased}' section.`, - type: 'boolean', - }) + .command( + 'update', + 'Update CHANGELOG.md with any changes made since the most recent release.\nUsage: $0 update [options]', + (_yargs) => + _yargs + .option('rc', { + default: false, + description: `Add new changes to the current release header, rather than to the '${unreleased}' section.`, + type: 'boolean', + }) + .epilog(updateEpilog), + ) .strict() + .demandCommand() .help('help') .usage( - `Update CHANGELOG.md with any changes made since the most recent release.\nUsage: $0 [options]`, - ) - .epilog(epilog); + `Utilities for validating and updating "Keep a Changelog" formatted changelogs.\nUsage: $0 [command] [options]`, + ); if (!npmPackageVersion) { console.error(