diff --git a/README.md b/README.md index fb9ac5e..a54a393 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ npx changelogen@latest [...args] [--dir ] - `--dir`: Path to git repository. When not provided, **current working directory** will be used as as default. - `--clean`: Determine if the working directory is clean and if it is not clean, exit. - `--output`: Changelog file name to create or update. Defaults to `CHANGELOG.md` and resolved relative to dir. Use `--no-output` to write to console only. +- `--skipAuthors`: Skip contributors section in changelog. - `--bump`: Determine semver change and update version in `package.json`. - `--release`. Bumps version in `package.json` and creates commit and git tags using local `git`. You can disable commit using `--no-commit` and tag using `--no-tag`. You can enable the automatic push of the new tag and release commit to your git repository by adding `--push`. - `--publish`. Publishes package as a new version on `npm`. You will need to set authorisation tokens separately via `.npmrc` or environment variables. diff --git a/src/commands/default.ts b/src/commands/default.ts index 3af769b..4a5f492 100644 --- a/src/commands/default.ts +++ b/src/commands/default.ts @@ -25,6 +25,7 @@ export default async function defaultMain(args: Argv) { to: args.to, output: args.output, newVersion: typeof args.r === "string" ? args.r : undefined, + skipAuthors: args.skipAuthors, }); if (args.clean) { diff --git a/src/config.ts b/src/config.ts index 7b6359f..1a7a860 100644 --- a/src/config.ts +++ b/src/config.ts @@ -27,6 +27,7 @@ export interface ChangelogConfig { tagBody?: string; }; excludeAuthors: string[]; + skipAuthors: boolean; } export type ResolvedChangelogConfig = Omit & { @@ -72,6 +73,7 @@ const getDefaultConfig = () => tagBody: "v{{newVersion}}", }, excludeAuthors: [], + skipAuthors: false, }; export async function loadChangelogConfig( diff --git a/src/markdown.ts b/src/markdown.ts index 6fd3c89..4852b3d 100644 --- a/src/markdown.ts +++ b/src/markdown.ts @@ -85,7 +85,7 @@ export async function generateMarkDown( const authors = [..._authors.entries()].map((e) => ({ name: e[0], ...e[1] })); - if (authors.length > 0) { + if (authors.length > 0 && !config.skipAuthors) { markdown.push( "", "### " + "❤️ Contributors", diff --git a/test/contributors.test.ts b/test/contributors.test.ts new file mode 100644 index 0000000..2232674 --- /dev/null +++ b/test/contributors.test.ts @@ -0,0 +1,69 @@ +import { describe, expect, test } from "vitest"; +import { loadChangelogConfig, generateMarkDown } from "../src"; +import { testCommits } from "./fixtures/commits"; + +describe("contributors", () => { + test("should include authors", async () => { + const config = await loadChangelogConfig(process.cwd(), { + newVersion: "1.0.0", + }); + const contents = await generateMarkDown(testCommits, config); + + expect(contents).toMatchInlineSnapshot(` + "## v1.0.0 + + + ### 🚀 Enhancements + + - **scope:** Add feature + + ### 🩹 Fixes + + - **scope:** Resolve bug + + ### 📖 Documentation + + - **scope:** Update documentation + + ### 🏡 Chore + + - **scope:** Update dependencies + + ### ❤️ Contributors + + - John Doe ([@brainsucker](https://github.com/brainsucker)) + - Jane Smith + - Alice Johnson + - Bob Williams " + `); + }); + + test("should skip authors", async () => { + const config = await loadChangelogConfig(process.cwd(), { + newVersion: "1.0.0", + skipAuthors: true, + }); + const contents = await generateMarkDown(testCommits, config); + + expect(contents).toMatchInlineSnapshot(` + "## v1.0.0 + + + ### 🚀 Enhancements + + - **scope:** Add feature + + ### 🩹 Fixes + + - **scope:** Resolve bug + + ### 📖 Documentation + + - **scope:** Update documentation + + ### 🏡 Chore + + - **scope:** Update dependencies" + `); + }); +}); diff --git a/test/fixtures/commits.ts b/test/fixtures/commits.ts new file mode 100644 index 0000000..bb2f1f1 --- /dev/null +++ b/test/fixtures/commits.ts @@ -0,0 +1,62 @@ +export const testCommits = [ + { + author: { + name: "John Doe", + email: "john@doe.com", + }, + message: "feat: add feature", + shortHash: "1234", + body: "body", + type: "feat", + description: "add feature", + scope: "scope", + references: [], + authors: [], + isBreaking: false, + }, + { + author: { + name: "Jane Smith", + email: "jane@smith.com", + }, + message: "fix: resolve bug", + shortHash: "5678", + body: "body", + type: "fix", + description: "resolve bug", + scope: "scope", + references: [], + authors: [], + isBreaking: false, + }, + { + author: { + name: "Alice Johnson", + email: "alice@johnson.com", + }, + message: "chore: update dependencies", + shortHash: "9012", + body: "body", + type: "chore", + description: "update dependencies", + scope: "scope", + references: [], + authors: [], + isBreaking: false, + }, + { + author: { + name: "Bob Williams", + email: "bob@williams.com", + }, + message: "docs: update documentation", + shortHash: "3456", + body: "body", + type: "docs", + description: "update documentation", + scope: "scope", + references: [], + authors: [], + isBreaking: false, + }, +];