Module: Pod::SPM::UpdateScript::Mixin

Included in:
Hook::UpdateCopyResourcesScript, Hook::UpdateEmbedFrameworksScript
Defined in:
lib/cocoapods-spm/hooks/helpers/update_script.rb

Instance Method Summary collapse

Instance Method Details

#update_script(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cocoapods-spm/hooks/helpers/update_script.rb', line 7

def update_script(options = {})
  script_name = options[:name]
  content_by_target = options[:content_by_target]

  aggregate_targets.each do |target|
    lines, input_paths, output_paths = content_by_target.call(target)
    next if input_paths.empty?

    update_script_content(
      path: target.send("#{script_name}_path"),
      before: options[:insert_before],
      insert: lines.join("\n")
    )

    # Update input/output files
    user_build_configurations.each_key do |config|
      append_contents = lambda do |method_name, contents|
        target.send(method_name, config).open("a") do |f|
          contents.each { |p| f << "\n" << p }
        end
      end
      append_contents.call("#{script_name}_input_files_path", input_paths)
      append_contents.call("#{script_name}_output_files_path", output_paths)
    end
  end
end