class PodsOrz::PodsRepo
Attributes
repo_name[RW]
repo_url[RW]
Public Class Methods
new(main_path)
click to toggle source
# 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
Public Instance Methods
check_repo_exist()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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