This package has been archived, and as such it is read-only.
It is unknown whether this package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers




JSR Score
58%
Published
11 months ago (0.0.9)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273import { join } from "jsr:@std/path@^1.0.8"; type SetNewVersionParams = { projectDir: string; newVersion: string; newBuildNumber: number; }; type UpdateFn = (data: SetNewVersionParams) => Promise<void>; export function setNewVersion(params: SetNewVersionParams) { return Promise.all([ updatePackageJSON(params), updateAppGradle(params), updateInfoPlist(params), updateProjectPBXPROJ(params), ]); } const updatePackageJSON: UpdateFn = async ({ projectDir, newVersion }) => { const packageJsonPath = join(projectDir, "package.json"); const packageJSON = await Deno.readTextFile(packageJsonPath).then(JSON.parse); await Deno.writeTextFile( packageJsonPath, JSON.stringify({ ...packageJSON, version: newVersion }, null, 2) + "\n" ); }; const updateAppGradle: UpdateFn = async ({ projectDir, newVersion, newBuildNumber, }) => { const path = join(projectDir, "android", "app", "build.gradle"); const fileData = await Deno.readTextFile(path); const versionCodeRegex = new RegExp(/versionCode .+/gm); const versionNameRegex = new RegExp(/versionName .+/gm); const updated = fileData .replace(versionNameRegex, `versionName ${newVersion}`) .replace(versionCodeRegex, `versionCode ${newBuildNumber}`); await Deno.writeTextFile(path, updated); }; const updateInfoPlist: UpdateFn = async ({ projectDir, newVersion }) => { const path = join(projectDir, "ios", "MadisonReed", "Info.plist"); const versionRegex = new RegExp(/\d+\.\d+\.\d+/gm); const content = await Deno.readTextFile( join(projectDir, "ios", "MadisonReed", "Info.plist") ); await Deno.writeTextFile(path, content.replace(versionRegex, newVersion)); }; const updateProjectPBXPROJ: UpdateFn = async ({ projectDir, newBuildNumber, }) => { const path = join( projectDir, "ios", "MadisonReed.xcodeproj", "project.pbxproj" ); const buildNumberRegex = /CURRENT_PROJECT_VERSION\s\=\s(\d+)/gm; const content = await Deno.readTextFile(path); await Deno.writeTextFile( path, content.replaceAll( buildNumberRegex, `CURRENT_PROJECT_VERSION = ${newBuildNumber}` ) ); };