diff --git a/README.md b/README.md index 995d99a..50d72e9 100644 --- a/README.md +++ b/README.md @@ -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 `: 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 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 `: see [Reporters](#reporters) @@ -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 ` +#### `cc add ` -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 @@ -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 diff --git a/USAGE b/USAGE index 990a174..376872b 100644 --- a/USAGE +++ b/USAGE @@ -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 Add release(s) to CHANGELOG.md. - lint Lint markdown files (default) - fix Fix markdown files - cc add 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 Files to ignore. Repeat to specify multiple patterns - -h --help Print usage and exit - -v --version Print version and exit - --report 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 or glob pattern to ignore (can be repeated) + -h --help Print usage and exit + -v --version Print version and exit + --report 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 diff --git a/cli.js b/cli.js index 3ba0850..c53858c 100644 --- a/cli.js +++ b/cli.js @@ -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) diff --git a/index.js b/index.js index 4a6703b..97a1dbb 100644 --- a/index.js +++ b/index.js @@ -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') { @@ -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) } } diff --git a/package.json b/package.json index 7add843..2601e3a 100644 --- a/package.json +++ b/package.json @@ -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",