react-native-integrate
Version:
Automate integration of additional code into React Native projects
63 lines (62 loc) • 2.88 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.importIosBuildProperties = importIosBuildProperties;
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 importIosBuildProperties(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 propertyNames = ['DEVELOPMENT_TEAM', 'TARGETED_DEVICE_FAMILY'];
const buildProperties = [];
for (const propertyName of propertyNames) {
const debugProperty = proj.getBuildProperty(propertyName, 'Debug', nativeTarget.target.name);
if (debugProperty)
buildProperties.push({
name: propertyName,
value: debugProperty,
type: 'Debug',
});
const releaseProperty = proj.getBuildProperty(propertyName, 'Release', nativeTarget.target.name);
if (releaseProperty)
buildProperties.push({
name: propertyName,
value: releaseProperty,
type: 'Release',
});
}
if (!buildProperties.length)
return null;
return {
id: 'iosBuildProperties',
title: 'Ios Build Properties',
value: buildProperties.length + ' properties',
apply: () => setIosBuildProperties(buildProperties),
};
}
catch (_e) {
return null;
}
}
async function setIosBuildProperties(buildProperties) {
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);
for (const buildProperty of buildProperties) {
proj.updateBuildPropertyByTarget(buildProperty.name, buildProperty.value, buildProperty.type, nativeTarget.target);
(0, prompter_1.logMessage)(`set ${picocolors_1.default.yellow(buildProperty.name)} (${buildProperty.type}) to ${picocolors_1.default.yellow(buildProperty.value)}`);
}
fs_1.default.writeFileSync(pbxFilePath, proj.writeSync(), 'utf-8');
return Promise.resolve();
}