From f1aea2658860837ec78e484c6efdfec6bcf0338f Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Tue, 16 Apr 2019 23:25:56 +0200 Subject: [PATCH 1/4] initial commit --- .../src/link-pods/findLineToAddPod.js | 2 +- .../src/link-pods/findMarkedLinesInPodfile.js | 2 +- .../src/link-pods/findPodTargetLine.js | 1 + .../src/link-pods/registerNativeModule.js | 22 ++++++++++++++++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/platform-ios/src/link-pods/findLineToAddPod.js b/packages/platform-ios/src/link-pods/findLineToAddPod.js index 9f7a4c61a..691a6629c 100644 --- a/packages/platform-ios/src/link-pods/findLineToAddPod.js +++ b/packages/platform-ios/src/link-pods/findLineToAddPod.js @@ -15,7 +15,7 @@ export default function findLineToAddPod(podLines, firstTargetLine) { // match function definition, like: post_install do |installer| (some Podfiles have function defined inside main target const functionDefinition = /^\s*[a-z_]+\s+do(\s+\|[a-z]+\|)?/g; - for (let i = firstTargetLine, len = podLines.length; i < len; i++) { + for (let i = firstTargetLine; i < podLines.length - 1; i++) { const matchNextConstruct = podLines[i].match(nextTarget) || podLines[i].match(functionDefinition); const matchEnd = podLines[i].match(endOfCurrentTarget); diff --git a/packages/platform-ios/src/link-pods/findMarkedLinesInPodfile.js b/packages/platform-ios/src/link-pods/findMarkedLinesInPodfile.js index 3087937b7..05033817a 100644 --- a/packages/platform-ios/src/link-pods/findMarkedLinesInPodfile.js +++ b/packages/platform-ios/src/link-pods/findMarkedLinesInPodfile.js @@ -7,7 +7,7 @@ * @format */ -const MARKER_TEXT = '# Add new pods below this line'; +export const MARKER_TEXT = '# Add new pods below this line'; export default function findMarkedLinesInPodfile(podLines) { const result = []; diff --git a/packages/platform-ios/src/link-pods/findPodTargetLine.js b/packages/platform-ios/src/link-pods/findPodTargetLine.js index 71bd8353e..c728001b9 100644 --- a/packages/platform-ios/src/link-pods/findPodTargetLine.js +++ b/packages/platform-ios/src/link-pods/findPodTargetLine.js @@ -8,6 +8,7 @@ */ export default function findPodTargetLine(podLines, projectName) { + console.log(projectName); const targetName = projectName.replace('.xcodeproj', ''); // match first target definition in file: target 'target_name' do const targetRegex = new RegExp(`target ('|")${targetName}('|") do`, 'g'); diff --git a/packages/platform-ios/src/link-pods/registerNativeModule.js b/packages/platform-ios/src/link-pods/registerNativeModule.js index 5d8abca42..2c77c03fb 100644 --- a/packages/platform-ios/src/link-pods/registerNativeModule.js +++ b/packages/platform-ios/src/link-pods/registerNativeModule.js @@ -6,11 +6,15 @@ * * @format */ +import chalk from 'chalk'; +import {CLIError, inlineString} from '@react-native-community/cli-tools'; import readPodfile from './readPodfile'; import findPodTargetLine from './findPodTargetLine'; import findLineToAddPod from './findLineToAddPod'; -import findMarkedLinesInPodfile from './findMarkedLinesInPodfile'; +import findMarkedLinesInPodfile, { + MARKER_TEXT, +} from './findMarkedLinesInPodfile'; import addPodEntry from './addPodEntry'; import savePodFile from './savePodFile'; @@ -31,5 +35,21 @@ function getLinesToAddEntry(podLines, {projectName}) { return linesToAddPodWithMarker; } const firstTargetLined = findPodTargetLine(podLines, projectName); + if (firstTargetLined === null) { + throw new CLIError( + inlineString(` + We couldn't find a target to add a CocoaPods dependency. + + Make sure that you have a ${chalk.bold( + `target '${projectName.replace('.xcodeproj', '')}' do`, + )} line in your Podfile. + + Alternatively, include ${chalk.dim( + MARKER_TEXT, + )} in a Podfile where we should add + linked dependencies. + `), + ); + } return findLineToAddPod(podLines, firstTargetLined); } From 0f64225702d472f898725f30882250abdf48a66d Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Tue, 16 Apr 2019 23:28:44 +0200 Subject: [PATCH 2/4] Remove log --- packages/platform-ios/src/link-pods/findPodTargetLine.js | 1 - packages/platform-ios/src/link-pods/registerNativeModule.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/platform-ios/src/link-pods/findPodTargetLine.js b/packages/platform-ios/src/link-pods/findPodTargetLine.js index c728001b9..71bd8353e 100644 --- a/packages/platform-ios/src/link-pods/findPodTargetLine.js +++ b/packages/platform-ios/src/link-pods/findPodTargetLine.js @@ -8,7 +8,6 @@ */ export default function findPodTargetLine(podLines, projectName) { - console.log(projectName); const targetName = projectName.replace('.xcodeproj', ''); // match first target definition in file: target 'target_name' do const targetRegex = new RegExp(`target ('|")${targetName}('|") do`, 'g'); diff --git a/packages/platform-ios/src/link-pods/registerNativeModule.js b/packages/platform-ios/src/link-pods/registerNativeModule.js index 2c77c03fb..20bb70895 100644 --- a/packages/platform-ios/src/link-pods/registerNativeModule.js +++ b/packages/platform-ios/src/link-pods/registerNativeModule.js @@ -40,7 +40,7 @@ function getLinesToAddEntry(podLines, {projectName}) { inlineString(` We couldn't find a target to add a CocoaPods dependency. - Make sure that you have a ${chalk.bold( + Make sure that you have a ${chalk.dim( `target '${projectName.replace('.xcodeproj', '')}' do`, )} line in your Podfile. From be44a4028f6473a2d70de56d28cf05c9d2761446 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Tue, 16 Apr 2019 23:32:07 +0200 Subject: [PATCH 3/4] fix: failing cocoa-pods tests --- packages/platform-ios/native_modules.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/platform-ios/native_modules.rb b/packages/platform-ios/native_modules.rb index 287468f95..cff2a1b42 100644 --- a/packages/platform-ios/native_modules.rb +++ b/packages/platform-ios/native_modules.rb @@ -195,8 +195,8 @@ def pluralize(count) @podfile.use_native_modules({ "pkg-1" => @ios_package }) @podfile.use_native_modules({ "pkg-1" => @ios_package, "pkg-2" => @ios_package }) @printed_messages.must_equal [ - "Detected native module pod for ios-dep", - "Detected native module pods for ios-dep, and ios-dep" + "Detected React Native module pod for ios-dep", + "Detected React Native module pods for ios-dep, and ios-dep" ] end From 48f045d88a33ccb881d78b6c3c9c7191978458b9 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Tue, 16 Apr 2019 23:38:33 +0200 Subject: [PATCH 4/4] Improve accessibility --- .../platform-ios/src/link-pods/registerNativeModule.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/platform-ios/src/link-pods/registerNativeModule.js b/packages/platform-ios/src/link-pods/registerNativeModule.js index 20bb70895..a3363e0a4 100644 --- a/packages/platform-ios/src/link-pods/registerNativeModule.js +++ b/packages/platform-ios/src/link-pods/registerNativeModule.js @@ -40,13 +40,13 @@ function getLinesToAddEntry(podLines, {projectName}) { inlineString(` We couldn't find a target to add a CocoaPods dependency. - Make sure that you have a ${chalk.dim( + Make sure that you have a "${chalk.dim( `target '${projectName.replace('.xcodeproj', '')}' do`, - )} line in your Podfile. + )}" line in your Podfile. - Alternatively, include ${chalk.dim( + Alternatively, include "${chalk.dim( MARKER_TEXT, - )} in a Podfile where we should add + )}" in a Podfile where we should add linked dependencies. `), );