update-changelog-release-date.js 970 B

1234567891011121314151617181920212223242526272829303132
  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 pkg = require('../../package.json');
  7. if (pkg.version.indexOf('-rc') !== -1) {
  8. process.exit(0);
  9. }
  10. const version = pkg.version.replace(/-.*/, ''); // Remove the rc suffix
  11. const changelog = fs.readFileSync('CHANGELOG.md', 'utf8');
  12. // The changelog entry to be updated looks like this:
  13. // ## 2.5.3 (unreleased)
  14. // We need to add the date in a YYYY-MM-DD format, so that it looks like this:
  15. // ## 2.5.3 (2019-04-25)
  16. if (changelog.indexOf(`## ${version} (unreleased)`) === -1) {
  17. throw Error(`Found no changelog entry for version ${version}`);
  18. }
  19. fs.writeFileSync('CHANGELOG.md', changelog.replace(
  20. `## ${version} (unreleased)`,
  21. `## ${version} (${new Date().toISOString().split('T')[0]})`)
  22. );
  23. cp.execSync('git add CHANGELOG.md', { stdio: 'inherit' });