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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
# File 'lib/cocoapods-tools/command/spec/tag.rb', line 33
def run
super
podspec_path = ''
find_podspec_path = Pathname.pwd
pod_specs = find_podspec_path.children.select { |pn| pn.extname == '.podspec' }
example_path = Pathname.new("#{find_podspec_path}/Example").expand_path
project_path = example_path.children.select { |pn| pn.extname == '.xcodeproj' }.first
project_name = File.basename(project_path, '.*')
default_name = "#{project_name}.podspec"
podspec_path = default_name
spec_default = "#{project_name}.podspec"
if pod_specs.count > 1
input_tag = true
serial = 0
puts Color.color_text(
"Find #{pod_specs.count} podspec files, please enter the serial number selection:\n(default:#{spec_default})", Color.white)
while input_tag
(0...pod_specs.count).each do |i|
puts "#{i + 1}. #{pod_specs[i]}"
end
serial = $stdin.gets.chomp
input_tag = (serial.to_i > pod_specs.count || serial.to_i <= 0)
if serial.empty?
input_tag = false
podspec_path = spec_default
elsif input_tag
puts "Input serial = #{serial}, it's invalid and you need to input 1~#{pod_specs.count}:"
else
input_tag = false
podspec_path = pod_specs[serial.to_i - 1]
end
end
elsif pod_specs.count == 1
podspec_path = pod_specs.first.split.last
else
puts color_text("Can't find any podspec file", Color.red)
return
end
if !File.exist?(podspec_path)
puts ("找不到 podspec 文件: #{podspec_path}, 请确认当前路径")
return
else
puts "Ready to deal with podspec named #{Color.color_text(podspec_path.to_s, Color.white)}"
end
podspec_dir = File.dirname podspec_path
podspec_absolute_path = "#{find_podspec_path}/#{podspec_path}"
temp_podspec_path = "#{podspec_dir}/need_delete_temp.podspec"
temp_podspec_absolute_path = "#{find_podspec_path}/#{temp_podspec_path}"
cur_version = ''
File.open(podspec_absolute_path, 'r+') do |f|
f.each_line do |line|
version_desc = /.*\.version\s*=.*/.match line
next if version_desc.nil?
cur_version = version_desc.to_s.split('=').last.to_s.gsub("'", '')
cur_version = cur_version.gsub(' ', '')
break
end
end
puts Color.color_text('Current version = ', Color.white) + Color.color_text(cur_version.to_s, Color.green)
if @arguments.count == 1
input_version = @arguments.first
puts Color.color_text "不输入时默认自增。本次已输入,版本号:#{input_version}", Color.white
input_v_s = input_version.to_s.split('.')
cur_v_s = cur_version.split('.')
v_index = 0
input_valid = false
while v_index < cur_v_s.count && v_index < input_v_s.count do
if input_v_s[v_index].to_i > cur_v_s[v_index].to_i
input_valid = true
break
elsif input_v_s[v_index].to_i == cur_v_s[v_index].to_i
v_index += 1
else
break
end
end
puts Color.color_text "版本号 #{input_version} 无效,默认自增", Color.natural if input_valid == false
end
system("touch #{temp_podspec_path}") unless File.exist? temp_podspec_absolute_path
new_version = ''
git_source = ''
File.open(temp_podspec_absolute_path, 'r+') do |t|
File.open(podspec_absolute_path) do |f|
f.each_line do |line|
write_line = line
version_desc = /.*\.version\s*=.*/.match line
unless version_desc.nil?
version_comes = version_desc.to_s.split('=')
if (input_valid == true) && (@arguments.count == 1)
new_version = input_version.to_s
else
version_num = version_comes.last.to_s.gsub("'", '').gsub('"', '').gsub(' ', '')
v_s = version_num.split('.')
(0...v_s.count).each do |i|
new_version += if i == v_s.count - 1
(v_s[i].to_i + 1).to_s
else
"#{v_s[i]}."
end
end
end
puts Color.color_text('New version = ', Color.white) + Color.color_text(new_version.to_s, Color.green)
write_line = "#{version_comes.first}= '#{new_version}'\n"
end
source_desc = /.*\.source\s*=.*/.match line
unless source_desc.nil?
source_desc = /:git.*,/.match source_desc.to_s
source_desc = /'.*'/.match source_desc.to_s
git_source = source_desc.to_s.gsub("'", '')
puts "git source is #{git_source}"
end
t.write write_line
end
end
end
puts Color.color_text('Update version from ',
Color.white) + Color.color_text(cur_version.to_s,
Color.green) + Color.color_text(' to ', Color.white) + Color.color_text(new_version.to_s, Color.green)
system("cp -f #{temp_podspec_path} #{podspec_path}")
system("rm -f #{temp_podspec_path}")
pod_repo_source = 'ssh://[email protected]:7999/third/third_specs.git'
pod_repo_source = 'ssh://[email protected]:7999/third/third_specs.git'
pod_repo_name = pod_repo_source.split('/').last.split('.').first
puts Color.color_text('Start upload code to remote', Color.white)
system("git commit -am 'update version to #{new_version}'")
Color.die_log('[!] git push code error') if system('git push origin master') == false
system("git tag #{new_version}")
if system('git push origin --tags') == false
Color.die_log('[!] git push tags error')
return
end
home_dir ||= Pathname.new(ENV['CP_HOME_DIR'] || '~/.cocoapods').expand_path
specs_git_syn = Pathname.new("#{home_dir}/specs_git_syn").expand_path
FileUtils.mkdir_p(specs_git_syn) unless specs_git_syn.exist?
pod_spec_dir = Pathname.new("#{specs_git_syn}/#{pod_repo_name}").expand_path
Dir.chdir(specs_git_syn) do
system("git clone #{pod_repo_source} #{pod_spec_dir}") unless pod_spec_dir.exist?
pod_repo_dir = Pathname.new("#{pod_spec_dir}/#{project_name}").expand_path
version_dir = Pathname.new("#{pod_repo_dir}/#{new_version.to_s}").expand_path
FileUtils.mkdir_p(version_dir, mode: 0o755)
spec_repo_path = Pathname.new("#{version_dir}/#{podspec_path}").expand_path
system("cp -f #{podspec_absolute_path} #{spec_repo_path}")
Dir.chdir(pod_spec_dir) do
puts Color.color_text("Start push pod '#{pod_spec_dir}' to remote repo '#{pod_repo_name}'", Color.white)
system('git add .')
system("git commit -am 'update version to #{new_version}'")
Color.die_log('[!] git push code error') if system('git push origin master') == false
system("git tag #{new_version}")
if system('git push origin --tags') == false
Color.die_log('[!] git push tags error')
return
end
puts Color.color_text("Update success ☕️! Current version = #{new_version}", Color.green)
end
end
end
|