UNPKG

react-native-integrate

Version:

Automate integration of additional code into React Native projects

66 lines (65 loc) 3.1 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.applySetDeploymentVersion = applySetDeploymentVersion; const picocolors_1 = __importDefault(require("picocolors")); const constants_1 = require("../../constants"); const prompter_1 = require("../../prompter"); const getDeploymentVersion_1 = require("../../utils/getDeploymentVersion"); const variables_1 = require("../../variables"); function applySetDeploymentVersion(content, action) { let { target } = action; target = (0, variables_1.getText)(target); const nativeTarget = content.getTarget(constants_1.Constants.XCODE_APPLICATION_TYPE); let projTarget; let logTarget; switch (target) { case 'root': projTarget = content.getFirstProject().firstProject; logTarget = 'project root'; break; case 'main': projTarget = nativeTarget.target; logTarget = `${nativeTarget.target.name} target`; break; default: projTarget = content.pbxTargetByName(target) || content.pbxTargetByName(`"${target}"`); logTarget = `${target} target`; break; } const minVersion = isNumberOrText(action.setDeploymentVersion) ? getVersionFromText(action.setDeploymentVersion) : getVersionFromText(action.setDeploymentVersion.min); // get current version from target let currentVersion = +(content.getBuildPropertyByTarget('IPHONEOS_DEPLOYMENT_TARGET', 'Release', projTarget) || 0); // get version from main/root target if (currentVersion == 0) { const versionData = (0, getDeploymentVersion_1.getIosDeploymentVersionFromXcodeProject)(content); currentVersion = +versionData.version; // write to root target if current target has no version if (versionData.target == 'root') projTarget = content.getFirstProject().firstProject; } const maxVersion = isNumberOrText(action.setDeploymentVersion) ? getVersionFromText(action.setDeploymentVersion) : getVersionFromText(action.setDeploymentVersion.max || Infinity); const newVersion = Math.min(Math.max(currentVersion, minVersion), maxVersion).toFixed(1); // should write back to root target content.updateBuildPropertyByTarget('IPHONEOS_DEPLOYMENT_TARGET', `${newVersion}`, 'Debug', projTarget); content.updateBuildPropertyByTarget('IPHONEOS_DEPLOYMENT_TARGET', `${newVersion}`, 'Release', projTarget); (0, prompter_1.logMessage)(`set deployment version to ${picocolors_1.default.yellow(newVersion)} in ${picocolors_1.default.yellow(logTarget)}`); return content; } function isNumberOrText(value) { const typeofValue = typeof value; return typeofValue == 'string' || typeofValue == 'number'; } function getVersionFromText(value) { if (typeof value == 'number') return value; return +(0, variables_1.getText)(value); }