Skip to content

Commit

Permalink
Merge pull request #2171 from IDEMSInternational/hotfix/yarn-scripts-…
Browse files Browse the repository at this point in the history
…version

hotfix: yarn scripts version also updates strings targeted by android build action
  • Loading branch information
esmeetewinkel authored Jan 30, 2024
2 parents ed09cf0 + af95ca2 commit 5e37117
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/scripts/src/commands/version.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "fs-extra";
import { Command } from "commander";
import inquirer from "inquirer";
import { APP_BUILD_GRADLE_PATH, MAIN_PACKAGE_PATH } from "../paths";
import { APP_BUILD_GRADLE_PATH, MAIN_PACKAGE_PATH, ANDROID_BUILD_ACTION_PATH } from "../paths";

/***************************************************************************************
* CLI
Expand All @@ -26,6 +26,7 @@ async function version(options: IProgramOptions) {
const newVersion = await promptNewVersion(oldVersion);
updatePackageJson(newVersion);
updateGradleBuild(newVersion);
updateAndroidBuildAction(newVersion);
}

function updateGradleBuild(newVersionName: string) {
Expand All @@ -47,6 +48,20 @@ async function updatePackageJson(newVersion: string) {
fs.writeJSONSync(MAIN_PACKAGE_PATH, packageJson, { spaces: 2 });
}

function updateAndroidBuildAction(newVersionName) {
let androidBuildAction = fs.readFileSync(ANDROID_BUILD_ACTION_PATH, { encoding: "utf-8" });
const newVersionCode = _generateVersionCode(newVersionName);
androidBuildAction = androidBuildAction.replace(
/[0-9]+\/\$VERSION_CODE\//g,
`${newVersionCode}/$VERSION_CODE/`
);
androidBuildAction = androidBuildAction.replace(
/[0-9]+\.[0-9]+\.[0-9]+\/\$VERSION\//g,
`${newVersionName}/$VERSION/`
);
fs.writeFileSync(ANDROID_BUILD_ACTION_PATH, androidBuildAction, { encoding: "utf-8" });
}

async function promptNewVersion(currentVersion: string) {
const { version } = await inquirer.prompt([
{
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ export const RESOURCE_FOLDER_PATH = path.join(ROOT_DIR, "resources");

export const ANDROID_RES_PATH = path.join(ROOT_DIR, "android/app/src/main/res");
export const APP_BUILD_GRADLE_PATH = path.join(ROOT_DIR, "android/app/build.gradle");
export const ANDROID_BUILD_ACTION_PATH = path.join(
ROOT_DIR,
".github/workflows/reusable-android-build.yml"
);

0 comments on commit 5e37117

Please sign in to comment.