# frozen_string_literal: true require 'xcodeproj' module GoNative module Plugins module IOS class AddFiles extend DSL::Serviceable attr_reader :file_paths def initialize(path) @file_paths = Dir.glob(path) end def call return if file_paths.empty? project = Xcodeproj::Project.open('MedianIOS.xcodeproj') target = project.native_targets.first resources_directory = File.join(FileUtils.pwd, 'Resources') FileUtils.mkdir_p(resources_directory) resources_group = project.main_group['Resources'] || project.main_group.new_group('Resources') file_paths.each do |file_path| file_name = File.basename(file_path) destination_path = File.join(resources_directory, file_name) FileUtils.cp(file_path, destination_path) relative_path = File.join('Resources', file_name) file_ref = resources_group.new_file(relative_path) target.resources_build_phase.add_file_reference(file_ref) end project.save end end end end end