Skip to content

Instantly share code, notes, and snippets.

@schmichri
Created March 14, 2025 07:04
Show Gist options
  • Select an option

  • Save schmichri/724937834313af1e5113a01b66591e46 to your computer and use it in GitHub Desktop.

Select an option

Save schmichri/724937834313af1e5113a01b66591e46 to your computer and use it in GitHub Desktop.
Version Bump for Typescript and package.json
import semver from 'semver';
import fs from "fs";
function bumpVersion(currentVersion: string, release: 'major' | 'minor' | 'patch'): string {
const newVersion = semver.inc(currentVersion, release);
if (!newVersion) {
throw new Error('Failed to bump version');
}
return newVersion;
}
export const websitePackageJsonFilePath = process.env.WEBSITE_PACKAGE_JSON_FILE_PATH!;
export function bumpVersionInPackageJson(filePath: string, release: 'major' | 'minor' | 'patch'): void {
let file = fs.readFileSync(filePath, {encoding: "utf-8"})
let json = JSON.parse(file);
json.version = bumpVersion(json.version, release);
fs.writeFileSync(filePath, JSON.stringify(json, null, 2));
}
@schmichri
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment