forked from orlandos-nl/MongoKitten
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GenerateXcodeproj.rb
executable file
·55 lines (42 loc) · 1.68 KB
/
GenerateXcodeproj.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
#!/usr/bin/ruby
require 'xcodeproj'
puts "Generating Xcode project using SPM"
system "swift package generate-xcodeproj"
puts "Opening generated xcodeproj"
path_to_project = "MongoKitten.xcodeproj"
project = Xcodeproj::Project.open(path_to_project)
puts "Adding additional files to project"
readme_reference = project.main_group.new_reference("README.md")
project.main_group.children.move(readme_reference, 0)
if File.exists?("MongoKitten.playground")
puts "Adding playground to project"
project.main_group.new_reference("MongoKitten.playground")
end
config_group = project.new_group("Configuration files and scripts")
Dir.foreach('.') do |item|
if item.end_with? ".md" and item != "README.md"
item_reference = project.main_group.new_reference(item)
project.main_group.children.move(item_reference, 1) # Move markdown files to the top, after the readme
elsif item.end_with? ".rb" or item.end_with? ".sh" or item.end_with? ".yml" or item.end_with? ".yaml" or item.end_with? ".json"
config_group.new_reference(item)
end
end
puts "Adding build phases"
target = project.targets.select { |target| target.name == 'MongoKitten' }.first
# Add script phase for Sourcery
phase = target.new_shell_script_build_phase()
phase.name = "Codegen"
phase.shell_script = "./Codegen.sh"
target.build_phases.move(phase, 0) # Codegen must happen before compilation
# Add script phase for SwiftLint
phase = target.new_shell_script_build_phase()
phase.name = "SwiftLint"
phase.shell_script = <<-SCRIPT
if which swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
SCRIPT
project.save()
puts "Done"