jellyflood/add_programguideview.rb

44 lines
1.1 KiB
Ruby

#!/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' }
file_path = 'jellypig tvOS/Views/ProgramGuideView.swift'
absolute_path = File.join(Dir.pwd, file_path)
unless File.exist?(absolute_path)
puts "ERROR: File does not exist: #{absolute_path}"
exit 1
end
# Navigate to correct group
group = project.main_group
['jellypig', 'jellypig tvOS', 'Views', 'ProgramGuideView'].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
# Check if already exists
existing_file = group.files.find { |f| f.path == File.basename(file_path) }
if existing_file
puts "File already exists in project"
else
# Add file reference
file_ref = group.new_reference(absolute_path)
# Add to target's source build phase
target.source_build_phase.add_file_reference(file_ref)
puts "Added: #{file_path}"
end
# Save the project
project.save
puts "Done!"