Sha256: 06f6bb71c348196ddf4eb76b50d858ed1a65e08eaa6a76e1247af03780eb4c8a

Contents?: true

Size: 1.74 KB

Versions: 11

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

require 'xcodeproj'

module GoNative
  module Plugins
    module IOS
      class Rename
        extend DSL::Serviceable

        attr_reader :name, :proj

        def initialize(name)
          @name = name
        end

        def call
          system("mv MedianIOS.xcodeproj #{proj_path}")
          @proj = Xcodeproj::Project.open(proj_path)
          rename_target!
          recreate_scheme!
          fix_workspace_refs!
          system('pod install')
        end

        def rename_target!
          proj.targets.first.name = name
          proj.save
        end

        def recreate_scheme!
          schemes_dir = Xcodeproj::XCScheme.shared_data_dir(proj_path)
          FileUtils.rm_rf(schemes_dir)
          FileUtils.mkdir_p(schemes_dir)

          scheme = Xcodeproj::XCScheme.new
          target = proj.targets.first

          test_target = target if target.respond_to?(:test_target_type?) && target.test_target_type?
          launch_target = target.respond_to?(:launchable_target_type?) && target.launchable_target_type?
          scheme.configure_with_targets(target, test_target, launch_target: launch_target)

          scheme.save_as(proj_path, target.name, true)
        end

        def fix_workspace_refs!
          FileUtils.rm_rf('MedianIOS.xcworkspace')
          proj_ref = Xcodeproj::Workspace::FileReference.new(proj_path)
          pods_ref = Xcodeproj::Workspace::FileReference.new('Pods/Pods.xcodeproj')
          workspace = Xcodeproj::Workspace.new(nil, proj_ref, pods_ref)
          workspace.save_as(workspace_path)
        end

        private

        def proj_path
          "#{name}.xcodeproj"
        end

        def workspace_path
          "#{name}.xcworkspace"
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
gonative-cli-1.4.0 lib/gonative/plugins/ios/rename.rb
gonative-cli-1.3.9 lib/gonative/plugins/ios/rename.rb
gonative-cli-1.3.8 lib/gonative/plugins/ios/rename.rb
gonative-cli-1.3.7 lib/gonative/plugins/ios/rename.rb
gonative-cli-1.3.6 lib/gonative/plugins/ios/rename.rb
gonative-cli-1.3.5 lib/gonative/plugins/ios/rename.rb
gonative-cli-1.3.4 lib/gonative/plugins/ios/rename.rb
gonative-cli-1.3.3 lib/gonative/plugins/ios/rename.rb
gonative-cli-1.3.2 lib/gonative/plugins/ios/rename.rb
gonative-cli-1.3.1 lib/gonative/plugins/ios/rename.rb
gonative-cli-1.3.0 lib/gonative/plugins/ios/rename.rb