react-native-payments-cli
Version:
## Installation First, install [Carthage](https://github.com/Carthage/Carthage) (if you don't already have it installed):
104 lines (85 loc) • 3.41 kB
JavaScript
function filterOutCommentKeys(key) {
return !key.endsWith('_comment');
}
function addFrameworks(project, frameworkDirPath, frameworkFileNames = []) {
// Add frameworks pbx
project.addPbxGroup(
[],
'Frameworks',
frameworkDirPath
);
frameworkFileNames.forEach(frameworkFileName => {
project.addFramework(`${frameworkDirPath}/${frameworkFileName}`)
});
}
function addPathsToBuildScriptPhase(project, buildPhaseName, inputPaths, outputPaths) {
const buildScriptPhases = project.hash.project.objects['PBXShellScriptBuildPhase'] || {};
Object.keys(buildScriptPhases)
.forEach(buildPhaseKey => {
const buildScriptPhase = buildScriptPhases[buildPhaseKey];
if (buildScriptPhase.name === `"${buildPhaseName}"`) {
const newInputPaths = inputPaths
.filter(inputPath => !buildScriptPhase.inputPaths.includes(inputPath))
const newOutputPaths = outputPaths
.filter(outputPath => !buildScriptPhase.outputPaths.includes(outputPath))
buildScriptPhase.inputPaths = [...buildScriptPhase.inputPaths, ...newInputPaths];
buildScriptPhase.outputPaths = [...buildScriptPhase.outputPaths, ...newOutputPaths];
}
});
}
function buildScriptPhaseExists(project, name) {
const buildScriptPhases = project.hash.project.objects['PBXShellScriptBuildPhase'] || {};
return Object.keys(buildScriptPhases)
.reduce((acc, buildScriptPhaseKey) => {
if (!acc) {
return buildScriptPhases[buildScriptPhaseKey].name === `"${name}"`
}
return acc;
}, false);
}
function addCarthageRunScriptPhase(project, inputPaths, outputPaths) {
const buildPhaseName = 'Copy Carthage Frameworks (Generated by react-native-payments-cli)';
const buildScriptPhases = project.hash.project.objects['PBXShellScriptBuildPhase'] || {};
if (buildScriptPhaseExists(project, buildPhaseName)) {
addPathsToBuildScriptPhase(project, buildPhaseName, inputPaths, outputPaths);
return;
}
project.addBuildPhase(
[],
'PBXShellScriptBuildPhase',
buildPhaseName,
undefined,
{
shellPath: '/bin/sh',
shellScript: '/usr/local/bin/carthage copy-frameworks',
inputPaths,
outputPaths
}
);
}
function addFrameworkSearchPaths(project, filePaths) {
const config = project.pbxXCBuildConfigurationSection();
Object.keys(config)
.filter(filterOutCommentKeys)
.forEach(key => {
const buildSettings = config[key].buildSettings;
const hasFrameworkSearchPaths = buildSettings.hasOwnProperty('FRAMEWORK_SEARCH_PATHS');
// If there's only one path, the frameworkSearchPaths is a string, so we
// normalize it here.
const frameworkSearchPaths = buildSettings.FRAMEWORK_SEARCH_PATHS || [];
const normalizedFrameworkSearchPaths = Array.isArray(frameworkSearchPaths)
? frameworkSearchPaths
: [frameworkSearchPaths];
const pathsToAdd = filePaths
.filter(filePath => !normalizedFrameworkSearchPaths.includes(filePath));
const nextFrameworkSearchPaths = [...normalizedFrameworkSearchPaths, ...pathsToAdd];
buildSettings.FRAMEWORK_SEARCH_PATHS = nextFrameworkSearchPaths.length > 1
? nextFrameworkSearchPaths
: nextFrameworkSearchPaths.join('');
});
}
module.exports = {
addFrameworks,
addFrameworkSearchPaths,
addCarthageRunScriptPhase
};