UNPKG

rn-version-sync

Version:

Fast and simple utility to sync React Native version with native code

99 lines 3.86 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.updateIOSVersion = updateIOSVersion; const fs = __importStar(require("fs")); const path = __importStar(require("path")); /** * Find project.pbxproj file in iOS directory */ function findPbxproj(projectRoot) { const iosDir = path.join(projectRoot, 'ios'); if (!fs.existsSync(iosDir)) { return null; } // Look for .xcodeproj directories const entries = fs.readdirSync(iosDir, { withFileTypes: true }); for (const entry of entries) { if (entry.isDirectory() && entry.name.endsWith('.xcodeproj')) { const pbxprojPath = path.join(iosDir, entry.name, 'project.pbxproj'); if (fs.existsSync(pbxprojPath)) { return pbxprojPath; } } } return null; } /** * Update iOS project.pbxproj with new version name and version code */ function updateIOSVersion(projectRoot, versionName, versionCode, verbose) { const pbxprojPath = findPbxproj(projectRoot); if (!pbxprojPath) { if (verbose) console.log('Skipping iOS: project.pbxproj not found'); return; } let content = fs.readFileSync(pbxprojPath, 'utf8'); let modified = false; // Update MARKETING_VERSION (corresponds to CFBundleShortVersionString - version name) const marketingVersionRegex = /(MARKETING_VERSION\s*=\s*)([^;]+)(;)/g; if (marketingVersionRegex.test(content)) { const newContent = content.replace(marketingVersionRegex, `$1${versionName}$3`); if (newContent !== content) { content = newContent; modified = true; if (verbose) console.log(`Updated MARKETING_VERSION to ${versionName}`); } } // Update CURRENT_PROJECT_VERSION (corresponds to CFBundleVersion - version code) const currentProjectVersionRegex = /(CURRENT_PROJECT_VERSION\s*=\s*)([^;]+)(;)/g; if (currentProjectVersionRegex.test(content)) { const newContent = content.replace(currentProjectVersionRegex, `$1${versionCode}$3`); if (newContent !== content) { content = newContent; modified = true; if (verbose) console.log(`Updated CURRENT_PROJECT_VERSION to ${versionCode}`); } } if (modified) { fs.writeFileSync(pbxprojPath, content, 'utf8'); if (verbose) console.log(`Updated ${pbxprojPath}`); } } //# sourceMappingURL=ios.js.map