#!/usr/bin/env ruby require 'xcodeproj' project_path = 'jellypig.xcodeproj' project = Xcodeproj::Project.open(project_path) # Find the main target target = project.targets.find { |t| t.name == 'jellypig tvOS' } #Step 1: Remove ALL instances of EPG files file_names = ['EPGViewModel.swift', 'EPGProgramCell.swift', 'EPGChannelRow.swift', 'EPGTimelineHeader.swift', 'EPGCurrentTimeIndicator.swift'] puts "=== Step 1: Removing all EPG file references ===" file_names.each do |file_name| # Remove from build phase (all instances) target.source_build_phase.files.delete_if do |build_file| if build_file.file_ref && (build_file.file_ref.path == file_name || build_file.file_ref.path&.end_with?(file_name)) puts "Removed from build phase: #{file_name}" true else false end end # Remove file references (all instances) project.main_group.recursive_children.each do |child| if child.is_a?(Xcodeproj::Project::Object::PBXFileReference) && (child.path == file_name || child.path&.end_with?(file_name)) child.remove_from_project puts "Removed reference: #{file_name}" end end end puts "\n=== Step 2: Adding EPG files with correct paths ===" # Files to add with their paths and group locations files_to_add = [ { path: 'Shared/ViewModels/EPGViewModel.swift', group_path: ['jellypig', 'Shared', 'ViewModels'] }, { path: 'jellypig tvOS/Views/ProgramGuideView/Components/EPGProgramCell.swift', group_path: ['jellypig', 'jellypig tvOS', 'Views', 'ProgramGuideView', 'Components'] }, { path: 'jellypig tvOS/Views/ProgramGuideView/Components/EPGChannelRow.swift', group_path: ['jellypig', 'jellypig tvOS', 'Views', 'ProgramGuideView', 'Components'] }, { path: 'jellypig tvOS/Views/ProgramGuideView/Components/EPGTimelineHeader.swift', group_path: ['jellypig', 'jellypig tvOS', 'Views', 'ProgramGuideView', 'Components'] }, { path: 'jellypig tvOS/Views/ProgramGuideView/Components/EPGCurrentTimeIndicator.swift', group_path: ['jellypig', 'jellypig tvOS', 'Views', 'ProgramGuideView', 'Components'] } ] files_to_add.each do |file_info| file_path = file_info[:path] absolute_path = File.join(Dir.pwd, file_path) unless File.exist?(absolute_path) puts "ERROR: File does not exist: #{absolute_path}" next end # Navigate to the correct group group = project.main_group file_info[:group_path].each do |group_name| found_group = group.groups.find { |g| g.name == group_name || g.path == group_name } group = found_group || group.new_group(group_name) end # Add file reference file_ref = group.new_reference(absolute_path) # Add to target's source build phase (only once!) target.source_build_phase.add_file_reference(file_ref) puts "Added: #{file_path}" end # Save the project project.save puts "\n=== Done! Project updated successfully! ==="