Class: BB::PodModule

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb

Constant Summary collapse

@@all_modules =

全部项目配置 => { 全部项目配置 }

[
]
@@member_modules =

个人项目配置 => { 门牌 => { 项目名称, 获取方式, 分支,目标, 版本,} } 匹配全部项目配置 个人配置替换全局配置

{
}
@@member_configs =

成员配置 => { 门牌 => { 项目名称, 获取方式, 分支,目标, 版本,} } 匹配全部项目配置 个人配置替换全局配置

[
]

Instance Method Summary collapse

Constructor Details

#initialize(all_modules, member_modules = {}, member_configs = [], ignore_local_stable = false, skip_stable_check = false, ignore_dependencies_pod_names = []) ⇒ PodModule

pod组件合并 参数说明 all_modules 业务使用组件 member_modules 项目成员模块,一般用于切本地开发使用 member_configs 项目成员工程配置 ignore_local_stable 是否忽略本地stable配置,true 适合pod子组件 skip_stable_check 是否跳过stable检测,true 采用标准pod合并操作 ignore_dependencies_pod_names 过滤组件,不受stable版本控制



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 25

def initialize(all_modules, member_modules = {}, member_configs = [], ignore_local_stable = false, skip_stable_check = false, ignore_dependencies_pod_names=[])
    @source_manager = BB::SourceManager.new()
    BB::DataConfig.config.set_ignore_dependencies_pod_names(ignore_dependencies_pod_names)
    #加载远程稳定仓库 和本地podfile 指定的仓库进行合并
    if skip_stable_check == true
        # 过滤带:remove数据
        @@all_modules = filter_origin_pod_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

Instance Method Details

#convert_local_stable_data(local_stable_data) ⇒ Object

stable本地数据去除指向本地



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 175

def convert_local_stable_data(local_stable_data)
    stable_hash = {}
    local_stable_data.each do |name,pod|
        if pod.is_a? Hash
            path = pod[:path]
            if path
                puts "filter local path data:#{name}".red
            else
                stable_hash[name] = pod
            end
        else
            stable_hash[name] = pod
        end
    end
    return stable_hash
end

#convert_podfile_specs_data(podfile_specs) ⇒ Object

转化数据to hash



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
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
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 119

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]
        remove = pod[:remove]
        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
            if remove
                data[:remove] = remove
                puts "###业务方配置需要移除插件####names:[#{names}] pod:#{pod}".red
            end
            names.each do |pod_name|
                podfile_hash[pod_name] = data
            end
        end
    }
    return podfile_hash
end

#current_all_modulesObject



84
85
86
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 84

def current_all_modules
    return @@all_modules
end

#current_memberObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 54

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_modulesObject



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 70

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 } ]



95
96
97
98
99
100
101
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 95

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



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 105

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

合并组建数据 策略:本地stable作为基础数据,遍历podfile组件进行替换,变化以本地为主,标签以stable为主



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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb', line 193

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={}
    # fix 指向本地组件切换到远端组件,本地yml配置不会更新问题
    stable_hash = convert_local_stable_data(local_stable_data) # stable_hash = local_stable_data
    podfile_hash.each do |podName,podfile_pod|
        if podfile_pod.count == 0
            puts "❌ podfile组件[#{podName}]配置异常,请确认: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 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]
                    remove = podfile_pod[:remove]
                    if remove
                        puts "[PodAssistant] 过滤组件数据 #{podName} #{podfile_pod}".red
                        stable_hash.delete(podCoreName)
                        next
                    end
                    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]
                            stable_path = pod[:path]
                            if stable_git.nil?
                                stable_git = pod[:git_format]
                            end
                            if (stable_branch && !stable_branch.empty?) || (stable_git && !stable_git.empty?) || (stable_path && !stable_path.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') ||  pod.include?(':path')
                                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|
            if pod.is_a? Hash
                remove = pod[:remove]
                if remove
                    puts "[PodAssistant] 过滤组件数据 #{podName} #{pod} remove:#{remove}".red
                    stable_hash.delete(podName)
                    next
                end
            end
            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 "===git===分支==> #{data}".green
                stable_specs.push(data)
            end
        elsif pod.is_a? String
            # puts "===git===标签==> { names: [\"#{name}\"], version: #{pod}, method: REMOTE_TAG }".green
            stable_specs.push({ names: [name], version: pod, method: REMOTE_TAG })
        else
            puts "unknow type [#{name}] data:#{pod}".red
        end
    end
    # puts "[PodAssistant] stable_specs:#{stable_specs}".green
    return stable_specs
end