Class: BB::PodModule
- Inherits:
-
Object
- Object
- BB::PodModule
- Defined in:
- lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb
Constant Summary collapse
- @@all_modules =
全部项目配置 => { 全部项目配置 }
[ ]
- @@member_modules =
个人项目配置 => { 门牌 => { 项目名称, 获取方式, 分支,目标, 版本,} } 匹配全部项目配置 个人配置替换全局配置
{ }
- @@member_configs =
成员配置 => { 门牌 => { 项目名称, 获取方式, 分支,目标, 版本,} } 匹配全部项目配置 个人配置替换全局配置
[ ]
Instance Method Summary collapse
-
#convert_podfile_specs_data(podfile_specs) ⇒ Object
转化数据to hash.
- #current_all_modules ⇒ Object
- #current_member ⇒ Object
- #current_member_modules ⇒ Object
-
#format_podfile_specs(pods) ⇒ Object
linkline stable ����� ################################# 格式化podfile 中的specs [ { names: “BBGlobalMainModule”, version: “1.1.1”, method: REMOTE_TAG }, { names: “xxxx”, version: “1.1.2”, method: REMOTE_TAG } ].
-
#initialize(all_modules, member_modules, member_configs, ignore_local_stable = false, skip_stable_check = false) ⇒ PodModule
constructor
A new instance of PodModule.
-
#load_stable_specs_to_podfile(podfile_specs, ignore_local_stable = false) ⇒ Object
合并stable和podfile 中的specs! ⚠️podfile 中的组件会覆盖stable 中的! 比如stable 中AFNetworking 指向标签1.1,而 podfile中AFNetworking 指向develop,那么最终AFNetworking 会指向develop.
- #merge_module_data(podfile_specs, local_stable_data) ⇒ Object
Constructor Details
#initialize(all_modules, member_modules, member_configs, ignore_local_stable = false, skip_stable_check = false) ⇒ PodModule
Returns a new instance of PodModule.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 17 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 # puts "member_modules:#{member_modules}" end |
Instance Method Details
#convert_podfile_specs_data(podfile_specs) ⇒ Object
转化数据to hash
95 96 97 98 99 100 101 102 103 104 105 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 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 95 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 |
#current_all_modules ⇒ Object
60 61 62 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 60 def current_all_modules return @@all_modules end |
#current_member ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 30 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 |
#current_member_modules ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 46 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 |
#format_podfile_specs(pods) ⇒ Object
linkline stable ����� ################################# 格式化podfile 中的specs [ { names: “BBGlobalMainModule”, version: “1.1.1”, method: REMOTE_TAG }, { names: “xxxx”, version: “1.1.2”, method: REMOTE_TAG } ]
71 72 73 74 75 76 77 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 71 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 |
#load_stable_specs_to_podfile(podfile_specs, ignore_local_stable = false) ⇒ Object
合并stable和podfile 中的specs! ⚠️podfile 中的组件会覆盖stable 中的!比如stable 中AFNetworking 指向标签1.1,而 podfile中AFNetworking 指向develop,那么最终AFNetworking 会指向develop
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 81 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 |
#merge_module_data(podfile_specs, local_stable_data) ⇒ Object
145 146 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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 145 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={} podfile_hash.each do |podName,pod| local_pod_data = local_stable_data[podName] if pod != local_pod_data branch = pod[:branch] git_format = pod[:git_format] version = pod[:version] podCoreName = @source_manager.subspec_podname(podName) # puts "podName:#{podName} pod:#{pod} branch:#{branch} git_format:#{git_format} version:#{version} local_pod_data:#{local_pod_data}".green if (branch && !branch.empty?) || (git_format && !git_format.empty?) # 项目配置指向分支数据,以本项目为主 puts "[PodAssistant] #{podName} 指向分支数据 => #{pod}" need_update_pod_data[podCoreName] = pod end # succ = (version && !version.empty? && (local_pod_data.is_a? String) && (version != local_pod_data) && !version.include?(local_pod_data)) # puts "podName:#{podName} version:#{version} succ=#{succ}".red if (version && !version.empty? && (local_pod_data.is_a? String) && (version != local_pod_data) && !version.include?(local_pod_data)) 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_version == true) || (is_fuzzy_versionV2 == true) puts "[PodAssistant] ⚠️ 限制组件版本 '#{podName}', '#{version}' 以项目配置为主. (最新版本=> #{local_pod_data.send(:red)})" need_update_pod_data[podCoreName] = version 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 |podCoreName,pod| local_stable_data.keys.each do |podName| if (podName == podCoreName) || @source_manager.has_pod_subspec(podName, podCoreName) local_stable_data[podName] = pod puts "[PodAssistant] 合并组件 #{podName} #{pod} 以项目为主".yellow end end end puts "[PodAssistant] 重新保存本地stable数据".yellow @source_manager.update_localstable_datas(local_stable_data) else puts "[PodAssistant] 本地stable数据无变化<===完成".yellow end # puts "local_stable_data: #{local_stable_data}".red stable_specs = [] local_stable_data.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 data:#{pod}".red end end return stable_specs end |