# Version Management ## Semantic Versioning ### Version Format ``` MAJOR.MINOR.PATCH Examples: 1.0.0 - Initial release 1.0.1 - Bug fix 1.1.0 - New feature 2.0.0 - Breaking changes ``` ### Version Rules - **MAJOR**: Breaking changes, incompatible API changes - **MINOR**: New features, backward compatible - **PATCH**: Bug fixes, backward compatible ## Automated Versioning ### Package.json Version Management ```bash # Install version management tools npm install -g standard-version # Bump version automatically npm version patch # 1.0.0 -> 1.0.1 npm version minor # 1.0.0 -> 1.1.0 npm version major # 1.0.0 -> 2.0.0 # With standard-version (recommended) npx standard-version --release-as patch npx standard-version --release-as minor npx standard-version --release-as major ``` ### Cross-Platform Version Script **scripts/version-bump.js:** ```javascript #!/usr/bin/env node const fs = require('fs'); const path = require('path'); const { execSync } = require('child_process'); const versionType = process.argv[2] || 'patch'; const packageJsonPath = path.join(__dirname, '../package.json'); const androidBuildGradle = path.join(__dirname, '../android/app/build.gradle'); const iosPlistPath = path.join(__dirname, '../ios/SaayamApp/Info.plist'); // Read current version from package.json const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); const currentVersion = packageJson.version; console.log(`Current version: ${currentVersion}`); // Bump version in package.json execSync(`npm version ${versionType} --no-git-tag-version`, { stdio: 'inherit' }); // Read new version const updatedPackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); const newVersion = updatedPackageJson.version; console.log(`New version: ${newVersion}`); // Update Android version updateAndroidVersion(newVersion); // Update iOS version updateiOSVersion(newVersion); // Create git commit and tag execSync(`git add .`, { stdio: 'inherit' }); execSync(`git commit -m "chore: bump version to ${newVersion}"`, { stdio: 'inherit' }); execSync(`git tag -a v${newVersion} -m "Release version ${newVersion}"`, { stdio: 'inherit' }); console.log(`Version bumped to ${newVersion} successfully!`); function updateAndroidVersion(version) { let buildGradleContent = fs.readFileSync(androidBuildGradle, 'utf8'); // Update versionName buildGradleContent = buildGradleContent.replace( /versionName\s+"[^"]*"/, `versionName "${version}"` ); // Update versionCode (increment by 1) const versionCodeMatch = buildGradleContent.match(/versionCode\s+(\d+)/); if (versionCodeMatch) { const currentVersionCode = parseInt(versionCodeMatch[1]); const newVersionCode = currentVersionCode + 1; buildGradleContent = buildGradleContent.replace( /versionCode\s+\d+/, `versionCode ${newVersionCode}` ); console.log(`Android versionCode updated to: ${newVersionCode}`); } fs.writeFileSync(androidBuildGradle, buildGradleContent); console.log(`Android versionName updated to: ${version}`); } function updateiOSVersion(version) { try { // Update CFBundleShortVersionString execSync(`/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${version}" "${iosPlistPath}"`, { stdio: 'inherit' }); // Get current build number and increment const currentBuild = execSync(`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${iosPlistPath}"`, { encoding: 'utf8' }).trim(); const newBuild = parseInt(currentBuild) + 1; // Update CFBundleVersion execSync(`/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${newBuild}" "${iosPlistPath}"`, { stdio: 'inherit' }); console.log(`iOS version updated to: ${version} (${newBuild})`); } catch (error) { console.error('Error updating iOS version:', error.message); } } ``` ### Make Script Executable ```bash chmod +x scripts/version-bump.js ``` ### Usage ```bash # Bump patch version ./scripts/version-bump.js patch # Bump minor version ./scripts/version-bump.js minor # Bump major version ./scripts/version-bump.js major ``` ## Changelog Management ### Conventional Commits ```bash # Install commitizen for conventional commits npm install -g commitizen cz-conventional-changelog # Configure commitizen echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc # Use commitizen for commits git cz ``` ### Commit Message Format ``` ():