-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_pod.rb
executable file
·197 lines (164 loc) · 5.15 KB
/
create_pod.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env ruby
#### Constants used in the script
ex_app_path = "./ExampleApp/Podfile"
swiftlint_path = "./.swiftlint.yml"
linting_path = "./fastlane/Linting.fastfile"
gitlab_ci_path = "./.gitlab-ci.yml"
podfile_line_ref = "\n ### create pod protoncore_ios_all_versions placeholder"
podfile_test_line_ref = "\n ### create pod protoncore_unit_tests_all_versions placeholder"
lint_line_ref = " ### create pod add library placeholder"
linting_add_lane_ref = "### create pod add lane placeholder"
linting_all_variant_ref = " ### create pod all variant placeholder"
linting_single_variant_ref = " ### create pod single variant placeholder"
gitlab_ci_single_ref = "### create pod build single variant place holder"
gitlab_ci_all_ref = "### create pod build all variant place holder"
def gitlab_ci_single_add(project_name)
"""build_#{project_name}_single_basic_variant:
script:
- fastlane build_#{project_name}_single_basic_variant
<<: *building_subspecs_lite
"""
end
def gitlab_ci_all_add(project_name)
"""build_#{project_name}_all_variants:
script:
- fastlane build_#{project_name}_all_variants
<<: *building_subspecs_full
"""
end
def new_pod_linting(project_name)
"""lane :build_#{project_name}_all_variants do
install_dependencies_from_gemfile
build_spec(\"#{project_name}\", \"ios,macos\", no_test_podspecs)
end
lane :build_#{project_name}_single_basic_variant do
install_dependencies_from_gemfile
build_spec(\"#{project_name}\", \"ios\", no_test_podspecs)
end
"""
end
def lane_all_variant(project_name)
" build_#{project_name}_all_variants"
end
def lane_single_variant(project_name)
" build_#{project_name}_single_basic_variant"
end
def lint_library(project_name)
" - libraries/#{project_name}"
end
def new_pod(project_name)
" pod \"ProtonCore-#{project_name}\", :path => \"../../\""
end
def pod_test(project_name)
" pod \"ProtonCore-#{project_name}\", :path => \"../../\", :testspecs => [\"Tests\"]"
end
#### ---------------------------
class TemplateEngine
attr_accessor(
:project_name,
:module_pattern
)
def initialize(project_name = "TEMPLATE_NAME")
@project_name = project_name
@module_pattern = 'TEMPLATE_NAME'
end
def create_project
path = "./ProtonCore-#{project_name}.podspec"
new_path = File.basename(path).gsub(@module_pattern, @project_name)
if !File.directory? new_path
replacements = { module_pattern => project_name }
replacements.each do | pattern_to_find, replacement |
text = File.read(new_path)
new_contents = text.gsub(/#{pattern_to_find}/, replacement)
File.open(new_path, "w") {|file| file.puts new_contents }
end
end
end
def add_line_before(path, after_line, line_to_add)
replace(path, /^#{after_line}/) do |match|
"#{line_to_add}\n#{match}"
end
end
def add_same_line(path, regexp, pod_to_add)
replace(path, /^#{regexp}/) do |match|
"#{match}\"#{pod_to_add}\" "
end
end
def replace(filepath, regexp, *args, &block)
content = File.read(filepath).gsub(regexp, *args, &block)
File.open(filepath, 'wb') { |file| file.write(content) }
end
end
class ValidatedCommand
attr_accessor(
:name,
:is_valid
)
def initialize(args)
@is_valid = args.length == 1
@name = args[0]
end
end
command = ValidatedCommand.new(ARGV)
if not command.is_valid
puts 'Usage: ./create_module.sh [POD NAME]'
puts " [POD NAME] is the name of the Pod you're creating."
else
puts "Generating Module"
system("cp ./TEMPLATE.podspec ./ProtonCore-#{ARGV[0]}.podspec")
templateEngine = TemplateEngine.new(ARGV[0])
templateEngine.create_project
puts "Pod Generated"
puts "\n"
puts "Add new pod to ExampleApp Podfile"
templateEngine.add_line_before(
ex_app_path,
podfile_line_ref,
new_pod(templateEngine.project_name)
)
templateEngine.add_line_before(
ex_app_path,
podfile_test_line_ref,
pod_test(templateEngine.project_name)
)
puts "Add new files to linter"
templateEngine.add_line_before(
swiftlint_path,
lint_line_ref,
lint_library(templateEngine.project_name)
)
puts "Add lanes to Linting.fastlane"
templateEngine.add_line_before(
linting_path,
linting_add_lane_ref,
new_pod_linting(templateEngine.project_name)
)
templateEngine.add_line_before(
linting_path,
linting_all_variant_ref,
lane_all_variant(templateEngine.project_name)
)
templateEngine.add_line_before(
linting_path,
linting_single_variant_ref,
lane_single_variant(templateEngine.project_name)
)
puts "Add script to gitlab ci"
templateEngine.add_line_before(
gitlab_ci_path,
gitlab_ci_single_ref,
gitlab_ci_single_add(templateEngine.project_name)
)
templateEngine.add_line_before(
gitlab_ci_path,
gitlab_ci_all_ref,
gitlab_ci_all_add(templateEngine.project_name)
)
puts "\n"
puts "############################################"
puts "################ NEXT STEPS ################"
puts "############################################"
puts "- Add a relevant summary and description in the #{templateEngine.project_name}.podspec file."
puts "- Run the update_pods_in_example_projects.sh script."
puts "\n"
end