Created
March 14, 2025 07:04
-
-
Save schmichri/724937834313af1e5113a01b66591e46 to your computer and use it in GitHub Desktop.
Version Bump for Typescript and package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used in the pipeline of https://www.license-token.com/wiki.
the https://gist.github.com/schmichri/2c7b12edb62845249de601c0c3c46f7f reads the Package Json