Skip to content

Commit

Permalink
feat(cli): release version description (#39)
Browse files Browse the repository at this point in the history
* cli, add release-desc opt
* files, apply desc to body
  • Loading branch information
cdcabrera authored Feb 25, 2023
1 parent dc8a202 commit 7fcfae9
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ or Yarn
list item searches for the prior release message prefix
for range. [write new, search old]
[array] [default: "chore(release)"]
--release-desc Add a description under the release version header
copy. Example, "⚠ BREAKING CHANGES" [string]
--remote-url Git remote get-url for updating [CHANGELOG.md] base
urls. This should start with "http". Defaults to "$ git
remote get-url origin" [string]
Expand Down
13 changes: 10 additions & 3 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const {
package: packageFile,
'pr-path': prPath,
'release-message': releaseTypeScope,
'release-desc': releaseDescription,
'remote-url': remoteUrl
} = yargs
.usage('Generate a CHANGELOG.md with conventional commit types.\n\nUsage: changelog [options]')
Expand Down Expand Up @@ -98,6 +99,10 @@ const {
'A list of prefix release scope commit messages. First list item is the new commit message prefix, the second list item searches for the prior release message prefix for range. [write new, search old]',
type: 'array'
})
.option('release-desc', {
describe: 'Add a description under the release version header copy. Example, "⚠ BREAKING CHANGES"',
type: 'string'
})
.option('remote-url', {
describe:
'Git remote get-url for updating [CHANGELOG.md] base urls. This should start with "http". Defaults to "$ git remote get-url origin"',
Expand All @@ -108,9 +113,10 @@ const {
* Set global OPTIONS
*
* @type {{comparePath: string, date: string, packagePath: Function, isOverrideVersion: boolean,
* packageFile: string, isAllowNonConventionalCommits: boolean, prPath: string, isCommit: boolean,
* overrideVersion: string|*, changelogPath: Function, commitPath: string, changelogFile: string,
* releaseTypeScope: string[]|string, isDryRun: boolean, remoteUrl: string, isBasic: boolean}}
* packageFile: string, releaseDescription: string, isAllowNonConventionalCommits: boolean, prPath: string,
* isCommit: boolean, overrideVersion: string|*, changelogPath: Function, commitPath: string,
* changelogFile: string, releaseTypeScope: string[]|string, isDryRun: boolean, remoteUrl: string,
* isBasic: boolean}}
* @private
*/
OPTIONS._set = {
Expand All @@ -132,6 +138,7 @@ OPTIONS._set = {
return join(this.contextPath, packageFile);
},
prPath,
releaseDescription,
releaseTypeScope,
remoteUrl
};
Expand Down
2 changes: 2 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ Update CHANGELOG.md with commit output.
</tr><tr>
<td>options.isDryRun</td><td><code>boolean</code></td>
</tr><tr>
<td>options.releaseDescription</td><td><code>string</code></td>
</tr><tr>
<td>settings</td><td><code>object</code></td>
</tr><tr>
<td>settings.fallbackPackageVersion</td><td><code>string</code></td>
Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/__snapshots__/files.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
## 1.0.0 (2022-10-01)
### Features
* **dolor** issues/20 sit enhancements (#8) (53a1234)
Expand All @@ -27,6 +28,7 @@ All notable changes to this project will be documented in this file.
## [1.0.0](https://localhost/lorem/ipsum/comparmock/REALFIRST2345d421231231312312345dca11235...LASTg45b597123453031234555b6d25574ccacee) (2022-10-01)
### Features
* **dolor** issues/20 sit enhancements (#8) (53a1234)
Expand All @@ -47,6 +49,9 @@ exports[`Files should create, and update CHANGELOG.md version with a comparison
All notable changes to this project will be documented in this file.
## 1.0.0 (2022-10-01)
### ⚠ **lorem ipsum**
- \`dolor\` (#1234)
- \`sit\` (#5678)
### Features
* **dolor** issues/20 sit enhancements (#8) (53a1234)
Expand All @@ -69,6 +74,7 @@ All notable changes to this project will be documented in this file.
## ¯\\_(ツ)_/¯ (2022-10-01)
### Features
* **dolor** issues/20 sit enhancements (#8) (53a1234)
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
## <semverClean>["15.0.0"]</semverClean> (2022-10-01)
",
"package": "Version bump: <semverClean>["15.0.0"]</semverClean>",
"parsedCommits": {},
Expand All @@ -24,6 +25,7 @@ All notable changes to this project will be documented in this file.
## <semverClean>["<semverInc>[\\"0.0.100\\",\\"patch\\"]</semverInc>"]</semverClean> (2022-10-01)
",
"package": "Version bump: patch",
"parsedCommits": {},
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ describe('Files', () => {
'1.0.0',
{
...OPTIONS,
isBasic: true
isBasic: true,
releaseDescription: '### ⚠ **lorem ipsum**\n- `dolor` (#1234)\n- `sit` (#5678)'
},
{
getComparisonCommitHashes: () => comparisonObjReleaseCommit,
Expand Down
6 changes: 4 additions & 2 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const { getComparisonCommitHashes } = require('./parse');
* @param {string} options.date
* @param {boolean} options.isBasic
* @param {boolean} options.isDryRun
* @param {string} options.releaseDescription
* @param {object} settings
* @param {string} settings.fallbackPackageVersion
* @param {Function} settings.getComparisonCommitHashes
Expand All @@ -34,7 +35,7 @@ const { getComparisonCommitHashes } = require('./parse');
const updateChangelog = (
parsedCommits = {},
packageVersion,
{ date, changelogPath, isBasic = false, isDryRun = false } = OPTIONS,
{ date, changelogPath, isBasic = false, isDryRun = false, releaseDescription } = OPTIONS,
{
fallbackPackageVersion = '¯\\_(ツ)_/¯',
getComparisonCommitHashes: getAliasComparisonCommitHashes = getComparisonCommitHashes,
Expand All @@ -46,6 +47,7 @@ const updateChangelog = (
timeZone: 'UTC'
});
const { compareUrl } = getAliasRemoteUrls();
const updatedReleaseDescription = releaseDescription || '';
let header = headerMd;
let version = fallbackPackageVersion;
let body = '';
Expand Down Expand Up @@ -73,7 +75,7 @@ const updateChangelog = (
}
}

const updatedBody = `## ${version} (${systemTimestamp})\n${displayCommits}`;
const updatedBody = `## ${version} (${systemTimestamp})\n${updatedReleaseDescription}\n${displayCommits}`;
const output = `${header}\n\n${updatedBody}\n${body}${(body && '\n') || ''}`;

if (isDryRun) {
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/code.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`General code checks should only have specific console.[warn|log|info|er
"cmds.js:27: console.error(color.RED, errorMessage.replace('{0}', e.message), color.NOCOLOR)",
"cmds.js:156: console.error(color.RED, \`Semver: \${e.message}\`, color.NOCOLOR)",
"cmds.js:186: console.error(color.RED, \`Semver: \${e.message}\`, color.NOCOLOR)",
"files.js:80: console.info(\` \${updatedBody}\`)",
"files.js:82: console.info(\` \${updatedBody}\`)",
"global.js:68: console.error(color.RED, \`Conventional commit types: \${e.message}\`, color.NOCOLOR)",
"index.js:54: console.info( index.js:68: console.info(color.NOCOLOR)",
]
Expand Down

0 comments on commit 7fcfae9

Please sign in to comment.