# 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("git mv GoNativeIOS.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('GoNativeIOS.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