Class: BB::PodModule

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

Constant Summary collapse

@@all_modules =

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

[
]
@@member_modules =

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

{
}
@@member_configs =

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

[
]

Instance Method Summary collapse

Constructor Details

#initialize(all_modules, member_modules, member_configs) ⇒ PodModule

Returns a new instance of PodModule.



17
18
19
20
21
22
# File 'lib/cocoapods-bb-PodAssistant/helpers/podmodule.rb', line 17

def initialize(all_modules, member_modules, member_configs)
    #加载远程稳定仓库 和本地podfile 指定的仓库进行合并
    @@all_modules = load_stable_specs_to_podfile(all_modules)
    @@member_modules = member_modules
    @@member_configs = member_configs
end

Instance Method Details

#current_all_modulesObject



54
55
56
# File 'lib/cocoapods-bb-PodAssistant/helpers/podmodule.rb', line 54

def current_all_modules
    return @@all_modules
end

#current_memberObject



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

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



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cocoapods-bb-PodAssistant/helpers/podmodule.rb', line 40

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



65
66
67
68
69
70
71
# File 'lib/cocoapods-bb-PodAssistant/helpers/podmodule.rb', line 65

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) ⇒ Object

合并stable和podfile 中的specs! ⚠️podfile 中的组件会覆盖stable 中的! 比如stable 中AFNetworking 指向标签1.1,而 podfile中AFNetworking 指向develop,那么最终AFNetworking 会指向develop



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/cocoapods-bb-PodAssistant/helpers/podmodule.rb', line 75

def load_stable_specs_to_podfile(podfile_specs)
    source_manager = BB::SourceManager.new()
    local_specs = source_manager.fetch_local_stable_datas
    # puts "pod in/up local_specs:#{local_specs}"
    stable_specs = []
    local_specs.each do |name,version|
        stable_specs.push({ names: [name], version: version, method: REMOTE_TAG })
    end
    # puts "pod in/up stable_specs:#{stable_specs}"
    #格式化podfile_specs,方便比较
    podfile_specs = format_podfile_specs(podfile_specs)
    
    #如果podfile 和 stable指定有冲突,优先使用 podfile
    stable_specs.reject! do |stable|
        podfile_specs.any? { |pod|
            podfileName = pod[:names].first.include?('/') ? pod[:names].first.split('/').first.strip : pod[:names].first
            stableName = stable[:names].first
            stableName == podfileName
        }
    end if stable_specs.any?
    
    #podfile 仓库需要格式化之后和远端合并
    return stable_specs + podfile_specs
end