Skip to content

Commit

Permalink
Adds support for script_phases in CocoaPods
Browse files Browse the repository at this point in the history
  • Loading branch information
orta authored and alloy committed Mar 21, 2019
1 parent 6f882f1 commit 80a7ab3
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions packages/cli/native_modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ def use_native_modules!(packages = nil)
end

pod spec.name, :path => package["root"]

if package["ios"]["scriptPhases"]
# Can be either an object, or an array of objects
Array(package["ios"]["scriptPhases"]).each do |phase|
# see https://www.rubydoc.info/gems/cocoapods-core/Pod/Podfile/DSL#script_phase-instance_method
# for the full object keys

# Support passing in a path instead of the raw script
if phase["path"]
phase["script"] = File.read(phase["path"])
phase.delete("path")
end

# Support converting the execution position into a symbol
if phase["execution_position"]
phase["execution_position"] = phase["execution_position"].to_sym
end

script_phase phase
end
end

found_pods.push spec
end

Expand Down Expand Up @@ -64,16 +86,17 @@ def pluralize(count)
end
end

script_phase = {
"script" => "123",
"name" => "My Name",
"execution_position" => "before_compile",
"input" => "string"
}

ios_package = {
"root" => "/Users/grabbou/Repositories/WebViewDemoApp/node_modules/react",
"ios" => {
"podspec" => "React.podspec",
"buildPhases" => [{
"path" => "/Users/grabbou/Repositories/WebViewDemoApp/node_modules/react/ios/build_phase_script.sh",
"name" => "My Name",
"executionPosition" => "before_compile",
"input" => "string"
}],
},
"android" => nil,
}
Expand All @@ -91,6 +114,7 @@ def pluralize(count)
@activated_pods = activated_pods = []
@current_target_definition_dependencies = current_target_definition_dependencies = []
@printed_messages = printed_messages = []
@added_scripts = added_scripts = []
@target_definition = target_definition = Object.new
@podfile = podfile = Object.new
@spec = spec = Object.new
Expand All @@ -110,6 +134,10 @@ def pluralize(count)
activated_pods << { name: name, options: options }
end

podfile.singleton_class.send(:define_method, :script_phase) do |options|
added_scripts << options
end

target_definition.singleton_class.send(:define_method, :dependencies) do
current_target_definition_dependencies
end
Expand Down Expand Up @@ -154,6 +182,23 @@ def pluralize(count)
@activated_pods.must_equal []
end

it "sets up script_phases and passes in the options directly" do
@podfile.instance_eval do
config["ios-dep"]["ios"]["scriptPhases"] = [script_phase]
use_native_modules!(config)
end

@activated_pods.must_equal [{
name: "ios-dep",
options: { path: ios_package["root"] }
}]
@added_scripts.must_equal [{
"script" => "123",
"name" => "My Name",
"execution_position" => :before_compile,
"input" => "string"}]
end

it "prints out the native module pods that were found" do
@podfile.instance_eval do
use_native_modules!({})
Expand Down

0 comments on commit 80a7ab3

Please sign in to comment.