Module: Pindo::XcodeAppConfig

Included in:
Command::Deploy::Configproj, Command::Ipa::Import, Command::Ipa::Output
Defined in:
lib/pindo/module/xcode/xcodeappconfig.rb

Instance Method Summary collapse

Instance Method Details

#add_pod_modue(project_dir: nil, pod_name: nil, pod_version: nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/pindo/module/xcode/xcodeappconfig.rb', line 70

def add_pod_modue(project_dir:nil, pod_name:nil, pod_version:nil)
            
    puts "Modify App Podfile: "
    # if File.exist?(File.join(project_dir, "Podfile.lock"))
    #     FileUtils.rm_rf(File.join(project_dir, "Podfile.lock"))
    # end

    pod_file = File.join(project_dir, "Podfile")

    command = 'sed -i "" "/.*' + "AppSource" +'.*/d" ' + pod_file
    system command

    command = 'sed -i "" "/.*' + "QuarkData" +'.*/d" ' + pod_file
    system command

    command = 'sed -i "" "/.*' + "VMData" +'.*/d" ' + pod_file
    system command

    command = 'sed -i "" "/.*' + pod_name +'.*/d" ' + pod_file
    system command

    if File.exist?(File.join(project_dir, "Podfile"))
        puts " #{pod_name} #{pod_version}"
        text = File.read(File.join(project_dir, "Podfile"))

        if pod_version.nil? || pod_version == "" || pod_version.empty?

            if text.include?("FirebaseAnalytics")
                new_contents = text.gsub!(/\'FirebaseAnalytics\'.*$/, "\'FirebaseAnalytics\'\r\n     pod \'#{pod_name}\' ")
            elsif text.include?("UMCommon")
                new_contents = text.gsub!(/\'UMCommon\'.*$/, "\'UMCommon\'\r\n     pod \'#{pod_name}\' ")
            end
        else
            if text.include?("FirebaseAnalytics")
                new_contents = text.gsub!(/\'FirebaseAnalytics\'.*$/, "\'FirebaseAnalytics\'\r\n    pod \'#{pod_name}\', \'#{pod_version}\' ")
            elsif text.include?("UMCommon")
                new_contents = text.gsub!(/\'UMCommon\'.*$/, "\'UMCommon\'\r\n    pod \'#{pod_name}\', \'#{pod_version}\' ")
            end
        end
        File.open(File.join(project_dir, "Podfile"), "w") {|file| file.puts new_contents }
    end  
end

#add_project_modue(project_dir: nil, proj_name: nil, config_json: nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pindo/module/xcode/xcodeappconfig.rb', line 35

def add_project_modue(project_dir:nil, proj_name:nil, config_json:nil)

        module_dict = config_json['project_info']['project_module']
        if !module_dict.nil?
            module_dict.each do |key, module_item|
                # puts module_item
                # puts module_item['module_type'] 
                if module_item && module_item['module_type'] = 'pod'
                    add_pod_modue(project_dir:project_dir, pod_name:key, pod_version:module_item['module_git_tag'])
                elsif module_item && module_item['module_type'] = 'sub_git'
                
                elsif module_item && module_item['module_type'] = 'package'

                end
            end
        end
            
end

#auto_increase_buildnumber(app_config_file: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pindo/module/xcode/xcodeappconfig.rb', line 9

def auto_increase_buildnumber(app_config_file:nil)
    if File.exist?(app_config_file)
        config_json = JSON.parse(File.read(app_config_file))
        app_version = config_json['app_info']['app_version']
        app_build_version = config_json['app_info']['app_build_version']
        
        app_version_array = app_version.split('.') || []
        app_build_version_array = app_build_version.split('.') || []

        while app_build_version_array.size < app_version_array.size + 1  do
            app_version_array << "0"
        end

        last_numer = app_build_version_array.pop.to_s
        new_last_numer = last_numer.to_i + 1
        app_build_version_array << new_last_numer.to_s
        app_build_version = app_build_version_array.join(".")

        config_json['app_info']['app_build_version'] = app_build_version
        File.open(app_config_file, "w") do |file|
            file.write(JSON.pretty_generate(config_json))
            file.close
        end
    end        
end

#find_group(group: nil, group_name: nil) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/pindo/module/xcode/xcodeappconfig.rb', line 114

def find_group(group:nil, group_name:nil)

    if group.display_name == group_name
        return group
    else
        if group.children.count > 0
            group.children.each do |child|
                if Xcodeproj::Project::Object::PBXGroup == child.class
                    result = find_group(group:child, group_name:group_name)
                    if !result.nil?
                        return result
                    end
                end
            end
        end  
        
    end

    return nil
end

#modify_appprefix_plist(project_dir: nil, appprefix_file: nil, config_json: nil) ⇒ Object



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
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
# File 'lib/pindo/module/xcode/xcodeappconfig.rb', line 136

def modify_appprefix_plist(project_dir:nil, appprefix_file:nil, config_json:nil)
    
    project_fullname = Dir.glob(File.join(project_dir, "/*.xcodeproj")).max_by {|f| File.mtime(f)}
    project_obj = Xcodeproj::Project.open(project_fullname) 
    presources_path = nil

    presources_group = find_group(group:project_obj.main_group, group_name:"PResources")
    if presources_group.nil? 
        presources_group = find_group(group:project_obj.main_group, group_name:"PResource")
    end
    if !presources_group.nil? 
        presources_path = presources_group.real_path
    end 

    if presources_path.nil?
        presources_path_array = Dir.glob(File.join(project_dir, "**", "PResources"))
        if presources_path_array.size > 1
            presources_path = presources_path_array.select{ |filename| File.directory?(filename) && filename.end_with?("PResources")}
        elsif presources_path_array.size == 1
            presources_path = presources_path_array.first
        end
    end

    if presources_path.nil?
        presources_path_array = Dir.glob(File.join(project_dir, "**", "PResource"))
        if presources_path_array.size > 1
            presources_path = presources_path_array.select{ |filename| File.directory?(filename) && filename.end_with?("PResource")}
        elsif presources_path_array.size == 1
            presources_path = presources_path_array.first
        end
    end


    if presources_path.nil? || !File.exist?(presources_path)
        raise Informative, "没有找到资源目录PResources !!!!"
    end

    
    config_file = Dir.glob(File.join(presources_path, "**", appprefix_file)).first
    if config_file.nil? || config_file.empty? || !File.exist?(config_file)
        raise Informative, "工程本地配置未修改,PResources/目录下没有找到对应的配置文件 #{appprefix_file} !!!!"
    end 


    config_json['app_setting'].each do |key, value|
        # puts value
        if !value.nil? && value.to_s.include?("__________config")
            raise Informative, "config.json 配置文件key : #{key} 包含初始值未修改, 配置正确的值或者删除!!!"
        end
    end

    xcode_config_value = nil
    if config_file.end_with?(".plist") then
        xcode_config_value = Xcodeproj::Plist.read_from_path(config_file)
    else
        xcode_config_value=JSON.parse(File.read(config_file))
    end

    new_info_plist_dict = {}
    xcode_config_value.each do |key, value|
        if !config_json['app_setting'][key].nil? && config_json['app_setting'][key] != ""
            new_info_plist_dict[key] = config_json['app_setting'][key]
        else
            new_info_plist_dict[key] = value
        end
    end

    if config_file.end_with?(".plist") then
        Xcodeproj::Plist.write_to_path(new_info_plist_dict, config_file)
    else
        File.open(config_file, "w") do |f|
            f.write(JSON.pretty_generate(new_info_plist_dict))
        end
    end
end

#remove_test_pod_modue(project_dir: nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pindo/module/xcode/xcodeappconfig.rb', line 53

def remove_test_pod_modue(project_dir:nil)
    
    pod_file = File.join(project_dir, "Podfile")

    command = 'sed -i "" "/.*' + "FancySettingsPlugin" +'.*/d" ' + pod_file
    system command

    command = 'sed -i "" "/.*' + "TYSettingsPlugin" +'.*/d" ' + pod_file
    system command

    command = 'sed -i "" "/.*' + "CSSettingsPlugin" +'.*/d" ' + pod_file
    system command

    command = 'sed -i "" "/.*' + "FunnySettingsPlugin" +'.*/d" ' + pod_file
    system command
end