Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createDedupeWriterOptions(changelogPath: string) {
const existingChangelogContent = readFileSync(changelogPath, 'utf8');
const commitSortFunction = changelogCompare.functionify(['type', 'scope', 'subject']);
return {
// Overwrite the changelog templates so that we can render the commits grouped
// by package names. Templates are based on the original templates of the
// angular preset: "conventional-changelog-angular/templates".
mainTemplate: readFileSync(join(__dirname, 'changelog-root-template.hbs'), 'utf8'),
commitPartial: readFileSync(join(__dirname, 'changelog-commit-template.hbs'), 'utf8'),
// Specify a writer option that can be used to modify the content of a new changelog section.
// See: conventional-changelog/tree/master/packages/conventional-changelog-writer
finalizeContext: (context: any) => {
const packageGroups: {[packageName: string]: ChangelogPackage} = {};
context.commitGroups.forEach((group: any) => {
group.commits.forEach((commit: any) => {
// Filter out duplicate commits. Note that we cannot compare the SHA because the commits
// will have a different SHA if they are being cherry-picked into a different branch.
function createChangelogWriterOptions(changelogPath: string, presetWriterOptions: any) {
const existingChangelogContent = readFileSync(changelogPath, 'utf8');
const commitSortFunction = changelogCompare.functionify(['type', 'scope', 'subject']);
const allPackages = [...orderedChangelogPackages, ...excludedChangelogPackages];
return {
// Overwrite the changelog templates so that we can render the commits grouped
// by package names. Templates are based on the original templates of the
// angular preset: "conventional-changelog-angular/templates".
mainTemplate: readFileSync(join(__dirname, 'changelog-root-template.hbs'), 'utf8'),
commitPartial: readFileSync(join(__dirname, 'changelog-commit-template.hbs'), 'utf8'),
// Overwrites the conventional-changelog-angular preset transform function. This is necessary
// because the Angular preset changes every commit note to a breaking change note. Since we
// have a custom note type for deprecations, we need to keep track of the original type.
transform: (commit, context) => {
commit.notes.forEach(n => n.type = n.title);
return presetWriterOptions.transform(commit, context);
},