diff --git a/README.md b/README.md index 5344901..d606ebf 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ Add release(s) to `CHANGELOG.md` and populate it with commits. If no `CHANGELOG. - 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`). - A [semver-valid](https://semver.org/) version like 2.4.0. -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. +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. If the version equals `0.0.1` or `1.0.0` and zero versions exist, then a [notice](https://common-changelog.org/#23notice) will be inserted (rather than commits) containing the text `:seedling: Initial release.`. Additional options for this command: @@ -189,6 +189,16 @@ Works best on a linear git history. If `hallmark` encounters other tags in the c 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`. +#### `cc init` + +Create a `CHANGELOG.md` from scratch. Inserts releases for every (semver-valid) git tag and then populates them with commits. If no git tags exist then the resulting `CHANGELOG.md` will merely have a `# Changelog` heading, without releases. + +Additional options for this command: + +- `--no-commits`: create empty releases +- `--gte `: only include versions greater than or equal to this version +- `--lte `: only include versions less than or equal to this version. + ## Package Options You can add a `hallmark` object to your `package.json` with additional configuration. For example: diff --git a/USAGE b/USAGE index 376872b..c09b4f1 100644 --- a/USAGE +++ b/USAGE @@ -7,6 +7,8 @@ Commands: lint [file...] Lint markdown files (default) fix [file...] Fix markdown files cc add Add release(s) to CHANGELOG.md. + cc init Create a CHANGELOG.md from scratch. Inserts releases + for all versions unless --gte or --lte are provided. Arguments: file By default hallmark includes files matching "*.md". @@ -23,6 +25,8 @@ Options: --[no-]color Force color in report (detected by default) --fix Backwards-compatible alias for fix command --no-commits Don't populate release with commits + --gte Only include versions greater than or equal to this + --lte Only include versions less than or equal to this Examples: # Lint *.md files diff --git a/cli.js b/cli.js index c53858c..7ab6916 100644 --- a/cli.js +++ b/cli.js @@ -42,6 +42,9 @@ if (argv.help) { const targets = rest.slice(2) if (!targets.length || !targets.every(Boolean)) usage(1) hallmark.cc.add(targets, { ...options, commits }, done) + } else if (rest[1] === 'init') { + const { gte, lte, ...rest } = options + hallmark.cc.add({ gte, lte }, { ...rest, commits }, done) } else { console.error('Error: unknown command.') usage(1) diff --git a/index.js b/index.js index 97a1dbb..a3dd269 100644 --- a/index.js +++ b/index.js @@ -170,6 +170,8 @@ export const cc = { 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 === 'object' && target !== null) { + // Range } else if (typeof target !== 'string') { throw new TypeError('First argument "target" must be a string or array of strings') } @@ -181,11 +183,13 @@ 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 fp = path.join(options.cwd || '.', files[0]) + + if (!fs.existsSync(fp)) { + fs.writeFileSync(fp, '# Changelog\n') } - const files = ['CHANGELOG.md'] const changelog = { commits: options.commits !== false, ...options.changelog, diff --git a/package.json b/package.json index 143e5a2..b2e44f1 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "remark": "^14.0.1", "remark-autolink-references": "^2.0.0", "remark-collapse": "~0.1.2", - "remark-common-changelog": "^2.0.0", + "remark-common-changelog": "^2.1.0", "remark-gfm": "^3.0.1", "remark-github": "^11.2.2", "remark-lint": "^9.1.0",