UNPKG

react-native-integrate

Version:

Automate integration of additional code into React Native projects

71 lines (70 loc) 3.92 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.importIosProjectVersion = importIosProjectVersion; const fs_1 = __importDefault(require("fs")); const picocolors_1 = __importDefault(require("picocolors")); const xcode_1 = __importDefault(require("xcode")); const constants_1 = require("../../../constants"); const prompter_1 = require("../../../prompter"); require("../../../tasks/xcode/xcodeTask.helpers"); const getIosProjectPath_1 = require("../../getIosProjectPath"); function importIosProjectVersion(projectPath) { try { const pbxFilePath = (0, getIosProjectPath_1.getPbxProjectPath)(projectPath); const proj = xcode_1.default.project(pbxFilePath); proj.parseSync(); const nativeTarget = proj.getTarget(constants_1.Constants.XCODE_APPLICATION_TYPE); const projectVersion = proj.getBuildProperty('CURRENT_PROJECT_VERSION', 'Release', nativeTarget.target.name); if (!projectVersion) return null; const versionVariable = projectVersion.toString().match(/\$\{(.*?)}/)?.[1]; let versionVariableValue; if (versionVariable) { const buildConfigurationLists = proj.pbxXCConfigurationList(); const buildConfigurationList = buildConfigurationLists[proj.getFirstProject().firstProject.buildConfigurationList]; const buildConfigurationSection = proj.pbxXCBuildConfigurationSection(); for (const buildConfiguration of buildConfigurationList.buildConfigurations) { if (buildConfiguration.comment == 'Release') { const id = buildConfiguration.value; const buildConfig = buildConfigurationSection[id]; versionVariableValue = buildConfig.buildSettings[versionVariable]; } } } return { id: 'iosProjectVersion', title: 'Ios Project Version', value: projectVersion + (versionVariableValue ? ` (${versionVariableValue})` : ''), apply: () => setIosProjectVersion(projectVersion, versionVariable, versionVariableValue), }; } catch (_e) { return null; } } async function setIosProjectVersion(newProjectVersion, versionVariable, versionVariableValue) { const pbxFilePath = (0, getIosProjectPath_1.getPbxProjectPath)(); const proj = xcode_1.default.project(pbxFilePath); proj.parseSync(); const nativeTarget = proj.getTarget(constants_1.Constants.XCODE_APPLICATION_TYPE); proj.updateBuildPropertyByTarget('CURRENT_PROJECT_VERSION', newProjectVersion, 'Debug', nativeTarget.target); proj.updateBuildPropertyByTarget('CURRENT_PROJECT_VERSION', newProjectVersion, 'Release', nativeTarget.target); (0, prompter_1.logMessage)(`set ${picocolors_1.default.yellow('CURRENT_PROJECT_VERSION')} to ${picocolors_1.default.yellow(newProjectVersion)}`); if (versionVariable) { const buildConfigurationLists = proj.pbxXCConfigurationList(); const buildConfigurationList = buildConfigurationLists[proj.getFirstProject().firstProject.buildConfigurationList]; const buildConfigurationSection = proj.pbxXCBuildConfigurationSection(); for (const buildConfiguration of buildConfigurationList.buildConfigurations) { const id = buildConfiguration.value; const buildConfig = buildConfigurationSection[id]; buildConfig.buildSettings[versionVariable] = versionVariableValue; } (0, prompter_1.logMessage)(`set ${picocolors_1.default.yellow(versionVariable)} to ${picocolors_1.default.yellow(versionVariableValue)}`); } fs_1.default.writeFileSync(pbxFilePath, proj.writeSync(), 'utf-8'); return Promise.resolve(); }