<commit_before>#!/usr/bin/env node

// Sets the release date of the current release in the changelog.
// This is run automatically when npm version is run.

const fs = require('fs');
const cp = require('child_process');

const suffix = process.env.PRERELEASE_SUFFIX || 'rc';

const changelog = fs.readFileSync('CHANGELOG.md', 'utf8');

// The changelog entry to be updated looks like this:
// ## Unreleased
// We need to add the version and release date in a YYYY-MM-DD format, so that it looks like this:
// ## 2.5.3 (2019-04-25)

const pkg = require('../../package.json');
const version = pkg.version.replace(new RegExp('-' + suffix + '\\..*'), '');

const unreleased = /^## Unreleased$/im;
const released = new RegExp(`^## ${version} \\([-\\d]*\\)$`, 'm');

if (released.test(changelog)) {
  process.exit(0);
}

if (!unreleased.test(changelog)) {
  console.error('Missing changelog entry');
  process.exit(1);
}

fs.writeFileSync('CHANGELOG.md', changelog.replace(
  unreleased,
  `## ${version} (${new Date().toISOString().split('T')[0]})`),
);

cp.execSync('git add CHANGELOG.md', { stdio: 'inherit' });
<commit_msg>Fix changelog versioning to include date only after final release<commit_after>#!/usr/bin/env node

// Sets the release date of the current release in the changelog.
// This is run automatically when npm version is run.

const fs = require('fs');
const cp = require('child_process');

const suffix = process.env.PRERELEASE_SUFFIX || 'rc';

const changelog = fs.readFileSync('CHANGELOG.md', 'utf8');

// The changelog entry to be updated looks like this:
// ## Unreleased
// We need to add the version and release date in a YYYY-MM-DD format, so that it looks like this:
// ## 2.5.3 (2019-04-25)

const pkg = require('../../package.json');
const version = pkg.version.replace(new RegExp('-' + suffix + '\\..*'), '');

const header = new RegExp(`^## (Unreleased|${version})$`, 'm');

if (!header.test(changelog)) {
  console.error('Missing changelog entry');
  process.exit(1);
}

const newHeader = pkg.version.indexOf(suffix) === -1
  ? `## ${version} (${new Date().toISOString().split('T')[0]})`
  : `## ${version}`;

fs.writeFileSync('CHANGELOG.md',
  changelog.replace(header, newHeader)
);

cp.execSync('git add CHANGELOG.md', { stdio: 'inherit' });

{'fraction_non_alphanumeric': 0.1882145998240985, 'fraction_numerical': 0.013192612137203167, 'mean_word_length': 4.205949656750572, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4257005', 'n_tokens_mistral': 795, 'n_tokens_neox': 772, 'n_words': 217}