From f528ba426f3eb955fce07dbb7c6ce83217b611be Mon Sep 17 00:00:00 2001 From: Yannik Beaulieu Date: Tue, 4 Feb 2025 18:24:57 +0000 Subject: [PATCH 1/2] Add bullet style support --- README.md | 11 +++++++++++ bin.ts | 6 +++++- src/Change.ts | 4 ++-- src/Changelog.ts | 1 + src/Release.ts | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 39c595659..c69044ffd 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,16 @@ const changelog = new Changelog(); changelog.format = "markdownlint"; ``` +### Custom bullet style + +By default, the bullet style of the markdown is "-". You can change it to use +other styles of bullet points: + +```js +const changelog = new Changelog(); +changelog.bulletStyle = "*"; +``` + ### Custom tag names By default, the tag names are `v` + version number. For example, the tag for the @@ -190,6 +200,7 @@ Available options: | Option | Description | | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `--format` | The output format for the generated markdown. It can be `markdownlint` or `compact`. The default value is `compact`. | +| `--bullet-style` | The Markdown bullet style to use. It can be `-`, `*+*`, `+`. The default value is `-`. | | `--file` | The markdown file of the changelog. The default value is `CHANGELOG.md`. | | `--url` | The base url used to build the diff urls of the different releases. It is taken from the existing diff urls in the markdown. If no urls are found, try to catch it using the url of the git remote repository. | | `--https` | Set to false to use `http` instead `https` in the url (`--https=false`). | diff --git a/bin.ts b/bin.ts index 00ac2c106..c9409d886 100755 --- a/bin.ts +++ b/bin.ts @@ -16,8 +16,9 @@ const argv = parseArgs(Deno.args, { https: true, quiet: false, head: null, + "bullet-style": "-", }, - string: ["file", "format", "url", "head"], + string: ["file", "format", "url", "head", "bullet-style"], boolean: ["https", "init", "latest-release", "quiet", "help"], alias: { h: "help", @@ -38,6 +39,7 @@ try { ); changelog.format = argv.format as "compact" | "markdownlint"; + changelog.bulletStyle = argv['bullet-style'] as "-" | "*" | "+"; save(file, changelog, true); Deno.exit(0); @@ -45,6 +47,7 @@ try { const changelog = parser(Deno.readTextFileSync(file)); changelog.format = argv.format as "compact" | "markdownlint"; + changelog.bulletStyle = argv['bullet-style'] as "-" | "*" | "+"; if (argv["no-v-prefix"]) { changelog.tagNameBuilder = (release) => String(release.version); } @@ -184,6 +187,7 @@ Usage: keep-a-changelog [options] Options: --file, -f Changelog file (default: CHANGELOG.md) --format Output format (default: compact) + --bullet-style Bullet point style (default: -) --url Repository URL --init Initialize a new changelog file diff --git a/src/Change.ts b/src/Change.ts index 4b7c10584..ab17de0df 100644 --- a/src/Change.ts +++ b/src/Change.ts @@ -26,9 +26,9 @@ export default class Change { this.description = Change.extractIssues(description, this.issues); } - toString() { + toString(bulletStyle = "-") { let t = this.title.split("\n").map((line) => ` ${line}`.trimEnd()); - t[0] = "-" + t[0].substr(1); + t[0] = bulletStyle + t[0].substr(1); if (this.description) { t.push(""); diff --git a/src/Changelog.ts b/src/Changelog.ts index 0bf374c1c..a7b903f00 100644 --- a/src/Changelog.ts +++ b/src/Changelog.ts @@ -15,6 +15,7 @@ export default class Changelog { compareLinkBuilder?: (previous: Release, release: Release) => string; tagLinkBuilder?: (url: string, tag: string, previous?: string) => string; format: "compact" | "markdownlint" = "compact"; + bulletStyle: "-" | "*" | "+" = "-"; constructor(title: string, description = "") { this.title = title; diff --git a/src/Release.ts b/src/Release.ts index 6c1dd2ae8..c902f2ced 100644 --- a/src/Release.ts +++ b/src/Release.ts @@ -163,7 +163,7 @@ export default class Release { if (changelog?.format === "markdownlint") { t.push(""); } - t = t.concat(changes.map((change) => change.toString())); + t = t.concat(changes.map((change) => change.toString(changelog?.bulletStyle))); t.push(""); } }); From 5498042d9c8aa6ca245f3a1095fdbe4f16102b3c Mon Sep 17 00:00:00 2001 From: Yannik Beaulieu Date: Wed, 5 Feb 2025 14:01:17 -0500 Subject: [PATCH 2/2] Add unit test --- test/Change.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/Change.test.ts b/test/Change.test.ts index a65754637..85025b34e 100644 --- a/test/Change.test.ts +++ b/test/Change.test.ts @@ -93,3 +93,9 @@ Deno.test("should extract issues which are inside parentheses with brackets", fu assertEquals(text, "some change - ([#777])"); assert(issues.includes("777")); }); + +Deno.test("should use given bullet style", function () { + const change = new Change("some change"); + const result = change.toString("*"); + assertEquals(result, "* some change"); +});