Skip to content

Instantly share code, notes, and snippets.

@chrsp
Created September 8, 2023 09:04
Show Gist options
  • Save chrsp/4acc9246ae5b3e40af32f4eda3e05f54 to your computer and use it in GitHub Desktop.
Save chrsp/4acc9246ae5b3e40af32f4eda3e05f54 to your computer and use it in GitHub Desktop.
Uses xcodeproj to add from a folder to a Xcode Project
#!/bin/bash
# Function to install the 'xcodeproj' gem
install_xcodeproj() {
gem install xcodeproj
}
# Check if 'xcodeproj' gem is installed
if ! gem spec xcodeproj > /dev/null 2>&1; then
echo "Installing 'xcodeproj' gem..."
install_xcodeproj
fi
# Set the parameters
project_path='iosApp.xcodeproj'
project_folder_path='iosApp'
folder_path='ksp'
target_name='iosApp'
# Run the Ruby script
ruby_script='
require "xcodeproj"
project_path = ARGV[0]
project_folder_path = ARGV[1]
folder_path = ARGV[2]
target_name = ARGV[3]
project = Xcodeproj::Project.open(project_path)
group_name = "KspGenerated"
project_folder = project.main_group.find_subpath(File.join(project_folder_path), true)
group = project[group_name] || project.new_group(group_name)
# Get a list of files in the folder
Dir.glob("#{folder_path}/*").each do |file_path|
file_reference = group.new_file(file_path)
target = project.targets.find { |t| t.name == target_name }
target.add_file_references([file_reference]) if target
end
project.save
'
# Execute the Ruby script with parameters
ruby -e "$ruby_script" "$project_path" "$project_folder_path" "$folder_path" "$target_name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment