require 'cocoapods-bb-PodAssistant/config/source_manager' module Pod class Command class Stable < Command class Push < Stable self.summary = '[更新stable组件稳定版本] Update outdated project dependencies and create new ' \ 'Podfile.lock' self.description = <<-DESC 常用命令如下:\n 更新所有公共组件: `pod stable push`\n 更新指定公共组件: `pod stable push <组件名称>`\n 更新指定公共组件/移除组件: `pod stable push <组件名称> --remove=组件名称` #多个移除名称带`,`\n 更新指定公共组件/带依赖关系: `pod stable push <组件名称> --dependencies=组件名称` #多个依赖名称带`,`\n 更新指定公共组件/带依赖关系/移除组件: `pod stable push <组件名称> --dependencies=组件名称 --remove=组件名称` #多个依赖名称带`,`\n 参数说明:--dependencies 依赖组件 --remove 需要移除组件 --update-matrix 更新矩阵产品公共业务线 --update-common 更新公共组件 DESC self.arguments = [ CLAide::Argument.new('POD_NAMES', false, true), ] def self.options [ ['--dependencies', '依赖组件名称,多个使用`,`隔开'], ['--remove', '移除公共组件名称,多个使用`,`隔开'], ['--update-matrix', '更新[矩阵]产品公共业务线,默认true'], ['--update-common', '更新公共组件,默认false'], ].concat(super) end def initialize(argv) @pods = argv.arguments! @dependencies = argv.option('dependencies', nil)&.split(',') @remove = argv.option('remove', nil)&.split(',') @is_pub = argv.flag?('update-common', false) @is_matrix = !@is_pub # argv.flag?('update-matrix', true) super end def run puts "[PodAssistant] 开始执行 $ pod stable push".yellow source_manager = BB::SourceManager.new(false, @is_matrix) cachePath = source_manager.cache_path puts "stable cache git=>#{cachePath}" Dir.chdir(File.join(cachePath)) { # puts "pwd:#{`pwd`}".green path = @is_matrix ? matrix_stable_path : common_stable_path Dir.chdir(File.join(path)) { commit_msg = "" if @pods.any? if (@pods.length > 1) && (@dependencies) puts "❌ 无效指令,不能处理多个组件#{@pods}依赖,更新组件仅支持单组件".red puts "举例:pod stable push <单组件> --dependencies=<多组件>".green puts "详见 pod stable push --help".green system "pod stable push --help" exit elsif (@pods.length == 1) && (@dependencies || @remove) pod_name=@pods.first dependencies_hash = {} if @dependencies dependencies_hash[pod_name] = @dependencies end if @is_matrix source_manager.update_business_dependencies_and_remove_data(dependencies_hash, @remove) else source_manager.update_common_dependencies_and_remove_data(dependencies_hash, @remove) end end pods_str = @pods.join(" ") system "pod stable update #{pods_str}" commit_msg = "update pod #{pods_str}" else if (@dependencies) || (@remove) puts "❌ 无效指令,没有制定组件名称 详见 pod stable push --help".red system "pod stable push --help" exit end system "pod stable update" end # 提交spec本地lock依赖,避免pod stable push <组件>出现组件版本回退问题 source_manager.commit_localspec_data(@is_matrix, commit_msg) } } end # 公共stable目录 private def common_stable_path return File.join(Dir.pwd, 'Common_Stable') end # 全线矩阵产品公共stable目录 private def matrix_stable_path return File.join(Dir.pwd, 'Matrix_Common_Stable') end end end end end