Module: Pindo::XcodeAppConfig
- Included in:
- Command::Appstore::Autobuild
- Defined in:
- lib/pindo/module/xcode/xcode_app_config.rb
Instance Method Summary collapse
- #add_pod_modue(project_dir: nil, pod_name: nil, pod_version: nil) ⇒ Object
- #add_project_modue(project_dir: nil, proj_name: nil, config_json: nil) ⇒ Object
- #auto_increase_buildnumber(app_config_file: nil) ⇒ Object
-
#create_release_tag(project_dir:, config_json:, bundle_id:, delete_tag_name: nil) ⇒ Boolean
创建发布 tag.
- #find_group(group: nil, group_name: nil) ⇒ Object
- #modify_appprefix_plist(project_dir: nil, appprefix_file: nil, config_json: nil) ⇒ Object
- #remove_test_pod_modue(project_dir: nil) ⇒ Object
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/xcode_app_config.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/xcode_app_config.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/xcode_app_config.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 |
#create_release_tag(project_dir:, config_json:, bundle_id:, delete_tag_name: nil) ⇒ Boolean
创建发布 tag
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 |
# File 'lib/pindo/module/xcode/xcode_app_config.rb', line 218 def create_release_tag(project_dir:, config_json:, bundle_id:, delete_tag_name: nil) require 'pindo/base/git_handler' require 'pindo/config/pindoconfig' require_relative '../../base/funlog' begin pindo_dir = File.(Pindo::PindoConfig.pindo_single_config.pindo_dir) app_config_dir = File.join(pindo_dir, bundle_id) # 如果指定了要删除的 tag if !delete_tag_name.nil? && !delete_tag_name.empty? result = Pindo::GitHandler.remove_tag(local_repo_dir: project_dir, tag_name: delete_tag_name) if result puts puts "代码仓库路径#{project_dir}" puts "已删除tag : #{delete_tag_name}" puts puts end result = Pindo::GitHandler.remove_tag(local_repo_dir: app_config_dir, tag_name: delete_tag_name) if result puts puts "配置仓库路径#{app_config_dir}" puts "已删除tag : #{delete_tag_name}" puts puts end end # 创建新的 tag if config_json && config_json["app_info"] && config_json["app_info"]["app_version"] temp_version = config_json["app_info"]["app_version"] else Funlog.instance.("无法从配置中获取 app_version") return false end tag_name = "ios_release_" + temp_version puts tag_name # 为代码仓库创建 tag Pindo::GitHandler.remove_tag(local_repo_dir: project_dir, tag_name: tag_name) result = Pindo::GitHandler.add_tag(local_repo_dir: project_dir, tag_name: tag_name) if result puts puts "代码仓库路径#{project_dir}" puts "已添加tag : #{tag_name}" puts puts end # 为配置仓库创建 tag Pindo::GitHandler.remove_tag(local_repo_dir: app_config_dir, tag_name: tag_name) result = Pindo::GitHandler.add_tag(local_repo_dir: app_config_dir, tag_name: tag_name) if result puts puts "配置仓库路径#{app_config_dir}" puts "已添加tag : #{tag_name}" puts puts end return true rescue StandardError => e Funlog.instance.("创建 tag 失败: #{e.}") puts e.backtrace return false 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/xcode_app_config.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/xcode_app_config.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/xcode_app_config.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 |