diff --git a/packages/flagship/__tests__/mock_project/ios/Podfile b/packages/flagship/__tests__/mock_project/ios/Podfile index f892d4b2e5..7578b60a81 100644 --- a/packages/flagship/__tests__/mock_project/ios/Podfile +++ b/packages/flagship/__tests__/mock_project/ios/Podfile @@ -1,5 +1,7 @@ # You Podfile should look similar to this file. React Native currently does not support use_frameworks! source 'https://github.com/CocoaPods/Specs.git' +# add more sources using environment key ios.pods.sources +# ADDITIONAL_POD_SOURCES platform :ios, '10.3' diff --git a/packages/flagship/ios/Podfile b/packages/flagship/ios/Podfile index 49475d7693..7568ae8283 100644 --- a/packages/flagship/ios/Podfile +++ b/packages/flagship/ios/Podfile @@ -1,5 +1,7 @@ # You Podfile should look similar to this file. React Native currently does not support use_frameworks! source 'https://github.com/CocoaPods/Specs.git' +# add more sources using environment key ios.pods.sources +# ADDITIONAL_POD_SOURCES platform :ios, '10.3' @@ -31,7 +33,7 @@ target 'FLAGSHIP' do # Add new pods below this line pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info' - + # When you have pods that also depend on React (like any custom module), # React can end up getting included multiple times. Remove React as a # dependency from pods. diff --git a/packages/flagship/src/commands/init.ts b/packages/flagship/src/commands/init.ts index 9748d78262..7f9e4755c2 100644 --- a/packages/flagship/src/commands/init.ts +++ b/packages/flagship/src/commands/init.ts @@ -195,6 +195,11 @@ function initIOS( ios.usageDescription(configuration); // Add usage descriptions ios.sentryProperties(configuration); ios.setEnvSwitcherInitialEnv(configuration, environmentIdentifier); + if (configuration.ios) { + if (configuration.ios.pods) { + cocoapods.sources(configuration.ios.pods.sources); + } + } if (!configuration.disableDevFeature) { ios.addDevMenuFlag(configuration); diff --git a/packages/flagship/src/lib/__tests__/cocoapods.test.ts b/packages/flagship/src/lib/__tests__/cocoapods.test.ts index 0ef4a639dc..766a520a4e 100644 --- a/packages/flagship/src/lib/__tests__/cocoapods.test.ts +++ b/packages/flagship/src/lib/__tests__/cocoapods.test.ts @@ -69,3 +69,12 @@ test(`add pod to podfile`, () => { expect(Podfile).toMatch('PODTEST2'); }); +test('add pod sources to podfile', () => { + cocoapods.sources(['POD_SOURCE_1', 'POD_SOURCE_2']); + const Podfile = fs + .readFileSync(nodePath.join(tempRootDir, `ios/Podfile`)) + .toString(); + expect(Podfile).toMatch('POD_SOURCE_1'); + expect(Podfile).toMatch('POD_SOURCE_2'); +}); + diff --git a/packages/flagship/src/lib/cocoapods.ts b/packages/flagship/src/lib/cocoapods.ts index 7f279684ce..1be33c1cae 100644 --- a/packages/flagship/src/lib/cocoapods.ts +++ b/packages/flagship/src/lib/cocoapods.ts @@ -55,3 +55,17 @@ export function add(path: string, pods: string[]): void { helpers.logInfo(`Podfile updated: ${pods.join(', ')}`); } + +/** + * Add additional sources to the Podfile + * @param {string[]} sources - list of sources to add + */ +export function sources(sources: string[]): void { + if (sources && sources.length > 0) { + helpers.logInfo('adding additional pod sources: ' + sources.join(', ')); + let podfileContents = fs.readFileSync(path.ios.podfilePath(), 'utf8'); + podfileContents = podfileContents.replace('# ADDITIONAL_POD_SOURCES', + sources.map(s => `source '${s}'`).join('\n')); + fs.writeFileSync(path.ios.podfilePath(), podfileContents); + } +} diff --git a/packages/flagship/src/types.ts b/packages/flagship/src/types.ts index 80adf80e9b..28dab4827c 100644 --- a/packages/flagship/src/types.ts +++ b/packages/flagship/src/types.ts @@ -88,6 +88,15 @@ export interface Config { webTitle?: string; webScriptInjectHeader?: string; webScriptInjectFooter?: string; + ios: IOSConfig; +} + +export interface IOSConfig { + pods: PodsConfig; +} + +export interface PodsConfig { + sources: string[]; } export interface NPMPackageConfig {