update-changelog-release-date.js 848 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env node
  2. // Sets the release date of the current release in the changelog.
  3. // This is run automatically when npm version is run.
  4. const fs = require('fs');
  5. const cp = require('child_process');
  6. const changelog = fs.readFileSync('CHANGELOG.md', 'utf8');
  7. // The changelog entry to be updated looks like this:
  8. // ## Unreleased
  9. // We need to add the version and release date in a YYYY-MM-DD format, so that it looks like this:
  10. // ## 2.5.3 (2019-04-25)
  11. const unreleased = /^## Unreleased$/im;
  12. if (!unreleased.test(changelog)) {
  13. console.error('Missing changelog entry');
  14. process.exit(1);
  15. }
  16. const { version } = require('../../package.json');
  17. fs.writeFileSync('CHANGELOG.md', changelog.replace(
  18. unreleased,
  19. `## ${version} (${new Date().toISOString().split('T')[0]})`)
  20. );
  21. cp.execSync('git add CHANGELOG.md', { stdio: 'inherit' });