UNPKG

react-native-integrate

Version:

Automate integration of additional code into React Native projects

48 lines (47 loc) 2.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.importIosBundleId = importIosBundleId; 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"); const xcodeTask_helpers_1 = require("../../../tasks/xcode/xcodeTask.helpers"); const getIosProjectPath_1 = require("../../getIosProjectPath"); function importIosBundleId(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); let bundleId = proj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', 'Release', nativeTarget.target.name); if (!bundleId) return null; bundleId = (0, xcodeTask_helpers_1.normalizeBundleId)(bundleId, { productName: nativeTarget.target.name, }); return { id: 'iosBundleId', title: 'Ios Bundle Id', value: bundleId, apply: () => setIosBundleId(bundleId), }; } catch (_e) { return null; } } async function setIosBundleId(newBundleId) { 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('PRODUCT_BUNDLE_IDENTIFIER', newBundleId, 'Debug', nativeTarget.target); proj.updateBuildPropertyByTarget('PRODUCT_BUNDLE_IDENTIFIER', newBundleId, 'Release', nativeTarget.target); fs_1.default.writeFileSync(pbxFilePath, proj.writeSync(), 'utf-8'); (0, prompter_1.logMessage)(`set ${picocolors_1.default.yellow('PRODUCT_BUNDLE_IDENTIFIER')} to ${picocolors_1.default.yellow(newBundleId)}`); return Promise.resolve(); }