Skip to content

Commit 66edde1

Browse files
committed
Breaking: accept multiple targets on cc add
Previously, `hallmark bump <target>` would add a release to `CHANGELOG.md` and fix `*.md` files. Any further arguments were taken as file arguments, overriding the default `*.md` pattern. Now, `hallmark cc add <target>` only touches `CHANGELOG.md` and accepts multiple targets: `hallmark cc add 1.1.0 1.2.0` will add two releases to `CHANGELOG.md`. Ref #84
1 parent ecea8e2 commit 66edde1

5 files changed

Lines changed: 45 additions & 37 deletions

File tree

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,13 @@ README.md:5:3
143143

144144
## Usage
145145

146-
`hallmark [command] [options] [pattern ...]`
146+
`hallmark [command] [options]`
147147

148148
Lint or fix files in the current working directory. The default command is `lint`.
149149

150-
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.
151-
152150
Options:
153151

154-
- `--ignore / -i <pattern>`: files to ignore. Repeat to specify multiple patterns (e.g. `-i a.md -i docs/*.md`). Can also be configured via [Package Options](#package-options).
152+
- `--ignore / -i <file>`: file or glob pattern to ignore. Repeat to specify multiple (e.g. `-i a.md -i docs/*.md`). Can also be configured via [Package Options](#package-options).
155153
- `--help`: print usage and exit
156154
- `--version`: print version and exit
157155
- `--report <reporter>`: see [Reporters](#reporters)
@@ -160,17 +158,17 @@ Options:
160158

161159
### Commands
162160

163-
#### `lint`
161+
#### `lint [file...]`
164162

165-
Lint markdown files.
163+
Lint markdown files. By default `hallmark` includes files matching `*.md`. To override this, provide one or more file arguments which can be file paths or glob patterns. Files matching `.gitignore` patterns are ignored. To ignore additional files, use the `--ignore / -i` option.
166164

167-
#### `fix`
165+
#### `fix [file...]`
168166

169-
Fix markdown files in place.
167+
Fix markdown files in place. The optional `file` argument is the same as on `lint`.
170168

171-
#### `cc add <target>`
169+
#### `cc add <target...>`
172170

173-
Add a release to `CHANGELOG.md` and populate it with commits. The `target` must be one of:
171+
Add release(s) to `CHANGELOG.md` and populate it with commits. If no `CHANGELOG.md` file exists then it will be created. The `target` argument must be one of:
174172

175173
- A release type: `major`, `minor`, `patch`, `premajor`, `preminor`, `prepatch`, `prerelease`
176174
- These take the current version from the semver-latest tag, release or `package.json` (whichever is greatest if found) and bump it
@@ -185,9 +183,11 @@ Additional options for this command:
185183

186184
- `--no-commits`: create an empty release.
187185

186+
Multiple targets can be provided, in no particular order. For example `hallmark cc add 1.1.0 1.2.0` which acts as a shortcut for `hallmark cc add 1.1.0 && hallmark cc add 1.2.0`.
187+
188188
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.
189189

190-
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.
190+
The `cc add` command also fixes markdown (both existing content and generated content) but only in `CHANGELOG.md`. After you tweak the release following [Common Changelog](https://common-changelog.org) you may want to run `hallmark fix`.
191191

192192
## Package Options
193193

USAGE

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
Usage: hallmark [command] [options] [pattern ...]
1+
Lint or fix files in the current working directory.
22

3-
Lint or fix files in the current working directory. By default hallmark
4-
includes files matching "*.md". Pass one or more glob patterns to override
5-
this. Files matching .gitignore patterns are ignored. To ignore additional
6-
files, use the --ignore option.
3+
Usage:
4+
hallmark [command] [options]
75

86
Commands:
7+
lint [file...] Lint markdown files (default)
8+
fix [file...] Fix markdown files
9+
cc add <target...> Add release(s) to CHANGELOG.md.
910

10-
lint Lint markdown files (default)
11-
fix Fix markdown files
12-
cc add <target> Add new release to CHANGELOG.md. Target must be
13-
a release type (major, minor, patch, premajor,
14-
preminor, prepatch, prerelease) or a version.
11+
Arguments:
12+
file By default hallmark includes files matching "*.md".
13+
To override this provide one or more file arguments
14+
which can be file paths or glob patterns.
15+
target A release type (major, minor, patch, premajor,
16+
preminor, prepatch, prerelease) or a version.
1517

1618
Options:
17-
18-
-i --ignore <pattern> Files to ignore. Repeat to specify multiple patterns
19-
-h --help Print usage and exit
20-
-v --version Print version and exit
21-
--report <reporter> Specify reporter
22-
--[no-]color Force color in report (detected by default)
23-
--fix Backwards-compatible alias for fix command
24-
--no-commits Don't populate release with commits
19+
-i --ignore <file> File or glob pattern to ignore (can be repeated)
20+
-h --help Print usage and exit
21+
-v --version Print version and exit
22+
--report <reporter> Specify reporter
23+
--[no-]color Force color in report (detected by default)
24+
--fix Backwards-compatible alias for fix command
25+
--no-commits Don't populate release with commits
2526

2627
Examples:
27-
2828
# Lint *.md files
2929
$ hallmark
3030

cli.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ if (argv.help) {
3939
usage(1)
4040
} else if (rest[0] === 'cc') {
4141
if (rest[1] === 'add') {
42-
const target = rest[2]
43-
if (!target) usage(1)
44-
options.files = files(rest.slice(3))
45-
hallmark.cc.add(target, { ...options, commits }, done)
42+
const targets = rest.slice(2)
43+
if (!targets.length || !targets.every(Boolean)) usage(1)
44+
hallmark.cc.add(targets, { ...options, commits }, done)
4645
} else {
4746
console.error('Error: unknown command.')
4847
usage(1)

index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,12 @@ export const cc = {
166166
add: function (target, options, callback) {
167167
if (!target) {
168168
throw new TypeError('First argument "target" is required')
169+
} else if (Array.isArray(target)) {
170+
if (!target.every(t => typeof t === 'string' && t.trim() !== '')) {
171+
throw new TypeError('First argument "target" must be a string or array of strings')
172+
}
169173
} else if (typeof target !== 'string') {
170-
throw new TypeError('First argument "target" must be a string')
174+
throw new TypeError('First argument "target" must be a string or array of strings')
171175
}
172176

173177
if (typeof options === 'function') {
@@ -177,13 +181,18 @@ export const cc = {
177181
options = {}
178182
}
179183

184+
if (!fs.existsSync(path.join(options.cwd || '.', 'CHANGELOG.md'))) {
185+
fs.writeFileSync(path.join(options.cwd || '.', 'CHANGELOG.md'), '')
186+
}
187+
188+
const files = ['CHANGELOG.md']
180189
const changelog = {
181190
commits: options.commits !== false,
182191
...options.changelog,
183192
add: target
184193
}
185194

186-
return hallmark({ ...options, changelog, fix: true }, callback)
195+
return hallmark({ ...options, files, changelog, fix: true }, callback)
187196
}
188197
}
189198

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"remark": "^14.0.1",
2929
"remark-autolink-references": "^2.0.0",
3030
"remark-collapse": "~0.1.2",
31-
"remark-common-changelog": "^0.0.3",
31+
"remark-common-changelog": "^2.0.0",
3232
"remark-gfm": "^3.0.1",
3333
"remark-github": "^11.2.1",
3434
"remark-lint": "^9.1.0",

0 commit comments

Comments
 (0)