Sha256: 32a2f88d023bc28f0649e35facbd80a09ec0ed0fc16d09be3d456d07d3958281

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

# 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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gonative-cli-1.4.4 lib/gonative/plugins/ios/add_files.rb
gonative-cli-1.4.3 lib/gonative/plugins/ios/add_files.rb
gonative-cli-1.4.2 lib/gonative/plugins/ios/add_files.rb
gonative-cli-1.4.1 lib/gonative/plugins/ios/add_files.rb
gonative-cli-1.4.0 lib/gonative/plugins/ios/add_files.rb