Class: PodsOrz::PodsRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/podsorz/core/PodsOrz/pods_repo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(main_path) ⇒ PodsRepo

Returns a new instance of PodsRepo.



10
11
12
13
14
15
16
# File 'lib/podsorz/core/PodsOrz/pods_repo.rb', line 10

def initialize(main_path)
	# @repo_name = "kuxiu_specs"
	# 替换成config配置参数
	@orzconfig_parse = PodsOrz::PodOrzconfigParse.new(main_path)
	@repo_url = @orzconfig_parse.remote_url_codespec
	@repo_name = @orzconfig_parse.file_coderepo_name
end

Instance Attribute Details

#repo_nameObject

Returns the value of attribute repo_name.



8
9
10
# File 'lib/podsorz/core/PodsOrz/pods_repo.rb', line 8

def repo_name
  @repo_name
end

#repo_urlObject

Returns the value of attribute repo_url.



8
9
10
# File 'lib/podsorz/core/PodsOrz/pods_repo.rb', line 8

def repo_url
  @repo_url
end

Instance Method Details

#check_repo_existObject



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
# File 'lib/podsorz/core/PodsOrz/pods_repo.rb', line 18

def check_repo_exist
	command = Thread.new do 
		has_repo = false
		Open3.popen3("pod repo list") do |stdin , stdout , stderr, wait_thr|
	        while line = stdout.gets
	          has_repo = true if line.include? @repo_name
	        end
	    end

		unless has_repo
			Open3.popen3("pod repo add #{@repo_name} #{@repo_url}") do |stdin , stdout , stderr, wait_thr|
		        while line = stdout.gets
			          puts line
			    end
		    end
		end

		Open3.popen3("pod repo update #{@repo_name}") do |stdin , stdout , stderr, wait_thr|
	        while line = stdout.gets
		          puts line
		    end
	    end

		Logger.default("#{@repo_name} is update to latest.")
	end

	command.join
end

#compare_version(pod_version, git_tag) ⇒ Object



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
# File 'lib/podsorz/core/PodsOrz/pods_repo.rb', line 146

def compare_version(pod_version, git_tag)
	#0 => same , -1 => less , 1 => more
	result = 0

	pod_version = pod_version.strip.chomp
	git_tag = git_tag.strip.chomp

	version_parts = pod_version.split('.')
	tag_parts = git_tag.split('.')

	loop_count = 0
	if version_parts.size >= tag_parts.size
		loop_count = version_parts.size - tag_parts.size
		while loop_count > 0 do
			tag_parts << "0"
			loop_count = loop_count - 1
		end
	else
		loop_count = tag_parts.size - version_parts.size
		while loop_count > 0 do
			version_parts << "0"
			loop_count = loop_count - 1
		end
	end

	loop_count = tag_parts.size
	while loop_count > 0 do
		v = version_parts.shift
		t = tag_parts.shift

		if v.to_i > t.to_i
			result = 1
			return result
		elsif v.to_i < t.to_i
			result = -1
			return result
		else
			loop_count = loop_count -1
		end
	end

	return result
	
end

#directory_pod_version(pod, pod_version) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/podsorz/core/PodsOrz/pods_repo.rb', line 89

def directory_pod_version(pod, pod_version)
	directory_result = ""

	dir_kuxiu_specs = "#{Dir.home}/.cocoapods/repos/#{@repo_name}"
	dir_pod_path = File.expand_path("#{pod}", dir_kuxiu_specs)
	is_dir_exist = File.directory?(dir_pod_path)

	unless is_dir_exist
		Logger.warning("#{pod} remote #{pod}\/ directory do not exist")
		return directory_result
	end

	dir_version_path = File.expand_path("#{pod_version}", dir_pod_path)
	is_dir_exist = File.directory?(dir_version_path)
	unless is_dir_exist
		Logger.warning("#{pod}:#{pod_version} remote #{pod}.podspec do not exist")
		return directory_result
	end

	directory_result = dir_version_path

	directory_result
end

#ensure_local_pod_version_tag(pod, pod_version, git_tag) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/podsorz/core/PodsOrz/pods_repo.rb', line 47

def ensure_local_pod_version_tag(pod, pod_version, git_tag)
	#-1 => error or pod_version less than git_tag, 0 => same version, 1 => need add new tag
	compare_result = compare_version(pod_version, git_tag)

	case compare_result
	when 0
		#same
		Logger.default("#{pod}:#{pod_version} same with local git_tag:#{git_tag}")
	when -1
		#less than git_tag
		Logger.error("#{pod}:#{pod_version} is less than git tag:#{git_tag} \n please checkout manual,make sure latest_pod_version = (previous_git_tag +1).It would be great if you could also remove the invalid tag:#{pod_version} this time. It doesn't matter if you don't delete it")
	when 1
		#large than git_tag
		Logger.warning("#{pod}:#{pod_version} large than git_tag:#{git_tag}")
	end

	compare_result
	
end

#ensure_remote_pod_version(pod, pod_version) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/podsorz/core/PodsOrz/pods_repo.rb', line 67

def ensure_remote_pod_version(pod, pod_version)
	remote_version = "0.0.0"
	remote_version = fetch_remote_pod_version(pod)

	#-1 => error or pod_version less than git_tag, 0 => same version, 1 => publish new version
	compare_result = compare_version(pod_version, remote_version)

	case compare_result
	when 0
		#same
		Logger.default("#{pod}:#{pod_version} has nothing to update remote #{@repo_name}")
	when -1
		#less than remote version
		Logger.error("#{pod}:#{pod_version} is less than remote:#{remote_version} \n please checkout manual,make sure local_pod_version = (remote_version +1).It would be great if you could also remove the invalid tag:#{pod_version} this time. It doesn't matter if you don't delete it")
	when 1
		#large than remote version
		Logger.warning("#{pod}:#{pod_version} large than remote:#{remote_version}, will start update remote")
	end

	compare_result
end

#fetch_remote_pod_version(pod) ⇒ Object



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
# File 'lib/podsorz/core/PodsOrz/pods_repo.rb', line 113

def fetch_remote_pod_version(pod)
	version = "0.0.0"

	dir_kuxiu_specs = "#{Dir.home}/.cocoapods/repos/#{@repo_name}"
	dir_pod_path = File.expand_path("#{pod}", dir_kuxiu_specs)
	is_dir_exist = File.directory?(dir_pod_path)

	unless is_dir_exist
		Logger.warning("#{pod} remote spec do not exist, default version: 0.0.0")
		return version 
	end

	filter_list = []
	files_list = Dir.entries(dir_pod_path)
	files_list.each { |e|
		if /^\d{1,3}\.\d{1,3}/ =~ e.to_s
			filter_list << e
		end
	}

	if filter_list.empty?
		Logger.warning("#{pod} remote spec do not exist available version, default version: 0.0.0")
		return version 	
	end

	sort_array = filter_list.sort { |a, b|  
		compare_version(a,b)
	}
	version = sort_array.pop

	return version
end

#push_pod_remote(pod, file_path, pod_version, is_swift) ⇒ Object



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
# File 'lib/podsorz/core/PodsOrz/pods_repo.rb', line 191

def push_pod_remote(pod, file_path, pod_version, is_swift)
	is_push_success = false

	command = Thread.new do 
		repo_push_cmd = []
		repo_push_cmd << "cd #{file_path}"
		if is_swift
			repo_push_cmd << "pod repo push #{@repo_name} #{pod}.podspec --sources=#{@repo_url} --allow-warnings --use-libraries --skip-import-validation --use-modular-headers --swift-version=5.0 --skip-tests"
		else
			repo_push_cmd << "pod repo push #{@repo_name} #{pod}.podspec --sources=#{@repo_url} --allow-warnings --use-libraries --skip-import-validation --skip-tests"	
		end
		

		error_info = []

		Logger.separator()
		Logger.default("#{pod}】:#{pod_version} start push repo remote...")
		Logger.separator()

		IO.popen(repo_push_cmd.join(";")) do |io|	
			io.each do |line|
	            error_info.push(line)
	            is_push_success = true if line.include? "Pushing the `#{@repo_name}' repo"
         	end
        end

        unless is_push_success
            puts error_info
            Logger.error("Fail: \'#{pod}\':#{pod_version} push repo remote fail")
		else
			Logger.highlight(%Q(#{pod}:#{pod_version} push repo success))
         	end
	end

	command.join

        	is_push_success
end