diff options
Diffstat (limited to 'scripts/shared/changelog.mjs')
-rw-r--r-- | scripts/shared/changelog.mjs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/scripts/shared/changelog.mjs b/scripts/shared/changelog.mjs new file mode 100644 index 0000000..d5bf73c --- /dev/null +++ b/scripts/shared/changelog.mjs @@ -0,0 +1,15 @@ +import { readFile, writeFile } from 'fs/promises'; + +export { addToChangelog }; + +async function addToChangelog({ changelog, version, changelogPath = './CHANGELOG.md' }) { + const changelogContent = await readFile(changelogPath, 'utf-8'); + const versionTitle = `## Version ${version}`; + + if (changelogContent.includes(versionTitle)) { + throw new Error(`Version ${version} already exists in the changelog`); + } + + const newChangeLogContent = changelogContent.replace('## ', `${versionTitle}\n\n${changelog}\n\n## `); + await writeFile(changelogPath, newChangeLogContent, 'utf-8'); +} |