require 'cocoapods-bb-PodAssistant/config/source_manager' module BB class PodModule # 全部项目配置 => { 全部项目配置 } @@all_modules = [ ] # 个人项目配置 => { 门牌 => { 项目名称, 获取方式, 分支,目标, 版本,} } 匹配全部项目配置 个人配置替换全局配置 @@member_modules = { } # 成员配置 => { 门牌 => { 项目名称, 获取方式, 分支,目标, 版本,} } 匹配全部项目配置 个人配置替换全局配置 @@member_configs = [ ] # pod组件合并 # 参数说明 # all_modules 业务使用组件 # member_modules 项目成员模块,一般用于切本地开发使用 # member_configs 项目成员工程配置 # ignore_local_stable 是否忽略本地stable配置,true 适合pod子组件 # skip_stable_check 是否跳过stable检测,true 采用标准pod合并操作 def initialize(all_modules, member_modules = {}, member_configs = [], ignore_local_stable = false, skip_stable_check = false) @source_manager = BB::SourceManager.new() #加载远程稳定仓库 和本地podfile 指定的仓库进行合并 if skip_stable_check == true @@all_modules = all_modules else @@all_modules = load_stable_specs_to_podfile(all_modules, ignore_local_stable) end @@member_modules = member_modules @@member_configs = member_configs end def current_member if @@member_configs @@member_configs.each do | c | if c[:pathes] c[:pathes].each do | p | if File.exist?(p) return c end end end end end return { :name => :podbox_member, :force_local => false, } end def current_member_modules @current_member = self.current_member @current_member_modules = [] if @@member_modules[current_member[:name]] @@member_modules[current_member[:name]].each do | m | if m[:inhibit_warnings] == nil m[:inhibit_warnings] = true end @current_member_modules << m end end return @current_member_modules end def current_all_modules return @@all_modules end ################################# linkline stable ����� ################################# # 格式化podfile 中的specs #[ # { names: "BBGlobalMainModule", version: "1.1.1", method: REMOTE_TAG }, # { names: "xxxx", version: "1.1.2", method: REMOTE_TAG } #] def format_podfile_specs(pods) pods.flat_map do |spec| spec[:names].map do |name| spec.dup.tap { |s| s[:names] = [name] } end end end # 合并stable和podfile 中的specs! ⚠️podfile 中的组件会覆盖stable 中的! # 比如stable 中AFNetworking 指向标签1.1,而 podfile中AFNetworking 指向develop,那么最终AFNetworking 会指向develop def load_stable_specs_to_podfile(podfile_specs, ignore_local_stable = false) puts "[PodAssistant] start process pod module...".yellow local_stable_data = @source_manager.fetch_local_stable_datas # 本地stable配置 if (local_stable_data.is_a? Hash) && !local_stable_data.empty? return merge_module_data(podfile_specs, local_stable_data) else if !ignore_local_stable puts "❌ 没有配置pod stable环境!!! 请先执行`pod stable --init`初始化,再执行pod in/up操作".red exit end end return format_podfile_specs(podfile_specs) end # 转化数据to hash def convert_podfile_specs_data(podfile_specs) podfile_hash = {} podfile_specs.each { |pod| # 对现有pod支持格式进行解析 names = pod[:names] version = pod[:version] method = pod[:method] branch = pod[:branch] git = pod[:git] git_format = pod[:git_format] commit = pod[:commit] linkages = pod[:linkages] linkage = pod[:linkage] if (names.is_a? Array) && !names.empty? data = {} if version data[:version] = version end if method data[:method] = method end if branch data[:branch] = branch end if git data[:git] = git end if git_format if git_format.include?("{git_name}") data[:git_format] = git_format else data[:git] = git_format end end if commit data[:commit] = commit end if linkages data[:linkages] = linkages end if linkage data[:linkage] = linkage end names.each do |pod_name| podfile_hash[pod_name] = data end end } return podfile_hash end # 合并组建数据 # 策略:本地stable作为基础数据,遍历podfile组件进行替换,变化以本地为主,标签以stable为主 def merge_module_data(podfile_specs, local_stable_data) # puts "podfile_specs: #{podfile_specs}".green podfile_hash = convert_podfile_specs_data(podfile_specs) # puts "podfile_hash: #{podfile_hash}".red # puts "local_stable_data: #{local_stable_data}".red need_update_pod_data={} stable_hash = local_stable_data podfile_hash.each do |podName,podfile_pod| if podfile_pod.count == 0 puts "❌ podfile组件配置异常,请确认:method => REMOTE_VERSION是否配置\n组件信息如下:\n#{podName} => #{podfile_pod}".red exit end podCoreName = @source_manager.subspec_podname(podName) if (podName == podCoreName) || @source_manager.has_pod_subspec(podName, podCoreName) pod = stable_hash[podCoreName] if pod.nil? # stbale没有受版本控制 need_update_pod_data[podName] = podfile_pod else # if podCoreName == 'BBGameModule' # succ = (pod == podfile_pod) ? true : false # puts "[stable]podCoreName:#{podCoreName}(#{pod}) VS [podfile] podName:#{podName}(#{podfile_pod}) succ:#{succ}".green # end if pod == podfile_pod if podName != podCoreName need_update_pod_data[podName] = podfile_pod end else branch = podfile_pod[:branch] git = podfile_pod[:git] if git.nil? git = podfile_pod[:git_format] end version = podfile_pod[:version] if (branch && !branch.empty?) || (git && !git.empty?) # 项目配置指向分支数据,以本项目为主 puts "[PodAssistant] #{podName} 指向分支数据 => #{podfile_pod}" stable_hash[podCoreName] = podfile_pod if podName != podCoreName need_update_pod_data[podName] = podfile_pod end elsif (version && !version.empty? && (pod.is_a? String) && (version != pod)) version = version.lstrip # 去除首字母空格 initial_str = version[0..0] # 第一个字母 # 项目配置固定版本,以本项目为主 is_fixed_version = initial_str.include?('=') ? true : false # 固定版本 pod 'A','= x.x.x' is_lessthan_version = version.include?('<') ? true : false # 限制《最高》组件版本 pod 'A','< x.x.x' 或者 pod 'A','<= x.x.x' is_greaterthan_version = version.include?('>') ? true : false # 限制《最低》组件版本 pod 'A','> x.x.x' 或者 pod 'A','>= x.x.x' is_fuzzy_version = version.include?('~>') ? true : false # 固定版本 pod 'A','~> x.x.x' is_fuzzy_versionV2 = (!is_fixed_version && !is_lessthan_version && !is_greaterthan_version && !is_fuzzy_version) ? true : false # 固定版本 pod 'A','x.x.x' if (is_fixed_version == true) || (is_lessthan_version == true) || (is_fuzzy_versionV2 == true) puts "[PodAssistant] ⚠️ 限制组件版本 '#{podName}', '#{version}' 以项目配置为主. (最新版本=> #{pod.send(:red)})" stable_hash[podCoreName] = version if podName != podCoreName need_update_pod_data[podName] = version end elsif (is_greaterthan_version == true) || (is_fuzzy_version == true) # puts "[PodAssistant] '#{podName}', '#{pod.send(:red)}' 以stable配置为主." need_update_pod_data[podName] = pod end else is_podfile_data = false newPod = nil if pod.is_a? (Hash) stable_branch = pod[:branch] stable_git = pod[:git] if stable_git.nil? stable_git = pod[:git_format] end if (stable_branch && !stable_branch.empty?) || (stable_git && !stable_git.empty?) puts "[PodAssistant] '#{podName}', '#{podfile_pod}' 以podfile配置为主[分支=>标签]." newPod = podfile_pod is_podfile_data = true else newPod = pod end elsif pod.is_a? (String) if pod.include?(':branch') || pod.include?(':git') || pod.include?(':git_format') puts "[PodAssistant] '#{podName}', '#{podfile_pod}' 以podfile配置为主[分支=>标签]." newPod = podfile_pod is_podfile_data = true else newPod = pod end else newPod = podfile_pod is_podfile_data = true end if is_podfile_data == true need_update_pod_data[podCoreName] = newPod if podName != podCoreName need_update_pod_data[podName] = newPod end else if podName != podCoreName need_update_pod_data[podName] = newPod end end end end end end end if need_update_pod_data.count > 0 # puts "need_update_pod_data:#{need_update_pod_data}".green # 规避指向分支/远端版本替换yml配置所有组件,避免pod指向指向多个源 need_update_pod_data.each do |podName,pod| stable_hash[podName] = pod puts "[PodAssistant] merge pod #{podName} #{pod}" end else puts "[PodAssistant] 本地stable数据无变化<===完成".yellow end # puts "[PodAssistant] stable_hash:#{stable_hash}".red stable_specs = [] stable_hash.each do |name,pod| if pod.is_a? Hash branch = pod[:branch] git = pod[:git] version = pod[:version] method = pod[:method] git_format = pod[:git_format] commit = pod[:commit] linkages = pod[:linkages] linkage = pod[:linkage] data = { names: [name] } if version data[:version] = version end if method data[:method] = method end if branch data[:branch] = branch end if git data[:git] = git end if git_format data[:git_format] = git_format end if commit data[:commit] = commit end if linkages data[:linkages] = linkages end if linkage data[:linkage] = linkage end if !data.empty? # puts "name:#{name} stable_specs: #{data}".green stable_specs.push(data) end elsif pod.is_a? String stable_specs.push({ names: [name], version: pod, method: REMOTE_TAG }) else puts "unknow type [#{name}] data:#{pod}".red end end return stable_specs end ################################# linkline stable ����� ################################# end end