$ npm install conventional-changelogGenerate a changelog from git metadata.
[!NOTE] You don't have to use the angular commit convention. For the best result of the tool to tokenize your commit and produce flexible output, it's recommended to use a commit convention.
# pnpm
pnpm add conventional-changelog
# yarn
yarn add conventional-changelog
# npm
npm i conventional-changelog
conventional-changelog -p angular
This will not overwrite any previous changelogs. The above generates a changelog based on commits since the last semver tag that matches the pattern of "Feature", "Fix", "Performance Improvement" or "Breaking Changes".
If this is your first time using this tool and you want to generate all previous changelogs, you could do
conventional-changelog -p angular -r 0
This will overwrite any previous changelogs if they exist.
All available command line parameters can be listed using CLI: conventional-changelog --help.
[!TIP] You can alias your command or add it to your package.json. EG:
"changelog": "conventional-changelog -p angular -r 0".
package.jsonconventional-changelogpackage.json and CHANGELOG.md filesThe reason why you should commit and tag after conventional-changelog is that the CHANGELOG should be included in the new release, hence commits.from defaults to the latest semver tag.
npm versionUsing the npm scripts to our advantage with the following hooks:
{
"scripts": {
"version": "conventional-changelog -p angular && git add CHANGELOG.md"
}
}
You could follow the following workflow
npm version [patch|minor|major] commandYou could optionally add a preversion script to package your project or running a full suit of test.
And a postversion script to clean your system and push your release and tags.
By adding a .npmrc you could also automate your commit message and set your tag prefix as such:
tag-version-prefix=""
message="chore(release): %s :tada:"
import { ConventionalChangelog } from 'conventional-changelog'
const generator = new ConventionalChangelog()
.readPackage()
.loadPreset('angular')
generator
.writeStream()
.pipe(process.stdout)
// or
for await (const chunk of generator.write()) {
console.log(chunk)
}
new ConventionalChangelog(cwdOrGitClient: string | ConventionalGitClient = process.cwd())Create a new instance of conventional-changelog generator. cwdOrGitClient is the current working directory or a ConventionalGitClient instance.
generator.loadPreset(preset: PresetParams): thisLoad and set necessary params from a preset.
generator.config(config: Preset | Promise<Preset>): thisSet the config directly.
generator.readPackage(transform?: PackageTransform): thisFind package.json up the directory tree and read it. Optionally transform the package data.
generator.readPackage(path: string, transform?: PackageTransform): thisRead a package.json file from a specific path. Optionally transform the package data.
generator.package(pkg: Record<string, unknown>): thisSet the package data directly.
generator.readRepository(): thisRead and parse the repository URL from current git repository.
generator.repository(infoOrGitUrl: string | Partial<HostedGitInfo>): thisSet the repository info directly.
generator.options(options: Options): thisSet conventional-changelog options.
| Name | Type | Default | Description |
|---|---|---|---|
| reset | boolean | false | Whether to reset the changelog or not. |
| append | boolean | false | Should the log be appended to existing data. |
| releaseCount | number | 1 | How many releases of changelog you want to generate. It counts from the upcoming release. Useful when you forgot to generate any previous changelog. Set to 0 to regenerate all. |
| outputUnreleased | boolean | true if a different version than last release is given. Otherwise false | If this value is true and context.version equals last release then context.version will be changed to 'Unreleased'. |
| transformCommit | (commit: Commit, params: Params) => Partial<Commit> | Promise<Partial<Commit> | null> | null | A transform function that applies after the parser and before the writer. | |
| warn | function | Logger for warnings | |
| debug | function | Logger for debug messages | |
| fromatDate | (date: Date) => string | Custom date formatter function. |
generator.context(context: Context): thisSet the writer context.
generator.tags(params: GetSemverTagsParams): thisSet params to get semver tags.
| Name | Type | Default | Description |
|---|---|---|---|
| prefix | string | RegExp | Specify a prefix for the git tag that will be taken into account during the comparison. | |
| skipUnstable | boolean | false | If set, unstable release tags will be skipped, e.g. x.x.x-rc. |
| clean | boolean | false | Clean version from prefix and trash. |
If you want to take package-prefixed tags, for example lerna-style tags, you should use packagePrefix utility function:
import {
ConventionalChangelog,
packagePrefix
} from 'conventional-changelog'
const generator = new ConventionalChangelog()
.readPackage()
.loadPreset('angular')
.tags({
prefix: packagePrefix('foo-package')
})
generator.commits(params: GetCommitsParams, parserOptions?: ParserStreamOptions): thisSet params to get commits.
generator.writer(params: WriterOptions): thisSet writer options.
generator.write(includeDetails?: boolean): AsyncGenerator<string | Details<Commit>, void>Generate changelog.
generator.writeStream(includeDetails?: boolean): ReadableGenerate changelog stream.
MIT