Skip to content

Commit a633efa

Browse files
committed
Breaking: replace bump with cc add command
Existing behavior remains the same, so `hallmark cc add <target>` does the same as `hallmark bump <target>` did. The new command is more generic however: it also supports inserting a release into the changelog for an existing version (regardless of whether that version is first, last or somewhere in the middle). In addition, there's a new option `--no-commits` to skip populating the release with commits. Effectively only creating a markdown heading (with a version number, link and date). Closes #84
1 parent 2716078 commit a633efa

5 files changed

Lines changed: 79 additions & 34 deletions

File tree

README.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
- [Requirements](#requirements)
2121
- [Rules](#rules)
2222
- [Usage](#usage)
23+
- [Commands](#commands)
24+
- [`lint`](#lint)
25+
- [`fix`](#fix)
26+
- [`cc add <target>`](#cc-add-target)
2327
- [Package Options](#package-options)
2428
- [`ignore`](#ignore)
2529
- [`autolinkReferences`](#autolinkreferences)
@@ -65,10 +69,11 @@ Fix custom files:
6569
hallmark fix CHANGELOG.md docs/*.md
6670
```
6771

68-
Add new minor version to changelog:
72+
Add new minor version or existing version to changelog, optionally without content:
6973

7074
```
71-
hallmark bump minor
75+
hallmark cc add minor
76+
hallmark cc add 4.2.0 --no-commits
7277
```
7378

7479
## What You Might Do
@@ -134,13 +139,9 @@ README.md:5:3
134139

135140
`hallmark [command] [options] [pattern ...]`
136141

137-
Lint or fix files in the current working directory. By default `hallmark` includes files matching `*.md`. Pass one or more glob patterns to override this. Files matching `.gitignore` patterns are ignored. To ignore additional files, use the `--ignore / -i` option.
142+
Lint or fix files in the current working directory. The default command is `lint`.
138143

139-
Commands:
140-
141-
- `lint`: lint markdown files (default)
142-
- `fix`: fix markdown files
143-
- `bump <target>`: add new entry to changelog. Target must be a release type (major, minor, patch, premajor, preminor, prepatch, prerelease) or a version.
144+
By default `hallmark` includes files matching `*.md`. Pass one or more glob patterns to override this. Files matching `.gitignore` patterns are ignored. To ignore additional files, use the `--ignore / -i` option.
144145

145146
Options:
146147

@@ -151,6 +152,37 @@ Options:
151152
- `--[no-]color`: force color in report (detected by default)
152153
- `--fix`: backwards-compatible alias for fix command
153154

155+
### Commands
156+
157+
#### `lint`
158+
159+
Lint markdown files.
160+
161+
#### `fix`
162+
163+
Fix markdown files in place.
164+
165+
#### `cc add <target>`
166+
167+
Add a release to `CHANGELOG.md` and populate it with commits. The `target` must be one of:
168+
169+
- A release type: `major`, `minor`, `patch`, `premajor`, `preminor`, `prepatch`, `prerelease`
170+
- These take the current version from the semver-latest tag, release or `package.json` (whichever is greatest if found) and bump it
171+
- The `major` type bumps the major version (for example `2.4.1 => 3.0.0`); `minor` and `patch` work the same way.
172+
- The `premajor` type bumps the version up to the next major version and down to a prerelease of that major version; `preminor` and `prepatch` work the same way.
173+
- The `prerelease` type works the same as `prepatch` if the current version is a non-prerelease. If the current is already a prerelease then it's simply incremented (for example `4.0.0-rc.2` to `4.0.0-rc.3`).
174+
- A [semver-valid](https://semver.org/) version like 2.4.0.
175+
176+
If the (resulting) version is greater than the current version then commits will be taken from the semver-latest tag until HEAD. I.e. documenting a new release before it's git-tagged. If the version matches an existing tag then a release will be inserted at the appriopriate place, populated with commits between that version's tag and the one before it. I.e. documenting a past release after it's git-tagged.
177+
178+
Additional options for this command:
179+
180+
- `--no-commits`: create an empty release.
181+
182+
Works best on a linear git history. If `hallmark` encounters other tags in the commit range (which may happen if releases were made in parallel on other branches) it will stop there and not include further (older) commits.
183+
184+
The `cc add` command also fixes markdown - both existing content and generated content. After you tweak the release following [Common Changelog](https://common-changelog.org) you may want to run `hallmark fix` again.
185+
154186
## Package Options
155187

156188
You can add a `hallmark` object to your `package.json` with additional configuration. For example:

USAGE

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Commands:
99

1010
lint Lint markdown files (default)
1111
fix Fix markdown files
12-
bump <target> Add new entry to changelog. Target must be a
13-
release type (major, minor, patch, premajor,
12+
cc add <target> Add new release to CHANGELOG.md. Target must be
13+
a release type (major, minor, patch, premajor,
1414
preminor, prepatch, prerelease) or a version.
1515

1616
Options:
@@ -21,6 +21,7 @@ Options:
2121
--report <reporter> Specify reporter
2222
--[no-]color Force color in report (detected by default)
2323
--fix Backwards-compatible alias for fix command
24+
--no-commits Don't populate release with commits
2425

2526
Examples:
2627

@@ -34,4 +35,4 @@ Examples:
3435
$ hallmark fix CHANGELOG.md docs/*.md
3536

3637
# Add new minor version to changelog
37-
$ hallmark bump minor
38+
$ hallmark cc add minor

cli.js

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ if (process.version.match(/^v(\d+)\./)[1] < 10) {
77
}
88

99
const argv = require('subarg')(process.argv.slice(2), {
10-
boolean: ['fix', 'help', 'version'],
10+
boolean: ['fix', 'help', 'version', 'commits'],
1111
string: ['report'],
1212
default: {
1313
fix: false,
1414
help: false,
15-
version: false
15+
version: false,
16+
commits: true
1617
},
1718
alias: {
1819
h: 'help',
@@ -22,33 +23,36 @@ const argv = require('subarg')(process.argv.slice(2), {
2223
})
2324

2425
if (argv.help) {
25-
usage()
26+
usage(0)
2627
} else if (argv.version) {
2728
console.log(require('./package.json').version)
2829
} else {
29-
const rest = argv._
30+
const { commits, _: rest, ...options } = argv
3031

3132
if (rest[0] === 'lint') {
32-
argv.files = files(rest.slice(1))
33-
require('./index.js').lint(argv, done)
33+
options.files = files(rest.slice(1))
34+
require('./index.js').lint(options, done)
3435
} else if (rest[0] === 'fix') {
35-
argv.files = files(rest.slice(1))
36-
require('./index.js').fix(argv, done)
36+
options.files = files(rest.slice(1))
37+
require('./index.js').fix(options, done)
3738
} else if (rest[0] === 'bump') {
38-
const target = rest[1]
39-
40-
if (!target) {
41-
usage()
42-
process.exit(1)
39+
console.error("Error: the 'bump' command has been renamed to 'cc add'.\n")
40+
usage(1)
41+
} else if (rest[0] === 'cc') {
42+
if (rest[1] === 'add') {
43+
const target = rest[2]
44+
if (!target) usage(1)
45+
options.files = files(rest.slice(3))
46+
require('./index.js').cc.add(target, { ...options, commits }, done)
47+
} else {
48+
console.error('Error: unknown command.')
49+
usage(1)
4350
}
44-
45-
argv.files = files(rest.slice(2))
46-
require('./index.js').bump(target, argv, done)
4751
} else {
4852
// Old usage (no commands)
4953
// TODO: deprecate?
50-
argv.files = files(rest)
51-
require('./index.js')[argv.fix ? 'fix' : 'lint'](argv, done)
54+
options.files = files(rest)
55+
require('./index.js')[options.fix ? 'fix' : 'lint'](options, done)
5256
}
5357
}
5458

@@ -61,10 +65,16 @@ function done (err, result) {
6165
process.exit(result.code)
6266
}
6367

64-
function usage () {
68+
function usage (exitCode) {
6569
const fs = require('fs')
6670
const path = require('path')
67-
const usage = path.join(__dirname, 'USAGE')
71+
const usage = fs.readFileSync(path.join(__dirname, 'USAGE'), 'utf8').trim()
6872

69-
fs.createReadStream(usage).pipe(process.stdout)
73+
if (exitCode) {
74+
console.error(usage)
75+
process.exit(exitCode)
76+
} else {
77+
console.log(usage)
78+
process.exit()
79+
}
7080
}

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ exports.fix = function (options, callback) {
137137
return hallmark({ ...options, fix: true }, callback)
138138
}
139139

140-
exports.bump = function (target, options, callback) {
140+
exports.cc = {}
141+
exports.cc.add = function (target, options, callback) {
141142
if (!target) {
142143
throw new TypeError('First argument "target" is required')
143144
} else if (typeof target !== 'string') {
@@ -152,6 +153,7 @@ exports.bump = function (target, options, callback) {
152153
}
153154

154155
const changelog = {
156+
commits: options.commits !== false,
155157
...options.changelog,
156158
add: target
157159
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"remark": "^12.0.1",
2727
"remark-autolink-references": "^1.0.0",
2828
"remark-collapse": "~0.1.2",
29-
"remark-common-changelog": "^0.0.2",
29+
"remark-common-changelog": "^0.0.3",
3030
"remark-github": "^9.0.1",
3131
"remark-lint": "^7.0.1",
3232
"remark-lint-blockquote-indentation": "^2.0.1",

0 commit comments

Comments
 (0)