Skip to content

Commit

Permalink
feat(flagship): additional pod sources
Browse files Browse the repository at this point in the history
add configuration to allow for additional sources in Podfile
exposed as env config ios.pods.sources
  • Loading branch information
NickBurkhartBB authored and skyeckstrom committed Oct 19, 2018
1 parent 2df9d15 commit fe4c42e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/flagship/__tests__/mock_project/ios/Podfile
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
4 changes: 3 additions & 1 deletion packages/flagship/ios/Podfile
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions packages/flagship/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions packages/flagship/src/lib/__tests__/cocoapods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

14 changes: 14 additions & 0 deletions packages/flagship/src/lib/cocoapods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
9 changes: 9 additions & 0 deletions packages/flagship/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fe4c42e

Please sign in to comment.