-
Notifications
You must be signed in to change notification settings - Fork 5
/
create_example.rb
58 lines (43 loc) · 1.58 KB
/
create_example.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
##!/usr/bin/env ruby
def create_example(name)
project_name = "Example_#{name}"
# create exmaple
`mkdir #{project_name}`
`cp -R ./Template/ ./#{project_name}`
`touch ./#{project_name}/Podfile`
File.open("./#{project_name}/Podfile", 'w') do |file|
content = "use_frameworks!
platform :ios, '10.0'
target 'Template' do
end
"
file.puts content
end
# replace internal project settings
string_replacements = {
'Template' => project_name
}
Dir.glob("./#{project_name}/**/**/**/**").each do |name|
next if Dir.exists? name
text = File.read(name)
string_replacements.each do |find, replace|
text = text.gsub(find, replace)
end
File.open(name, 'w') { |file| file.puts text }
end
# rename files
File.rename("./#{project_name}/TemplateTests/TemplateTests.swift", "./#{project_name}/TemplateTests/#{project_name}Tests.swift")
File.rename("./#{project_name}/TemplateUITests/TemplateUITests.swift", "./#{project_name}/TemplateUITests/#{project_name}UITests.swift")
# rename xcodeproj
File.rename("./#{project_name}/Template.xcodeproj", "./#{project_name}/#{project_name}.xcodeproj")
# rename project folder
File.rename("./#{project_name}/Template", "./#{project_name}/#{project_name}")
File.rename("./#{project_name}/TemplateTests", "./#{project_name}/#{project_name}Tests")
File.rename("./#{project_name}/TemplateUITests", "./#{project_name}/#{project_name}UITests")
Dir.chdir(project_name) do
system "pod install"
system "open ./#{project_name}.xcworkspace"
end
end
example_name = ARGV.shift
create_example(example_name)