diff --git a/docs/dependencies.md b/docs/dependencies.md index b7174044d..4bd2d35f6 100644 --- a/docs/dependencies.md +++ b/docs/dependencies.md @@ -80,6 +80,33 @@ Custom path to `.podspec` file to use when auto-linking. Example: `node_modules/ An array of shared iOS libraries to link with the dependency. E.g. `libc++`. This is mostly a requirement of the native code that a dependency ships with. +#### platforms.ios.scriptPhases + +An array of iOS script phases to add to the project. Specifying a `path` property with a path relative to the dependency root will load the contents of the file at the path as the script contents. + +**Example:** + +```js +// react-native.config.js +module.exports = { + dependency: { + platforms: { + ios: { + scriptPhases: [ + { + name: '[MY DEPENDENCY] My Script', + path: './my_script.sh', + execution_position: 'after_compile', + }, + ], + }, + }, + }, +}; +``` + +See [`script_phase` options](https://www.rubydoc.info/gems/cocoapods-core/Pod/Podfile/DSL#script_phase-instance_method) for a full list of available object keys. + #### platforms.android.sourceDir A relative path to a folder with source files. E.g. `custom-android`, or `custom-android/app`. By default, CLI searches for `android` and `android/app` as source dirs. diff --git a/packages/cli/src/tools/config/__tests__/__snapshots__/index-test.js.snap b/packages/cli/src/tools/config/__tests__/__snapshots__/index-test.js.snap index 36eb20609..89f237697 100644 --- a/packages/cli/src/tools/config/__tests__/__snapshots__/index-test.js.snap +++ b/packages/cli/src/tools/config/__tests__/__snapshots__/index-test.js.snap @@ -94,6 +94,7 @@ Object { "podspecPath": null, "projectName": "HelloWorld.xcodeproj", "projectPath": "<>/node_modules/react-native-test/ios/HelloWorld.xcodeproj", + "scriptPhases": Array [], "sharedLibraries": Array [], "sourceDir": "./abc", }, @@ -128,6 +129,7 @@ Object { "podspecPath": null, "projectName": "customProject.xcodeproj", "projectPath": "<>/node_modules/react-native-foo/customLocation/customProject.xcodeproj", + "scriptPhases": Array [], "sharedLibraries": Array [], "sourceDir": "<>/node_modules/react-native-foo/customLocation", }, @@ -167,6 +169,7 @@ Object { "podspecPath": "<>/node_modules/react-native-test/ReactNativeTest.podspec", "projectName": "customProject.xcodeproj", "projectPath": "<>/node_modules/react-native-test/customLocation/customProject.xcodeproj", + "scriptPhases": Array [], "sharedLibraries": Array [], "sourceDir": "<>/node_modules/react-native-test/customLocation", }, @@ -204,6 +207,7 @@ Object { "podspecPath": null, "projectName": "HelloWorld.xcodeproj", "projectPath": "<>/node_modules/react-native-test/ios/HelloWorld.xcodeproj", + "scriptPhases": Array [], "sharedLibraries": Array [], "sourceDir": "<>/node_modules/react-native-test/ios", }, diff --git a/packages/cli/src/tools/config/__tests__/index-test.js b/packages/cli/src/tools/config/__tests__/index-test.js index 112754815..f9bc58808 100644 --- a/packages/cli/src/tools/config/__tests__/index-test.js +++ b/packages/cli/src/tools/config/__tests__/index-test.js @@ -354,6 +354,7 @@ module.exports = { "podspecPath": "custom-path", "projectName": "LocalRNLibrary.xcodeproj", "projectPath": "<>/native-libs/local-lib/ios/LocalRNLibrary.xcodeproj", + "scriptPhases": Array [], "sharedLibraries": Array [], "sourceDir": "<>/native-libs/local-lib/ios", }, diff --git a/packages/cli/src/tools/config/schema.js b/packages/cli/src/tools/config/schema.js index 8bb0174c7..7850227bd 100644 --- a/packages/cli/src/tools/config/schema.js +++ b/packages/cli/src/tools/config/schema.js @@ -52,6 +52,7 @@ export const dependencyConfig = t podspecPath: t.string(), sharedLibraries: t.array().items(t.string()), libraryFolder: t.string(), + scriptPhases: t.array().items(t.object()), }) .default({}), android: t diff --git a/packages/platform-ios/native_modules.rb b/packages/platform-ios/native_modules.rb index da922bf9f..7ddf4de6f 100644 --- a/packages/platform-ios/native_modules.rb +++ b/packages/platform-ios/native_modules.rb @@ -63,6 +63,7 @@ def use_native_modules!(root = "..", config = nil) Array(package_config["scriptPhases"]).each do |phase| # see https://www.rubydoc.info/gems/cocoapods-core/Pod/Podfile/DSL#script_phase-instance_method # for the full object keys + Pod::UI.puts "Adding a custom script phase for Pod #{spec.name}: #{phase["name"] || 'No name specified.'}" # Support passing in a path relative to the root of the package if phase["path"] @@ -75,6 +76,7 @@ def use_native_modules!(root = "..", config = nil) phase["execution_position"] = phase["execution_position"].to_sym end + phase = Hash[phase.map { |k, v| [k.to_sym, v] }] script_phase phase end end @@ -231,10 +233,10 @@ def pluralize(count) @config["dependencies"]["ios-dep"]["platforms"]["ios"]["scriptPhases"] = [@script_phase] @podfile.use_native_modules('..', @config) @added_scripts.must_equal [{ - "script" => "123", - "name" => "My Name", - "execution_position" => :before_compile, - "input" => "string" + :script => "123", + :name => "My Name", + :execution_position => :before_compile, + :input => "string" }] end @@ -251,10 +253,10 @@ def pluralize(count) end @added_scripts.must_equal [{ - "script" => "contents from file", - "name" => "My Name", - "execution_position" => :before_compile, - "input" => "string" + :script => "contents from file", + :name => "My Name", + :execution_position => :before_compile, + :input => "string" }] file_read_mock.verify end diff --git a/packages/platform-ios/src/config/index.js b/packages/platform-ios/src/config/index.js index 5bf40f7b8..52af841a2 100644 --- a/packages/platform-ios/src/config/index.js +++ b/packages/platform-ios/src/config/index.js @@ -68,6 +68,7 @@ export function projectConfig( libraryFolder: userConfig.libraryFolder || 'Libraries', sharedLibraries: mapSharedLibaries(userConfig.sharedLibraries || []), plist: userConfig.plist || [], + scriptPhases: userConfig.scriptPhases || [], }; } diff --git a/types/index.js b/types/index.js index 32ba63ef2..1c09e0a3e 100644 --- a/types/index.js +++ b/types/index.js @@ -70,6 +70,11 @@ type ProjectParamsIOST = { sharedLibraries?: string[], libraryFolder?: string, plist: any[], + scriptPhases: Array<{ + name?: string, + path?: string, + [key: string]: string, + }>, }; type PlatformConfig<