<commit_before>const config = require("./version-config")
const git = require("gitty")
const _ = require("lodash")
const fs = require("fs")

const myRepo = git("")

const newVersion = config.currVersion

const dateTemplateRegExp = /^(## X\.Y\.Z )\(INSERT_DATE_HERE\)/
if (!dateTemplateRegExp.test(config.changeLogString)) {
    console.log(
        "CHANGELOG.md must have first line in the format '## X.Y.Z (INSERT_DATE_HERE)'"
    )
    process.exit(-1)
}

// updating CHANGELOG.md date
const nowDate = new Date()
const nowDateString = nowDate.toLocaleDateString("en-US").replace(/\//g, "-")
const changeLogDate = config.changeLogString.replace(
    dateTemplateRegExp,
    "## " + newVersion + " " + "(" + nowDateString + ")"
)
fs.writeFileSync(config.changeLogPath, changeLogDate)

_.forEach(config.docFilesPaths, function(currDocPath) {
    console.log("bumping file: <" + currDocPath + ">")
    const currItemContents = fs.readFileSync(currDocPath, "utf8").toString()
    const bumpedItemContents = currItemContents.replace(
        /\d+_\d+_\d+/,
        newVersion.replace(/\./g, "_")
    )
    fs.writeFileSync(currDocPath, bumpedItemContents)
})

console.log("bumping unpkg link in: <" + config.readmePath + ">")
console.log("bumping version on <" + config.versionPath + ">")
const oldVersionRegExpGlobal = new RegExp(oldVersion, "g")
const bumpedVersionTsFileContents = config.apiString.replace(
    /\d+\.\d+\.\d+/g,
    newVersion
)
fs.writeFileSync(config.versionPath, bumpedVersionTsFileContents)

const readmeContents = fs.readFileSync(config.readmePath, "utf8").toString()
const bumpedReadmeContents = readmeContents.replace(
    oldVersionRegExpGlobal,
    newVersion
)
fs.writeFileSync(config.readmePath, bumpedReadmeContents)

// Just adding to the current commit is sufficient as lerna does the commit + tag + push
myRepo.addSync(
    [config.versionPath, config.changeLogPath].concat(config.docFilesPaths)
)<commit_msg>Read old version number during version bump from the old version file.<commit_after>const config = require("./version-config")
const git = require("gitty")
const _ = require("lodash")
const fs = require("fs")

const myRepo = git("")

const newVersion = config.currVersion

const dateTemplateRegExp = /^(## X\.Y\.Z )\(INSERT_DATE_HERE\)/
if (!dateTemplateRegExp.test(config.changeLogString)) {
    console.log(
        "CHANGELOG.md must have first line in the format '## X.Y.Z (INSERT_DATE_HERE)'"
    )
    process.exit(-1)
}

// updating CHANGELOG.md date
const nowDate = new Date()
const nowDateString = nowDate.toLocaleDateString("en-US").replace(/\//g, "-")
const changeLogDate = config.changeLogString.replace(
    dateTemplateRegExp,
    "## " + newVersion + " " + "(" + nowDateString + ")"
)
fs.writeFileSync(config.changeLogPath, changeLogDate)

_.forEach(config.docFilesPaths, function(currDocPath) {
    console.log("bumping file: <" + currDocPath + ">")
    const currItemContents = fs.readFileSync(currDocPath, "utf8").toString()
    const bumpedItemContents = currItemContents.replace(
        /\d+_\d+_\d+/,
        newVersion.replace(/\./g, "_")
    )
    fs.writeFileSync(currDocPath, bumpedItemContents)
})

console.log("bumping unpkg link in: <" + config.readmePath + ">")
console.log("bumping version on <" + config.versionPath + ">")

const oldVersion = require("../lib/src/version").VERSION
const oldVersionRegExpGlobal = new RegExp(oldVersion, "g")
const bumpedVersionTsFileContents = config.apiString.replace(
    /\d+\.\d+\.\d+/g,
    newVersion
)
fs.writeFileSync(config.versionPath, bumpedVersionTsFileContents)

const readmeContents = fs.readFileSync(config.readmePath, "utf8").toString()
const bumpedReadmeContents = readmeContents.replace(
    oldVersionRegExpGlobal,
    newVersion
)
fs.writeFileSync(config.readmePath, bumpedReadmeContents)

// Just adding to the current commit is sufficient as lerna does the commit + tag + push
myRepo.addSync(
    [config.versionPath, config.changeLogPath].concat(config.docFilesPaths)
)
{'fraction_non_alphanumeric': 0.1416062046534901, 'fraction_numerical': 0.0015011258443832875, 'mean_word_length': 4.5220994475138125, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2485212', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1282, 'n_words': 252}