Skip to main content
This package has been archived, and as such it is read-only.
This release is 1 version behind 0.0.9 — the latest version of @apompolo/mr-cli. Jump to latest
It is unknown whether this package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
58%
Published
4 weeks ago (0.0.8)
Package root>setNewVersion.ts
import { 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 = new RegExp(/CURRENT_PROJECT_VERSION = \K\d+/gm); const content = await Deno.readTextFile(path); const matches = buildNumberRegex.exec(content); console.log(matches); await Deno.writeTextFile( path, content.replaceAll(buildNumberRegex, newBuildNumber.toString()) ); }; updateInfoPlist({ projectDir: "/Users/beto/Projects/mr-mobile-app", newVersion: "3.0.1", newBuildNumber: 123, });