Skip to content

Instantly share code, notes, and snippets.

@flexbox
Last active December 15, 2023 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flexbox/df75b62aae9154824e050c6b17229f50 to your computer and use it in GitHub Desktop.
Save flexbox/df75b62aae9154824e050c6b17229f50 to your computer and use it in GitHub Desktop.
numb version React Native expo usage in package.json `"release": "node bin/bump-app-version.js && bin/release",`
/* eslint-disable prefer-destructuring */
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require("fs");
// Read the contents of the app.config.ts file
fs.readFile("app.config.ts", "utf8", (err, data) => {
if (err) {
throw err;
}
// Get the current values for the keys
const currentVersion = data.match(/version: "(\d+\.\d+\.\d+)"/)[1];
const currentBuildNumber = data.match(/buildNumber: "(\d+)"/)[1];
const currentVersionCode = data.match(/versionCode: (\d+)/)[1];
// Increment the values
const newVersion = incrementVersion(currentVersion);
const newBuildNumber = incrementBuildNumber(currentBuildNumber);
const newVersionCode = incrementVersionCode(currentVersionCode);
// Replace the existing values with the new values
data = data.replace(/version: "(\d+\.\d+\.\d+)"/, `version: "${newVersion}"`);
data = data.replace(
/buildNumber: "(\d+)"/,
`buildNumber: "${newBuildNumber}"`,
);
data = data.replace(/versionCode: (\d+)/, `versionCode: ${newVersionCode}`);
// Write the updated contents back to the app.config.ts file
fs.writeFile("app.config.ts", data, "utf8", (error) => {
if (error) {
throw error;
}
console.log("✅ app.config.ts file has been updated successfully!\n");
});
});
// function to increment version
function incrementVersion(version) {
const versionArr = version.split(".");
versionArr[2] = (parseInt(versionArr[2], 10) + 1).toString();
return versionArr.join(".");
}
// function to increment build number
function incrementBuildNumber(buildNumber) {
return (parseInt(buildNumber, 10) + 1).toString();
}
// function to increment version code
function incrementVersionCode(versionCode) {
return parseInt(versionCode, 10) + 1;
}
#!/bin/sh
echo 'EAS username you are logged in as'
eas whoami
echo ''
read -p "=> Starting the release: when ready, press [ENTER]"
# on macOS you can use `ggrep` instead of `grep` to use the GNU version
next_version=$(ggrep -oP 'version:\s*"\K[^"]+' app.config.ts)
echo ''
echo '==============================='
echo "🔭 Creating tag $next_version "
echo '==============================='
echo ''
git tag -a $next_version -m "chore: 🤖 release $next_version"
echo '==============================='
echo "🔑 Build using 'production' profile"
echo '==============================='
echo ''
eas build --auto-submit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment