Module: Flappy::UpdatePod
- Included in:
- Flappy::Util::ClassMethods
- Defined in:
- lib/flappy/util/update_pod.rb
Instance Method Summary collapse
-
#check_and_find_podfile ⇒ Object
check.
- #check_and_find_podfile_lock ⇒ Object
- #initialize_pod_cmd(args, options) ⇒ Object
- #merge_spec_hash(spec_hash_podfile, spec_hash_podfile_lock) ⇒ Object
-
#read_podfile ⇒ Object
read.
- #read_podfile_lock ⇒ Object
- #save_pod_file_and_lock ⇒ Object
- #save_spec_hash_to_file ⇒ Object
- #update_pod_if_needed(args, options) ⇒ Object
- #update_pod_repos(args, options) ⇒ Object
Instance Method Details
#check_and_find_podfile ⇒ Object
check
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/flappy/util/update_pod.rb', line 202 def check_and_find_podfile podfile_path = '' Dir.glob("#{@work_dir}/**/[Pp]odfile").each do |name| unless File.directory?(name) podfile_path = name end end if podfile_path.blank? log_iOS('No Podfile Found') else log_iOS("Found Podfile: #{podfile_path}") end podfile_path end |
#check_and_find_podfile_lock ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/flappy/util/update_pod.rb', line 220 def check_and_find_podfile_lock podfile_lock_path = '' Dir.glob("#{@work_dir}/**/[Pp]odfile.lock").each do |name| unless File.directory?(name) podfile_lock_path = name end end if podfile_lock_path.blank? log_iOS('No Podfile.lock Found') else log_iOS("Found Podfile.lock: #{podfile_lock_path}") end podfile_lock_path end |
#initialize_pod_cmd(args, options) ⇒ Object
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 |
# File 'lib/flappy/util/update_pod.rb', line 64 def initialize_pod_cmd(args, ) pod_cmd = '' unless @podfile_path.blank? pod_work_dir = File.dirname(@podfile_path) if [:'update-pod'] || [:'only-update-souche-pod'] pod_cmd = "cd #{pod_work_dir}; " if [:'only-update-souche-pod'] repo_cmd = update_pod_repos(args, ) pod_cmd += repo_cmd unless repo_cmd.blank? # pod repo update之后pod update之前 if [:'pod-env-test'] pod_cmd += "pod_env_test=1 " end pod_cmd += "pod update --no-repo-update --verbose" else # pod repo update之后pod update之前 if [:'pod-env-test'] pod_cmd += "pod_env_test=1 " end if [:'no-repo-update'] pod_cmd += "pod update --no-repo-update --verbose" else pod_cmd += "pod update --verbose" end end end else log_iOS('podfile path is empty') end pod_cmd end |
#merge_spec_hash(spec_hash_podfile, spec_hash_podfile_lock) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/flappy/util/update_pod.rb', line 46 def merge_spec_hash(spec_hash_podfile, spec_hash_podfile_lock) if spec_hash_podfile.blank? || spec_hash_podfile_lock.blank? return end spec_hash_podfile.each do |key_podfile, value_podfile| spec_hash_podfile_lock.each do |key_podfile_lock, value_podfile_lock| if key_podfile == key_podfile_lock spec_hash_merged = value_podfile.merge(value_podfile_lock) spec_hash_podfile.store(key_podfile, spec_hash_merged) break end end end log_iOS("spec_hash: \n#{spec_hash_podfile}") @spec_hash = spec_hash_podfile end |
#read_podfile ⇒ Object
read
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 |
# File 'lib/flappy/util/update_pod.rb', line 106 def read_podfile if @podfile_path.blank? return end spec_hash = {} File.foreach(@podfile_path).with_index do |line, line_num| # 突出显示打印匹配的部分 # puts line.gsub(/^pod .*'$/) { |str| "<<#{str}>>" } # 打印匹配的部分 # line.gsub(/^pod .*'$/) { |str| puts "#{str}" } # puts line.scan(/^pod .*'$/) line_trim = line.gsub(/\s+/, "") unless line.blank? # matched_string = line_trim.scan(/^pod.*'$/)[0] unless line_trim.blank? matched_list = line_trim.scan(/^pod.*'$/) unless line_trim.blank? unless matched_list.nil? matched_string = matched_list[0] if matched_list.count > 0 end unless matched_string.blank? name_version = matched_string.split(/'(.*?)'/) spec_name = name_version[1] podfile_spec_version = name_version[3] unless spec_name.blank? version_hash = {} unless podfile_spec_version.blank? version_hash.store('Podfile', podfile_spec_version) else version_hash.store('Podfile', '') end spec_hash.store(spec_name, version_hash) end end end spec_hash end |
#read_podfile_lock ⇒ Object
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 |
# File 'lib/flappy/util/update_pod.rb', line 147 def read_podfile_lock if @podfile_lock_path.blank? return end textfile = "#{Dir.tmpdir}/podfile_lock_#{Time.now.strftime('%Y%m%d%H%M%S')}.txt" podfile_lock = File.read(@podfile_lock_path) File.open(textfile, "w") do |f| in_header = true podfile_lock.each_line do |line| if in_header && /PODS:/ !~ line next else in_header = false end break if /DEPENDENCIES:/ =~ line f.write line end end spec_hash = {} if File.exists?(textfile) File.foreach(textfile).with_index do |line| unless line.blank? matched_list = line.scan(/^ - .*$/) unless line.blank? unless matched_list.nil? matched_string = matched_list[0] if matched_list.count > 0 unless matched_string.blank? spec_name = matched_string.split(/ - (.*?) \(/)[1] podfile_lock_spec_version = matched_string.split(/ \((.*?)\)/)[1] unless spec_name.blank? version_hash = {} unless podfile_lock_spec_version.blank? version_hash.store('Podfile.lock', podfile_lock_spec_version) else version_hash.store('Podfile.lock', '') end spec_hash.store(spec_name, version_hash) end end end end end end FileUtils.rm_rf(textfile) spec_hash end |
#save_pod_file_and_lock ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/flappy/util/update_pod.rb', line 37 def save_pod_file_and_lock @dest_pod_file_path = File.join(@app_output_archive_info_path, "#{@start_time}_#{@app_dir_name}_Podfile") FileUtils.cp_r(@podfile_path, @dest_pod_file_path) if File.exists?(@podfile_path) @dest_pod_file_lock_path = File.join(@app_output_archive_info_path, "#{@start_time}_#{@app_dir_name}_Podfile_lock") FileUtils.cp_r(@podfile_lock_path, @dest_pod_file_lock_path) if File.exists?(@podfile_lock_path) end |
#save_spec_hash_to_file ⇒ Object
32 33 34 35 |
# File 'lib/flappy/util/update_pod.rb', line 32 def save_spec_hash_to_file @spec_hash_file_path = File.join(@app_output_archive_info_path, "#{@start_time}_#{@app_dir_name}_Pod_json") File.write(@spec_hash_file_path, @spec_hash) unless @spec_hash.blank? end |
#update_pod_if_needed(args, options) ⇒ Object
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 |
# File 'lib/flappy/util/update_pod.rb', line 6 def update_pod_if_needed(args, ) @podfile_path = check_and_find_podfile spec_hash_podfile = read_podfile pod_cmd = initialize_pod_cmd(args, ) unless pod_cmd.blank? log_iOS('>>>>>>>>>>>>>>>>>>>>>>>>>>>> Updating pods......') log_iOS("pod cmd: #{pod_cmd}") log_iOS_pod(pod_cmd) if $?.to_i != 0 log_iOS('>>>>>>>>>>>>>>>>>>>>>>>>>>>> Pod update failed') exit 1 else log_iOS('>>>>>>>>>>>>>>>>>>>>>>>>>>>> Pod update succeed') end end @podfile_lock_path = check_and_find_podfile_lock spec_hash_podfile_lock = read_podfile_lock merge_spec_hash(spec_hash_podfile, spec_hash_podfile_lock) save_spec_hash_to_file save_pod_file_and_lock end |
#update_pod_repos(args, options) ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/flappy/util/update_pod.rb', line 239 def update_pod_repos(args, ) if [:'only-update-souche-pod'] repos_to_update = [] repo_path = File.("~/.cocoapods/repos") Dir.glob(repo_path + "/*").each do |name| # 一层 if File.directory?(name) basename = File.basename(name) if basename != "master" && basename != ".DS_Store" repos_to_update << basename end end end log_iOS("repos_to_update: #{repos_to_update}") repo_cmd = '' repos_to_update.each { |repo| repo_cmd += "pod repo update --verbose #{repo}; " # 只更新souche repo } else repo_cmd = "pod repo update --verbose" end repo_cmd end |