-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_files_dynamic.rb
More file actions
80 lines (60 loc) · 2.09 KB
/
Copy pathadd_files_dynamic.rb
File metadata and controls
80 lines (60 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env ruby
require 'xcodeproj'
project_path = '/Users/ruirui/Code/Ai_Code/SkinLab/SkinLab.xcodeproj'
project = Xcodeproj::Project.open(project_path)
# Get the main target
target = project.targets.find { |t| t.name == 'SkinLab' }
# Get files from command line arguments
if ARGV.empty?
puts "Usage: ruby add_files_dynamic.rb <file1.swift> <file2.swift> ..."
exit 1
end
# Helper function to find or create group
def find_or_create_group(project, path_components)
current_group = project.main_group
path_components.each do |component|
next_group = current_group.groups.find { |g| g.name == component || g.path == component }
if next_group.nil?
next_group = current_group.new_group(component, component)
end
current_group = next_group
end
current_group
end
added_count = 0
skipped_count = 0
ARGV.each do |relative_path|
file_path = File.join('/Users/ruirui/Code/Ai_Code/SkinLab', relative_path)
# Check if file exists
unless File.exist?(file_path)
puts "⚠️ File not found: #{relative_path}"
next
end
# Check if file is already in project
existing_file = project.files.find { |f| f.real_path.to_s == file_path }
if existing_file
puts "⏭️ Already in project: #{relative_path}"
skipped_count += 1
next
end
# Extract group path from file path
# e.g., "SkinLab/Features/Tracking/Models/File.swift" -> ["SkinLab", "Features", "Tracking", "Models"]
path_parts = relative_path.split('/')
group_parts = path_parts[0...-1] # All but the last (filename)
# Find or create the group
group = find_or_create_group(project, group_parts)
# Add file to group
file_ref = group.new_file(file_path)
# Add to target's sources build phase (only for .swift files)
if file_path.end_with?('.swift')
target.source_build_phase.add_file_reference(file_ref)
end
puts "✅ Added: #{relative_path}"
added_count += 1
end
# Save the project
project.save
puts "\n📊 Summary:"
puts " ✅ Added: #{added_count} files"
puts " ⏭️ Skipped: #{skipped_count} files (already in project)"
puts "\n✨ Project file updated successfully!"