@embrace-io/react-native
Version:
A React Native wrapper for the Embrace SDK
75 lines (74 loc) • 2.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.modifyPhase = exports.findPhase = exports.updateBuildProperty = exports.addFile = void 0;
const textUtils_1 = require("./textUtils");
const buildPhaseObj = (project) => {
return project.hash.project.objects.PBXShellScriptBuildPhase || {};
};
const findPhase = (project, matcher) => {
const phases = buildPhaseObj(project);
const phaseKeys = Object.keys(phases);
for (let i = 0; i < phaseKeys.length; i++) {
const key = phaseKeys[i];
const phase = phases[key];
const code = phase.shellScript && [phase.shellScript];
if (code && (0, textUtils_1.hasMatch)(code, matcher)) {
return { key, code };
}
}
return null;
};
exports.findPhase = findPhase;
const modifyPhase = (project, phaseKey, matcher, addBefore) => {
const phase = buildPhaseObj(project)[phaseKey];
let code = JSON.parse(phase.shellScript);
code = code.replace(matcher, (match) => `${addBefore}${addBefore === "" ? "" : match}`);
phase.shellScript = JSON.stringify(code);
};
exports.modifyPhase = modifyPhase;
const addFile = (project, groupName, path, fileType) => {
const target = findHash(project.hash.project.objects.PBXNativeTarget, groupName);
const group = findHash(project.hash.project.objects.PBXGroup, groupName);
if (target && group) {
const file = project.addFile(path, group[0], { target: target[0] });
if (!file) {
return;
}
file.target = target[0];
file.uuid = project.generateUuid();
project.addToPbxBuildFileSection(file);
if (fileType === "resource") {
project.addToPbxResourcesBuildPhase(file);
}
else if (fileType === "source") {
project.addToPbxSourcesBuildPhase(file);
}
}
};
exports.addFile = addFile;
const updateBuildProperty = (project, groupName, propertyName, value) => {
const targetHash = getTargetHash(project, groupName);
const configurations = project.pbxXCBuildConfigurationSection();
const xcConfigList = project.pbxXCConfigurationList();
for (const configName in xcConfigList) {
if (configName !== targetHash) {
continue;
}
for (const item of xcConfigList[configName].buildConfigurations) {
const config = configurations[item.value];
if (config) {
config.buildSettings[propertyName] = value;
}
}
}
};
exports.updateBuildProperty = updateBuildProperty;
const getTargetHash = (project, name) => {
const target = project.pbxTargetByName(name);
return target ? target.buildConfigurationList : "";
};
const findHash = (objects, groupName) => {
return Object.entries(objects).find(([_, group]) => {
return group.name === groupName;
});
};