function updateVersionByRegex()

in scripts/updateVersion.ts [79:90]


function updateVersionByRegex(filePath: string, regex: RegExp, newVersion: string) {
    const oldFileContents = readFileSync(filePath).toString();
    const match = oldFileContents.match(regex);
    if (!match || !match[0] || !match[1]) {
        throw new Error(`Failed to find match for "${regex.source}".`);
    }
    const [oldLine, oldVersion] = match;
    const newLine = oldLine.replace(oldVersion, newVersion);
    const newFileContents = oldFileContents.replace(oldLine, newLine);
    writeFileSync(filePath, newFileContents);
    console.log(`Updated ${filePath} from ${oldVersion} to version ${newVersion}`);
}