├── .gitignore ├── .gitattributes ├── lib ├── readPodfile.js ├── savePodFile.js ├── getProject.js ├── getProjectDependencies.js ├── registerNativeModule.js ├── checkForPod.js ├── saveProject.js ├── findMarkedLinesInPodfile.js ├── removePodEntry.js ├── unregisterNativeModule.js ├── findPodTargetLine.js ├── fixPods.js ├── isInstalled.js ├── addPod.js ├── getIOSProject.js ├── removePod.js ├── registerPodsFromPackage.js ├── findLineToAddPod.js ├── addPodEntry.js └── registerPod.js ├── bin ├── preinstall.js ├── cli.js ├── postlink.js └── makepod.js ├── rnplugin ├── installpods.js └── index.js ├── package.json ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | node_modules/* 3 | yarn.lock 4 | .watchmanconfig 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /lib/readPodfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | 5 | module.exports = function readPodfile(podfilePath) { 6 | const podContent = fs.readFileSync(podfilePath, 'utf8'); 7 | return podContent.split(/\r?\n/g); 8 | }; 9 | -------------------------------------------------------------------------------- /lib/savePodFile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | 5 | module.exports = function savePodFile(podfilePath, podLines) { 6 | const newPodfile = podLines.join('\n'); 7 | fs.writeFileSync(podfilePath, newPodfile); 8 | }; 9 | -------------------------------------------------------------------------------- /lib/getProject.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const process = require("process"); 3 | module.exports = () => { 4 | const projpath = process.cwd(); 5 | const packagepath = projpath + "/package.json"; 6 | const pkg = require(packagepath); 7 | return pkg; 8 | }; 9 | -------------------------------------------------------------------------------- /lib/getProjectDependencies.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const process = require("process"); 3 | const getProject = require("./getProject"); 4 | module.exports = () => { 5 | const pkg = getProject(); 6 | const dependencies = Object.keys(pkg.dependencies); 7 | return dependencies; 8 | }; 9 | -------------------------------------------------------------------------------- /lib/registerNativeModule.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const registerPod = require('./registerPod'); 3 | module.exports = function registerNativeModulePods(dependency, iOSProject) { 4 | const pod = {pod: dependency.config.ios.podspec, path: "../node_modules/" + dependency.name} 5 | return registerPod(pod, iOSProject); 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /lib/checkForPod.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const fs = require("fs") 3 | module.exports = (podName, podFilePath) => { 4 | const podFileContent = fs.readFileSync(podFilePath, "utf8"); 5 | const podRegex = new RegExp("\\n( |\\t)*pod\\s+(\"|')" + podName + "(\"|')(,\\s*(:[a-z]+\\s*=>)?\\s*((\"|').*?(\"|')|\\[[\\s\\S]*?\\]))*\\n", 'g'); 6 | return podRegex.test(podFileContent); 7 | } -------------------------------------------------------------------------------- /lib/saveProject.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const process = require("process"); 3 | const fs = require("fs"); 4 | module.exports = projectobj => { 5 | const projpath = process.cwd(); 6 | const packagepath = projpath + "/package.json"; 7 | fs.writeFileSync(packagepath, JSON.stringify(projectobj, null, 2)); 8 | const pkg = require(packagepath); 9 | return pkg; 10 | }; 11 | -------------------------------------------------------------------------------- /lib/findMarkedLinesInPodfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const MARKER_TEXT = '# Add new pods below this line'; 3 | 4 | module.exports = function findMarkedLinesInPodfile(podLines) { 5 | const result = []; 6 | for (let i = 0, len = podLines.length; i < len; i++) { 7 | if (podLines[i].includes(MARKER_TEXT)) { 8 | result.push({ line: i + 1, indentation: podLines[i].indexOf('#') }); 9 | } 10 | } 11 | return result; 12 | }; 13 | -------------------------------------------------------------------------------- /bin/preinstall.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const execSync = require("child_process").execSync; 3 | try { 4 | const out = execSync("which pod"); 5 | if (!out) { 6 | console.warn( 7 | "This package requires cocoapods to be installed on this machine. try running:\n\n\tgem install cocoapods\n\n" 8 | ); 9 | // exit(1); 10 | } 11 | } catch (e) { 12 | console.warn("Could not run which test - possible CI/CD environment"); 13 | } 14 | -------------------------------------------------------------------------------- /lib/removePodEntry.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function removePodEntry(podfileContent, podName) { 4 | // this regex should catch line(s) with full pod definition, like: pod 'podname', :path => '../node_modules/podname', :subspecs => ['Sub2', 'Sub1'] 5 | const podRegex = new RegExp("\\n( |\\t)*pod\\s+(\"|')" + podName + "(\"|')(,\\s*(:[a-z]+\\s*=>)?\\s*((\"|').*?(\"|')|\\[[\\s\\S]*?\\]))*\\n", 'g'); 6 | return podfileContent.replace(podRegex, '\n'); 7 | }; 8 | -------------------------------------------------------------------------------- /lib/unregisterNativeModule.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const removePodEntry = require('./removePodEntry'); 5 | 6 | /** 7 | * Unregister native module IOS with CocoaPods 8 | */ 9 | module.exports = function unregisterNativeModule(dependencyConfig, iOSProject) { 10 | const podContent = fs.readFileSync(iOSProject.podfile, 'utf8'); 11 | const removed = removePodEntry(podContent, dependencyConfig.podspec); 12 | fs.writeFileSync(iOSProject.podfile, removed); 13 | }; 14 | -------------------------------------------------------------------------------- /rnplugin/installpods.js: -------------------------------------------------------------------------------- 1 | const process = require("process"); 2 | const fs = require("fs"); 3 | var path = require("path"); 4 | var { spawnSync } = require("child_process"); 5 | const opts = { 6 | encoding: "utf8", 7 | stdio: "inherit" 8 | }; 9 | module.exports = (config, args) => { 10 | const makepodPath = path.join(__dirname, "..", "bin", "makepod.js"); 11 | spawnSync(makepodPath, [], opts); 12 | const postlinkPath = path.join(__dirname, "..", "bin", "postlink.js"); 13 | spawnSync(postlinkPath, [], opts); 14 | }; 15 | -------------------------------------------------------------------------------- /lib/findPodTargetLine.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function findPodTargetLine(podLines, projectName) { 4 | const targetName = projectName.replace('.xcodeproj', ''); 5 | //match first target definition in file: target 'target_name' do 6 | const targetRegex = new RegExp('target (\'|\")' + targetName + '(\'|\") do', 'g'); 7 | for (let i = 0, len = podLines.length; i < len; i++) { 8 | const match = podLines[i].match(targetRegex); 9 | if (match) { 10 | return i + 1; 11 | } 12 | } 13 | return null; 14 | }; 15 | -------------------------------------------------------------------------------- /bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const commander = require("commander"); 3 | const addPod = require("../lib/addPod"); 4 | const removePod = require("../lib/removePod"); 5 | commander 6 | .command("addpod ") 7 | .description("Add the named pod to the current package.json file") 8 | .option("--podversion [version]", "version directive") 9 | .option("--podgit [giturl]", "Git (usually github) source URL") 10 | .action((a, b, c) => { 11 | return addPod(a, c, b); 12 | }); 13 | commander 14 | .command("removepod ") 15 | .description("Remove the named pod from the current package.json file") 16 | .action(removePod); 17 | commander.parse(process.argv); 18 | -------------------------------------------------------------------------------- /lib/fixPods.js: -------------------------------------------------------------------------------- 1 | const xcode = require("@raydeck/xcode"); 2 | const getIOSProject = require("./getIOSProject"); 3 | const glob = require("glob"); 4 | const Path = require("path"); 5 | const fs = require("fs"); 6 | module.exports = () => { 7 | const ip = getIOSProject(); 8 | const baseDir = Path.dirname(ip.podfile); 9 | const g = Path.join(baseDir, "**", "project.pbxproj"); 10 | glob.sync(g).forEach(path => { 11 | console.log("Found pbxproj file at ", path); 12 | const project = xcode.project(path); 13 | project.parseSync(); 14 | project.addBuildProperty("ENABLE_BITCODE", "NO"); 15 | const out = project.writeSync(); 16 | fs.writeFileSync(path, out); 17 | }); 18 | }; 19 | -------------------------------------------------------------------------------- /lib/isInstalled.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const readPodfile = require('./readPodfile'); 4 | 5 | module.exports = function isInstalled(iOSProject, dependencyConfig) { 6 | if (!iOSProject.podfile) { 7 | return false; 8 | } 9 | // match line with pod declaration: pod 'dependencyPodName' (other possible parameters of pod are ignored) 10 | const dependencyRegExp = new RegExp('pod\\s+(\'|\")' + dependencyConfig.podspec + '(\'|\")', 'g'); 11 | const podLines = readPodfile(iOSProject.podfile); 12 | for (let i = 0, len = podLines.length; i < len; i++) { 13 | const match = podLines[i].match(dependencyRegExp); 14 | if (match) { 15 | return true; 16 | } 17 | } 18 | return false; 19 | }; 20 | -------------------------------------------------------------------------------- /lib/addPod.js: -------------------------------------------------------------------------------- 1 | const getProject = require("./getProject"); 2 | const saveProject = require("./saveProject"); 3 | 4 | module.exports = (podname, obj, args) => { 5 | if (typeof podname !== "string") podname = podname[0]; 6 | podinfo = { pod: podname }; 7 | if (args) { 8 | const { podversion: version, podgit: git, podspec: spec } = args; 9 | podinfo = { ...podinfo, version, git, spec }; 10 | } 11 | if (podinfo) { 12 | var p = getProject(); 13 | if (!p.pods) p.pods = {}; 14 | p.pods[podname] = podinfo; 15 | saveProject(p); 16 | console.log( 17 | "Run react-native link to finish installing the pod to your project" 18 | ); 19 | } else { 20 | console.log("Could not add pod with arguments", options); 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /lib/getIOSProject.js: -------------------------------------------------------------------------------- 1 | var pbxproj = require("@raydeck/xcode"); 2 | var fs = require("fs"); 3 | var path = require("path"); 4 | var glob = require("glob"); 5 | var process = require("process"); 6 | module.exports = () => { 7 | //Get my directory 8 | const thisPath = process.cwd(); 9 | const iosPath = thisPath + "/ios"; 10 | if (!fs.existsSync(iosPath)) { 11 | console.log("Could not find ios in ", thisPath, iosPath); 12 | console.log(fs.readdirSync(thisPath)); 13 | return false; 14 | } 15 | const podPath = iosPath + "/Podfile"; 16 | if (!fs.existsSync(podPath)) { 17 | console.log("Could not find a podfile at path", podPath); 18 | return false; 19 | } 20 | const package = require(thisPath + "/package.json"); 21 | 22 | return { 23 | projectName: package.name, 24 | podfile: podPath 25 | }; 26 | }; 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-pod", 3 | "version": "1.12.1", 4 | "description": "Automatically generate podfile for React Native", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "preinstall": "./bin/preinstall.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/rhdeck/react-native-pod" 12 | }, 13 | "author": "Ray Deck", 14 | "license": "MIT", 15 | "dependencies": { 16 | "@raydeck/xcode": "^2.2.1", 17 | "commander": "^2.14.1", 18 | "glob": "^7.1.2" 19 | }, 20 | "rnpm": { 21 | "plugin": "rnplugin", 22 | "commands": { 23 | "prelink": "node node_modules/react-native-pod/bin/makepod.js", 24 | "postlink": "node node_modules/react-native-pod/bin/postlink.js" 25 | } 26 | }, 27 | "bin": { 28 | "react-native-pod": "./bin/cli.js" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/removePod.js: -------------------------------------------------------------------------------- 1 | const removePodEntry = require("./removePodEntry"); 2 | const readPodfile = require("./readPodfile"); 3 | const savePodFile = require("./savePodFile"); 4 | const getProject = require("./getProject"); 5 | const saveProject = require("./saveProject"); 6 | const getIOSProject = require("./getIOSProject"); 7 | const fs = require("fs"); 8 | 9 | module.exports = podName => { 10 | if (!podName) { 11 | console.log("You need to specify a pod to remove"); 12 | return; 13 | } 14 | var p = getProject(); 15 | if (p && p.pods) { 16 | delete p.pods[podName]; 17 | if (Object.keys(p).length == 0) { 18 | delete p.pods; 19 | } 20 | saveProject(p); 21 | } 22 | try { 23 | const iOSProject = getIOSProject(); 24 | var podContent = fs.readFileSync(iOSProject.podfile, { encoding: "utf8" }); 25 | podContent = removePodEntry(podContent, podName); 26 | fs.writeFileSync(iOSProject.podfile, podContent); 27 | } catch (e) {} 28 | }; 29 | -------------------------------------------------------------------------------- /lib/registerPodsFromPackage.js: -------------------------------------------------------------------------------- 1 | const registerPod = require("./registerPod"); 2 | const checkForPod = require("./checkForPod"); 3 | const getIOSProject = require("./getIOSProject"); 4 | module.exports = package => { 5 | if (!package || !package.pods) { 6 | return; 7 | } 8 | Object.keys(package.pods).map(podname => { 9 | var podinfo = package.pods[podname]; 10 | if (!podinfo || podinfo == "*" || podinfo == podname) { 11 | podinfo = { pod: podname }; 12 | } else if (typeof podinfo === "string") { 13 | if (podinfo.indexOf("git") > -1) { 14 | podinfo = { 15 | pod: podname, 16 | git: podinfo 17 | }; 18 | } else { 19 | //Assume a version directive 20 | podinfo = { 21 | pod: podname, 22 | version: podinfo 23 | }; 24 | } 25 | } else if (!podinfo.pod) { 26 | { 27 | podinfo.pod = podname; 28 | } 29 | } 30 | const iOSProject = getIOSProject(); 31 | if (!checkForPod(podinfo.pod, iOSProject.podfile)) { 32 | registerPod(podinfo, iOSProject); 33 | } 34 | }); 35 | }; 36 | -------------------------------------------------------------------------------- /rnplugin/index.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | { 3 | name: "addpod [pod]", 4 | description: "Add specified pod", 5 | options: [ 6 | { 7 | command: "--podversion [version]", 8 | description: "version directive" 9 | }, 10 | { 11 | command: "--podgit [giturl]", 12 | description: "Git (usually github) source URL" 13 | }, 14 | { 15 | command: "--podspec ", 16 | description: "Podspec for full path/url pointer" 17 | } 18 | ], 19 | func: require("../lib/addPod.js") 20 | }, 21 | { 22 | name: "removepod [pod]", 23 | description: "Remove specified pod", 24 | func: require("../lib/removePod.js") 25 | }, 26 | 27 | { 28 | name: "installpods", 29 | func: require("./installpods.js"), 30 | description: 31 | "Install all pods specified in the podfile. (Happens automatically at react-native link)" 32 | }, 33 | { 34 | name: "fixpods", 35 | func: require("../lib/fixPods"), 36 | description: 37 | "Disable bitcode build in pod, can be important for swift-based projects" 38 | } 39 | ]; 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Ray Deck 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /lib/findLineToAddPod.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function findLineToAddPod(podLines, firstTargetLine) { 4 | // match line with new target: target 'project_name' do (most likely target inside podfile main target) 5 | const nextTarget = /target (\'|\")\w+(\'|\") do/g; 6 | // match line that has only 'end' (if we don't catch new target or function, this would mean this is end of current target) 7 | const endOfCurrentTarget = /^\s*end\s*$/g; 8 | // match function definition, like: post_install do |installer| (some Podfiles have function defined inside main target 9 | const functionDefinition = /^\s*[a-z_]+\s+do(\s+\|[a-z]+\|)?/g; 10 | 11 | for (let i = firstTargetLine, len = podLines.length; i < len; i++) { 12 | const matchNextConstruct = podLines[i].match(nextTarget) || podLines[i].match(functionDefinition); 13 | const matchEnd = podLines[i].match(endOfCurrentTarget); 14 | 15 | if (matchNextConstruct || matchEnd) { 16 | const firstNonSpaceCharacter = podLines[i].search(/\S/); 17 | return { 18 | indentation: firstNonSpaceCharacter + (matchEnd ? 2 : 0), 19 | line: i 20 | }; 21 | } 22 | } 23 | return null; 24 | }; 25 | -------------------------------------------------------------------------------- /lib/addPodEntry.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | module.exports = function addPodEntry(podLines, linesToAddEntry, podInfo) { 4 | if (typeof podInfo == "string") { 5 | podInfo = { pod: podInfo }; 6 | } 7 | var entryParts = ["pod '" + podInfo.pod + "'"]; 8 | if (podInfo.path) { 9 | entryParts.push(":path => '" + podInfo.path + "'"); 10 | } 11 | if (podInfo.version) { 12 | entryParts.push("'" + podInfo.version + "'"); 13 | } 14 | if (podInfo.git) { 15 | entryParts.push(":git => " + "'" + podInfo.git + "'"); 16 | } 17 | if (podInfo.spec) { 18 | entryParts.push("podspec: '" + podInfo.spec + "'"); 19 | } 20 | var newEntry = entryParts.join(", ") + "\n"; 21 | 22 | if (!linesToAddEntry) { 23 | return; 24 | } else if (Array.isArray(linesToAddEntry)) { 25 | linesToAddEntry.map(({ line, indentation }, idx) => 26 | podLines.splice(line + idx, 0, getLineToAdd(newEntry, indentation)) 27 | ); 28 | } else { 29 | const { line, indentation } = linesToAddEntry; 30 | podLines.splice(line, 0, getLineToAdd(newEntry, indentation)); 31 | } 32 | }; 33 | 34 | function getLineToAdd(newEntry, indentation) { 35 | const spaces = Array(indentation + 1).join(" "); 36 | return spaces + newEntry; 37 | } 38 | -------------------------------------------------------------------------------- /bin/postlink.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const path = require("path"); 3 | const process = require("process"); 4 | const { spawnSync } = require("child_process"); 5 | const registerPodsFromPackage = require("../lib/registerPodsFromPackage"); 6 | const dependencies = require("../lib/getProjectDependencies")(); 7 | const package = require("../lib/getProject")(); 8 | const nodepath = process.cwd() + "/node_modules"; 9 | const opts = { 10 | encoding: "utf8", 11 | stdio: "inherit" 12 | }; 13 | var isSwift = false; 14 | var needsSwiftFix = false; 15 | dependencies.map(dependency => { 16 | const package = require(path.resolve(nodepath, dependency, "package.json")); 17 | registerPodsFromPackage(package); 18 | if (package.isSwift) isSwift = true; 19 | if (package.needsSwiftFix) needsSwiftFix = true; 20 | }); 21 | registerPodsFromPackage(package); 22 | if (package.isSwift) isSwift = true; 23 | if (package.needsSwiftFix) needsSwiftFix = true; 24 | //Now that all my pods are here, let's run a pod install 25 | const doFix = isSwift && needsSwiftFix; 26 | const mydir = process.cwd(); 27 | process.chdir("./ios"); 28 | spawnSync("pod", ["install"], opts); 29 | if (doFix) { 30 | const fixPods = require("../lib/fixPods"); 31 | process.chdir(mydir); 32 | fixPods(); 33 | } 34 | -------------------------------------------------------------------------------- /lib/registerPod.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const readPodfile = require('./readPodfile'); 4 | const findPodTargetLine = require('./findPodTargetLine'); 5 | const findLineToAddPod = require('./findLineToAddPod'); 6 | const findMarkedLinesInPodfile = require('./findMarkedLinesInPodfile'); 7 | const addPodEntry = require('./addPodEntry'); 8 | const savePodFile = require('./savePodFile'); 9 | const getIOSProject = require('./getIOSProject'); 10 | 11 | module.exports = function registerPod(pod, iOSProject) { 12 | if(!iOSProject || !iOSProject.projectName) iOSProject = getIOSProject(); 13 | if(!iOSProject || !iOSProject.projectName) return false; 14 | const podLines = readPodfile(iOSProject.podfile); 15 | const linesToAddEntry = getLinesToAddEntry(podLines, iOSProject); 16 | addPodEntry(podLines, linesToAddEntry, pod); 17 | savePodFile(iOSProject.podfile, podLines); 18 | }; 19 | 20 | function getLinesToAddEntry(podLines, { projectName }) { 21 | const linesToAddPodWithMarker = findMarkedLinesInPodfile(podLines); 22 | if (linesToAddPodWithMarker.length > 0) { 23 | return linesToAddPodWithMarker; 24 | } else { 25 | const firstTargetLined = findPodTargetLine(podLines, projectName); 26 | return findLineToAddPod(podLines, firstTargetLined); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-pod 2 | 3 | Extends support for CocoaPods in React Native projects by: 4 | 5 | 1. Initializing a Podfile for your ios project (in /ios/Podfile) 6 | 2. On react-native link, scans the package.json of all dependencies for a "pods" entry. If found, adds those pods to the Podfile. 7 | 3. At the end of react-native link, runs `pod install` to update your Pods if necessary. Now you have installed pods! 8 | 4. You can update pods at any time by running `react-native installpods` 9 | 10 | # Usage: 11 | 12 | ```bash 13 | yarn add react-native-pod 14 | react-native link 15 | ``` 16 | 17 | # Developer use 18 | 19 | **New!** Add pods you would like distributed with your package from the command line: 20 | 21 | ``` 22 | react-native addpod [pod] 23 | ``` 24 | 25 | or 26 | 27 | ``` 28 | react-native addpod [pod] --podversion [version] 29 | ``` 30 | 31 | or 32 | 33 | ``` 34 | react-native addpod [pod] --podgit[giturl] 35 | ``` 36 | 37 | Note that adding a pod puts the reference in your package.json. This gives the hint to react-native link to add it to your Podfile. 38 | 39 | To remove a pod: 40 | 41 | ``` 42 | react-native removepod [pod] 43 | ``` 44 | 45 | # Prerequisite 46 | 47 | You need to have [CocoaPods](http://cocoapods.org) installed. To get it going: `sudo gem install cocoapods`. 48 | 49 | # How to add value with this 50 | 51 | When making a native module that has a pod dependency, just add the pod reference to your pods in package.json manually or using the tools above, and make `react-native-pod` a peer dependency. 52 | 53 | Feedback welcome! 54 | -------------------------------------------------------------------------------- /bin/makepod.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var pbxproj = require("@raydeck/xcode"); 3 | var fs = require("fs"); 4 | var path = require("path"); 5 | var glob = require("glob"); 6 | 7 | //Get my directory 8 | var iosPath = process.argv[2]; 9 | if (!iosPath || !iosPath.length || !fs.existsSync(iosPath)) { 10 | var thisPath = process.argv[1]; 11 | var thisPath = path.dirname(thisPath); //bin directory 12 | var thisPath = path.dirname(thisPath); //dependency directory 13 | var thisPath = path.dirname(thisPath); // node_modules 14 | var baseName = path.basename(thisPath); 15 | if (!baseName.startsWith("node_modules")) { 16 | console.log("This is not a dependency: ", thisPath); 17 | process.exit(); 18 | } 19 | var thisPath = path.dirname(thisPath); // parent 20 | var iosPath = path.resolve(thisPath, "ios"); 21 | } else { 22 | iosPath = fs.realpathSync(iosPath); 23 | } 24 | if (!fs.existsSync(iosPath)) { 25 | console.log("Could not find ios in ", thisPath, iosPath); 26 | console.log(fs.readdirSync(thisPath)); 27 | process.exit(1); 28 | } 29 | xpdir = glob.sync(iosPath + "/*.xcodeproj")[0]; 30 | if (xpdir.length === 0) { 31 | console.log("Could not find xcodeproj directory inside: ", iosPath); 32 | process.exit(1); 33 | } 34 | const podPath = iosPath + "/Podfile"; 35 | if (!fs.existsSync(podPath)) { 36 | let filename = path.resolve(xpdir, "project.pbxproj"); 37 | if (!fs.existsSync(filename)) { 38 | console.log("COuld not find pbxproj file:", filename); 39 | process.exit(); 40 | } 41 | var proj = pbxproj.project(filename); 42 | var targets = []; 43 | proj.parse(function(err) { 44 | const nts = proj.pbxNativeTargetSection(); 45 | for (var key in nts) { 46 | if (key.endsWith("_comment")) continue; 47 | targets.push(nts[key].name); 48 | } 49 | targets = targets.map(val => { 50 | while (val.startsWith('"')) val = val.substring(1); 51 | while (val.endsWith('"')) val = val.substring(0, val.length - 1); 52 | return val; 53 | }); 54 | targets.sort(); 55 | const mainprojects = targets.filter(val => { 56 | if (val.endsWith("Tests")) { 57 | return false; 58 | } 59 | return true; 60 | }); 61 | var podlines = []; 62 | podlines.push("# Created by react-native-pod"); 63 | mainprojects.map(project => { 64 | const tvOS = project.endsWith("tvOS"); 65 | podlines.push("target '" + project + "' do"); 66 | podlines.push( 67 | "\t# We uncomment because we like dynamic frameworks witn working with swift projects" 68 | ); 69 | podlines.push("\tuse_frameworks!"); 70 | if (!tvOS) podlines.push("\t# Add new pods below this line"); 71 | targets.map(target => { 72 | if (target == project + "Tests") { 73 | //This is my test project 74 | podlines.push("\ttarget '" + target + "' do"); 75 | podlines.push("\t\tinherit! :search_paths"); 76 | podlines.push("\t\t# Pods for testing"); 77 | if (!tvOS) podlines.push("\t\t# Add new pods below this line"); 78 | podlines.push("\tend"); 79 | } 80 | }); 81 | podlines.push("end"); 82 | }); 83 | const podText = podlines.join("\n").replace(new RegExp("\t", "g"), " "); 84 | fs.writeFileSync(podPath, podText); 85 | }); 86 | console.log("Podfile created in " + podPath); 87 | } else { 88 | console.log("Podfile already present, we're OK!"); 89 | } 90 | --------------------------------------------------------------------------------