@coveo/semantic-monorepo-tools
Version:
A library of helper functions to do SemVer2 compliant releases from Conventional Commits in monorepos
31 lines (28 loc) • 820 B
text/typescript
import changelogWriter, {
Context,
Options,
} from "conventional-changelog-writer";
import type { Commit } from "conventional-commits-parser";
interface WriterContext extends Context {
currentTag: string;
previousTag: string;
}
export default function (
parsedCommits: Array<Commit>,
newVersion: string,
writerContext: Partial<WriterContext> = {},
writerOpts: Options = {},
) {
const ctx = {
...writerContext,
version: newVersion,
};
let changelog = "";
const changelogStream = changelogWriter(ctx, writerOpts);
changelogStream.on("data", (data) => (changelog += data.toString()));
parsedCommits.forEach((commit) => changelogStream.write(commit));
changelogStream.end();
return new Promise<string>((resolve) =>
changelogStream.on("finish", () => resolve(changelog)),
);
}