Skip to content

Commit

Permalink
Merge pull request #48 from Bibz87/bullet-style-support
Browse files Browse the repository at this point in the history
Add bullet style support
  • Loading branch information
oscarotero authored Feb 6, 2025
2 parents 6cb0f25 + 5498042 commit a2440a0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`). |
Expand Down
6 changes: 5 additions & 1 deletion bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -38,13 +39,15 @@ try {
);

changelog.format = argv.format as "compact" | "markdownlint";
changelog.bulletStyle = argv['bullet-style'] as "-" | "*" | "+";

save(file, changelog, true);
Deno.exit(0);
}

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);
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand Down
1 change: 1 addition & 0 deletions src/Changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
}
});
Expand Down
6 changes: 6 additions & 0 deletions test/Change.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

0 comments on commit a2440a0

Please sign in to comment.