-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.rb
executable file
·79 lines (71 loc) · 2.78 KB
/
update.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
73
74
75
76
77
78
#!/usr/bin/env ruby
require 'xcodeproj'
project = Xcodeproj::Project.open('Wishlist.xcodeproj')
def addfiles(path, current_group, target)
Dir.glob(path) do |item|
next if item == '.' or item == '.DS_Store'
if File.directory?(item)
directory_path = File.basename(item)
directory_group = current_group.new_group(directory_path)
addfiles("#{item}/*", directory_group, target)
else
item_file = current_group.new_file(item)
if item.include? ".swift"
target.add_file_references([item_file])
end
end
end
end
# Add tooling
targets_for_sourcery = project.native_targets.select { |x| x.name == 'Tooling' }
targets_for_sourcery.each do |target|
# add files
sources_group = project.main_group.find_subpath("Sources", false)
tooling_group = sources_group.find_subpath("Tooling", true)
templates_group = tooling_group.find_subpath("AutoGenerated", true)
addfiles("./Sources/Tooling/AutoGenerated/*", templates_group, target)
# add linting
lint_phase = target.new_shell_script_build_phase()
lint_phase.name = "Lint Sources ..."
lint_phase.shell_script = %Q(
if which swiftlint >/dev/null; then
swiftlint --config .swiftlint.yml lint ./Sources/
else
echo "warning: SwiftLint not installed!"
fi
)
target.build_phases.move(lint_phase, 0)
# add generating
generate_phase = target.new_shell_script_build_phase()
generate_phase.name = "Generate Sources ..."
generate_phase.shell_script = %Q(
if which sourcery >/dev/null; then
sourcery --sources "./Sources/App"/ --sources "./Sources/Domain"/ --templates "./Sources/Tooling/AutoGenerated/App"/ --output "./Sources/App/[AutoGenerated]"/
sourcery --sources "./Sources/Domain"/ --templates "./Sources/Tooling/AutoGenerated/Domain"/ --output "./Sources/Domain/[AutoGenerated]"/
sourcery --sources "./Tests"/ --templates "./Sources/Tooling/AutoGenerated/Tests/LinuxMain.stencil" --output "./LinuxMain.swift"
else
echo "error: Sourcery not installed!"
fi
)
target.build_phases.move(generate_phase, 0)
end
# Sort build phases
target_name = 'App'
targets_to_sort = project.native_targets.select { |x| x.name == target_name || target_name.nil? }
phases_to_sort = [
Xcodeproj::Project::Object::PBXSourcesBuildPhase,
Xcodeproj::Project::Object::PBXCopyFilesBuildPhase,
Xcodeproj::Project::Object::PBXResourcesBuildPhase
]
targets_to_sort.each do |target|
phases_to_sort.each do |phase_to_sort|
target.build_phases.select { |x| x.class == phase_to_sort }.each do |phase|
phase.files.sort! { |l, r| l.display_name <=> r.display_name }
end
end
end
sources_group = project.groups.find do |group|
group.name == "Sources"
end
sources_group.sort_recursively_by_type()
project.save()