<commit_before>// Helper for the QUnit release preparation commit.
//
// See also RELEASE.md.
//
// Inspired by <https://github.com/jquery/jquery-release>.

const fs = require('fs');
const path = require('path');
const util = require('util');
const cp = require('child_process');
const gitAuthors = require('grunt-git-authors');

function parseLineResults (output = '') {
  output = output.trim();
  return !output ? [] : output.split('\n');
}

function versionAddedString (version) {
  return `version_added: "${version}"`;
}

const Repo = {
  async prep (version) {
    if (typeof version !== 'string' || !/^\d+\.\d+\.\d+$/.test(version)) {
      throw new Error('Invalid or missing version argument');
    }
    {
      const UNRELEASED_VERSION = versionAddedString('unreleased');

      // grep exits non-zero if no results
      const results = parseLineResults(cp.execSync(
        `grep -l '${UNRELEASED_VERSION}' docs/**/*.md || echo`,
        { encoding: 'utf8' }
      ));
      results.forEach(filePath => {
        const doc = fs.readFileSync(filePath, 'utf8');
        fs.writeFileSync(filePath,
          doc.replace(UNRELEASED_VERSION, versionAddedString(version))
        );
      });<commit_msg>Build: Add changelog substitution to prep-release.js<commit_after>// Helper for the QUnit release preparation commit.
//
// See also RELEASE.md.
//
// Inspired by <https://github.com/jquery/jquery-release>.

const fs = require('fs');
const path = require('path');
const util = require('util');
const cp = require('child_process');
const gitAuthors = require('grunt-git-authors');

function parseLineResults (output = '') {
  output = output.trim();
  return !output ? [] : output.split('\n');
}

function versionAddedString (version) {
  return `version_added: "${version}"`;
}

function formatChangelogColumn (version) {
  return `| [QUnit ${version}](https://github.com/qunitjs/qunit/releases/tag/${version}) |`;
}

const Repo = {
  async prep (version) {
    if (typeof version !== 'string' || !/^\d+\.\d+\.\d+$/.test(version)) {
      throw new Error('Invalid or missing version argument');
    }
    {
      const UNRELEASED_ADDED = versionAddedString('unreleased');
      const UNRELEASED_CHANGELOG = '| UNRELEASED |';

      // Silence error from grep, which exits non-zero if no results.
      const results = parseLineResults(cp.execSync(
        'grep -F -i -l unreleased docs/**/*.md || echo',
        { encoding: 'utf8' }
      ));
      results.forEach(filePath => {
        const doc = fs.readFileSync(filePath, 'utf8');
        fs.writeFileSync(filePath,
          doc
            .replace(UNRELEASED_ADDED, versionAddedString(version))
            .replace(UNRELEASED_CHANGELOG, formatChangelogColumn(version))
        );
      });
{'fraction_non_alphanumeric': 0.16020297209133744, 'fraction_numerical': 0.0014498006524102935, 'mean_word_length': 3.207317073170732, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 3, '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': '5732844', 'n_tokens_mistral': 854, 'n_tokens_neox': 849, 'n_words': 197}