-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
95 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
|
||
export function changePackageJsonMainVersion(path: string, version: string): void { | ||
const contents = fs.readFileSync(path, 'utf-8'); | ||
|
||
const regex = /"version": "(\d+\.\d+\.\d+)",/; | ||
const match = contents.match(regex); | ||
if (!match) { | ||
throw new Error(`Could not find version in ${path}`); | ||
} | ||
const oldVersion = match[1]; | ||
const newContents = contents.replace(oldVersion, version); | ||
fs.writeFileSync(path, newContents); | ||
console.log(`Updated ${path} version`); | ||
} | ||
|
||
export function changePyProjectTomlVersion(path: string, version: string): void { | ||
const contents = fs.readFileSync(path, 'utf-8'); | ||
|
||
const regex = /version = "(\d+\.\d+\.\d+)"/; | ||
const match = contents.match(regex); | ||
if (!match) { | ||
throw new Error(`Could not find version in ${path}`); | ||
} | ||
const oldVersion = match[1]; | ||
const newContents = contents.replace(oldVersion, version); | ||
fs.writeFileSync(path, newContents); | ||
console.log(`Updated ${path} version`); | ||
} | ||
|
||
export function changePythonRequirementsVersion(path: string, key: string, version: string): void { | ||
const contents = fs.readFileSync(path, 'utf-8'); | ||
|
||
const regex = new RegExp(`${key}==\\d+\\.\\d+\\.\\d+`); | ||
const match = contents.match(regex); | ||
|
||
if (!match) { | ||
throw new Error(`Could not find ${key} in ${path}`); | ||
} | ||
|
||
const oldVersion = match[0]; | ||
const newContents = contents.replace(oldVersion, `${key}==${version}`); | ||
fs.writeFileSync(path, newContents); | ||
console.log(`Updated ${path} version`); | ||
} | ||
|
||
export function changePackageJsonDependenciesVersion(path: string, key: string, version: string): void { | ||
const contents = fs.readFileSync(path, 'utf-8'); | ||
|
||
const regex = new RegExp(`"${key}": "\\d+\\.\\d+\\.\\d+"`); | ||
const match = contents.match(regex); | ||
if (!match) { | ||
throw new Error(`Could not find ${key} in ${path}`); | ||
} | ||
|
||
const oldVersion = match[0]; | ||
const newContents = contents.replace(oldVersion, `"${key}": "${version}"`); | ||
fs.writeFileSync(path, newContents); | ||
console.log(`Updated ${path} version`); | ||
} |
This file contains 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