Skip to content

Commit

Permalink
Breaking: accept multiple targets on cc add
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vweevers committed Nov 14, 2021
1 parent ecea8e2 commit 66edde1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 37 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,13 @@ README.md:5:3

## Usage

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

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

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.

Options:

- `--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).
- `--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).
- `--help`: print usage and exit
- `--version`: print version and exit
- `--report <reporter>`: see [Reporters](#reporters)
Expand All @@ -160,17 +158,17 @@ Options:

### Commands

#### `lint`
#### `lint [file...]`

Lint markdown files.
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.

#### `fix`
#### `fix [file...]`

Fix markdown files in place.
Fix markdown files in place. The optional `file` argument is the same as on `lint`.

#### `cc add <target>`
#### `cc add <target...>`

Add a release to `CHANGELOG.md` and populate it with commits. The `target` must be one of:
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:

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

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

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`.

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.

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.
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`.

## Package Options

Expand Down
38 changes: 19 additions & 19 deletions USAGE
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
Usage: hallmark [command] [options] [pattern ...]
Lint or fix files in the current working directory.

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 option.
Usage:
hallmark [command] [options]

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

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

Options:

-i --ignore <pattern> Files to ignore. Repeat to specify multiple patterns
-h --help Print usage and exit
-v --version Print version and exit
--report <reporter> Specify reporter
--[no-]color Force color in report (detected by default)
--fix Backwards-compatible alias for fix command
--no-commits Don't populate release with commits
-i --ignore <file> File or glob pattern to ignore (can be repeated)
-h --help Print usage and exit
-v --version Print version and exit
--report <reporter> Specify reporter
--[no-]color Force color in report (detected by default)
--fix Backwards-compatible alias for fix command
--no-commits Don't populate release with commits

Examples:

# Lint *.md files
$ hallmark

Expand Down
7 changes: 3 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ if (argv.help) {
usage(1)
} else if (rest[0] === 'cc') {
if (rest[1] === 'add') {
const target = rest[2]
if (!target) usage(1)
options.files = files(rest.slice(3))
hallmark.cc.add(target, { ...options, commits }, done)
const targets = rest.slice(2)
if (!targets.length || !targets.every(Boolean)) usage(1)
hallmark.cc.add(targets, { ...options, commits }, done)
} else {
console.error('Error: unknown command.')
usage(1)
Expand Down
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,12 @@ export const cc = {
add: function (target, options, callback) {
if (!target) {
throw new TypeError('First argument "target" is required')
} else if (Array.isArray(target)) {
if (!target.every(t => typeof t === 'string' && t.trim() !== '')) {
throw new TypeError('First argument "target" must be a string or array of strings')
}
} else if (typeof target !== 'string') {
throw new TypeError('First argument "target" must be a string')
throw new TypeError('First argument "target" must be a string or array of strings')
}

if (typeof options === 'function') {
Expand All @@ -177,13 +181,18 @@ export const cc = {
options = {}
}

if (!fs.existsSync(path.join(options.cwd || '.', 'CHANGELOG.md'))) {
fs.writeFileSync(path.join(options.cwd || '.', 'CHANGELOG.md'), '')
}

const files = ['CHANGELOG.md']
const changelog = {
commits: options.commits !== false,
...options.changelog,
add: target
}

return hallmark({ ...options, changelog, fix: true }, callback)
return hallmark({ ...options, files, changelog, fix: true }, callback)
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"remark": "^14.0.1",
"remark-autolink-references": "^2.0.0",
"remark-collapse": "~0.1.2",
"remark-common-changelog": "^0.0.3",
"remark-common-changelog": "^2.0.0",
"remark-gfm": "^3.0.1",
"remark-github": "^11.2.1",
"remark-lint": "^9.1.0",
Expand Down

0 comments on commit 66edde1

Please sign in to comment.