mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-12 22:39:06 +08:00
Summary: The core React Native codebase already has full support for CocoaPods. However, `react-native link` doesn’t play nicely with CocoaPods, so installing third-party libs from the RN ecosystem is really hard. This change will allow to link projects that contains its own `.podspec` file to CocoaPods-based projects. In case `link` detect `Podfile` in `iOS` directory, it will look for related `.podspec` file in linked project directory, and add it to `Podfile`. If `Podfile` and `.podspec` files are not present, it will fall back to previous implementation. **Test Plan** 1. Build a React Native project where the iOS part uses CocoaPods to manage its dependencies. The most common scenario here is to have React Native be a Pod dependency, among others. 2. Install a RN-related library, that contains `.podspec` file, with `react-native link` (as an example it could be: [react-native-maps](https://github.com/airbnb/react-native-maps) 3. Building the resulting iOS workspace should succeed (and there should be new entry in `Podfile`) Closes https://github.com/facebook/react-native/pull/15460 Differential Revision: D6078649 Pulled By: hramos fbshipit-source-id: 9651085875892fd66299563ca0e42fb2bcc00825
26 lines
1.0 KiB
JavaScript
26 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
const readPodfile = require('./readPodfile');
|
|
const findPodTargetLine = require('./findPodTargetLine');
|
|
const findLineToAddPod = require('./findLineToAddPod');
|
|
const findMarkedLinesInPodfile = require('./findMarkedLinesInPodfile');
|
|
const addPodEntry = require('./addPodEntry');
|
|
const savePodFile = require('./savePodFile');
|
|
|
|
module.exports = function registerNativeModulePods(dependency, iOSProject) {
|
|
const podLines = readPodfile(iOSProject.podfile);
|
|
const linesToAddEntry = getLinesToAddEntry(podLines, iOSProject);
|
|
addPodEntry(podLines, linesToAddEntry, dependency.config.ios.podspec, dependency.name);
|
|
savePodFile(iOSProject.podfile, podLines);
|
|
};
|
|
|
|
function getLinesToAddEntry(podLines, { projectName }) {
|
|
const linesToAddPodWithMarker = findMarkedLinesInPodfile(podLines);
|
|
if (linesToAddPodWithMarker.length > 0) {
|
|
return linesToAddPodWithMarker;
|
|
} else {
|
|
const firstTargetLined = findPodTargetLine(podLines, projectName);
|
|
return findLineToAddPod(podLines, firstTargetLined);
|
|
}
|
|
}
|