-
Notifications
You must be signed in to change notification settings - Fork 1
/
DLSharedBundleResources.rb
executable file
·72 lines (62 loc) · 2.54 KB
/
DLSharedBundleResources.rb
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
#!/usr/bin/ruby
# Importing libraries
require 'Xcodeproj'
require 'colorize'
# end import
# Setting the project path (absolute path, example: /Users/username/Documents/xcode_workspace/folder/to/project/project.xcodeproj)
# DO NOT USE THE ~/ TO REPRESENT /Users/username/ path
print "Insert your project path (do not use ~/ to represent /Users/username/ folder): "
path = gets.chomp
print "\nEnter the incomplete target name: "
notCompleteTargetName = gets.chomp
print "\nEnter the complete target name: "
completeTargetName = gets.chomp
# Settings a file "blacklist" that it makes you able to automatically skip files you won't be shared
# You can also specify only a part of the file name
blacklist = ["ADBM"]
# end settings
# Open the project
project = Xcodeproj::Project.open(path);
# Setting the targets index
# The index in the array is the target position (top = 0; bottom = last one) on the project tab in Xcode
fullTargetIndex = 999 # Non-existing position to avoid not correct target name
incompleteTargetIndex = 999 # Non-existing position to avoid not correct target name
# end setting
print "Retrieving targets on project...\n"
currentIndex = 0
project.targets.each do |target|
# If this target is equal to the one type as incompleteTarget...
if target.name.casecmp(notCompleteTargetName).zero?
# ... I will save its index
incompleteTargetIndex = currentIndex
# If this target is equal to the one typed as completeTarget...
elsif target.name.casecmp(completeTargetName).zero?
# ... I will save its index
fullTargetIndex = currentIndex
end
# Incrementing the counter
currentIndex+=1
end
# Setting targets
# The index in the array is the target position (top = 0; bottom = last one) on the project tab in Xcode
incompleteTarget = project.targets[incompleteTargetIndex];
fullTarget = project.targets[fullTargetIndex];
#end setting target
# Start iteration on fullTarget resources
fullTarget::resources_build_phase.files.each do |buildFile|
fileReference = buildFile::file_ref
# If it is a blacklisted file, I will skip it
if blacklist.any? { |file| fileReference.display_name.include? file }
print "#{fileReference.display_name} skipped\n".red
else
print "#{fileReference.display_name}\n"
# If the file isn't in the resources of the incomplete target...
unless incompleteTarget.resources_build_phase.files_references.include?(fileReference)
print "Added #{fileReference.real_path}\n".green
# ... I will add it
incompleteTarget.resources_build_phase.add_file_reference(fileReference)
end
end
end
# Saving the project
project::save