changelog.mjs 586 B

123456789101112131415
  1. import { readFile, writeFile } from 'fs/promises';
  2. export { addToChangelog };
  3. async function addToChangelog({ changelog, version, changelogPath = './CHANGELOG.md' }) {
  4. const changelogContent = await readFile(changelogPath, 'utf-8');
  5. const versionTitle = `## Version ${version}`;
  6. if (changelogContent.includes(versionTitle)) {
  7. throw new Error(`Version ${version} already exists in the changelog`);
  8. }
  9. const newChangeLogContent = changelogContent.replace('## ', `${versionTitle}\n\n${changelog}\n\n## `);
  10. await writeFile(changelogPath, newChangeLogContent, 'utf-8');
  11. }