module Jxedt module CachePucher def self.push(output_dir, targets=nil, force_push=false) require_relative 'git_command' require_relative 'zip' repo = Jxedt.config.git_remote_repo cache_path = Jxedt.config.git_cache_path branch = Jxedt.config.cache_branch commander = Jxedt::GitCommand.new(cache_path) # fetch commander.git_fetch(repo, branch) output_dir = Pathname.new(output_dir) approve, refuse = [], [] output_dir.children.each do |child| next unless child.directory? pod_name = child.basename.to_s next if targets && targets.is_a?(Array) && targets.size > 0 && !(targets.include?(pod_name)) pod_checksum = child.children.select { |ch| ch.extname == '.checksum' }.first pod_checksum = pod_checksum.basename.sub_ext('').to_s unless pod_checksum.nil? next if pod_checksum.nil? to_dir = Pathname.new(cache_path) + "GeneratedFrameworks" + pod_name to_dir.mkpath unless to_dir.exist? zip_file = to_dir + "#{pod_checksum}.zip" skip = zip_file.exist? && !force_push next refuse << pod_name if skip approve << pod_name Jxedt::ZipUtils.zip(child.to_s, :zip_name => pod_checksum, :to_dir => to_dir) end # push commander.git_commit_and_push(branch) if approve.size > 0 Pod::UI.puts "🎉 组件已缓存成功: #{approve}".yellow if approve.size > 0 Pod::UI.puts "👻 组件缓存失败,存在相同的校验和: #{refuse}".red if refuse.size > 0 end end end