class TYCICore::ODMbuild
Attributes
base_branch[RW]
build_branch[RW]
group_name[RW]
group_spec[RW]
template_config[RW]
Public Class Methods
new(template_config, default_config=nil)
click to toggle source
# File lib/tuya/ci/core/odm_build.rb, line 10 def initialize (template_config, default_config=nil) if validate(template_config) # 数据校验通过以后,再进行赋值 @template_config = template_config # 客户选择的模板的配置信息 puts "ODM Builder template is : \n#{@template_config}" @group_name = @template_config["git"]["group"] puts "ODM Builder group name is : #{@group_name}" @group_spec = "#{@group_name}Specs" group_host= @template_config["git"]["host"] @group_spec_url = "#{group_host}/#{@group_name}/#{@group_spec}.git" puts "ODM Builder group spec #{@group_spec} #{@group_spec_url}" @base_branch = @template_config["baseBranch"] puts "ODM Builder base branch is : #{@base_branch}" @build_branch = @template_config["branchName"] puts "ODM Builder target branch is : #{@build_branch}" @default_config = default_config unless default_config.nil? || default_config.empty? # 默认模板的部分配置信息 if @default_config.nil? || @default_config.empty? # 业务类型 1-登录,2-首页,3-场景,4-我的,5-application 100-其他 @default_config = { "1" => { "module" => "TYLoginModule2" }, "2" => { "module" => "TYSmartHouse", "skeleton" => "TYSmartHouseUISkeleton", "biz" => "TYSmartHouseBizKit" }, "3" => { "module" => "TYSmartSceneModule", "biz" => "TYSmartSceneBizKit" }, "4" => { "module" => "TYUserCenterModule", "biz" => "TYUserCenterBizKit" }, "5" => { "module" => "TYSmartApplication" } } end puts "odm builder initial finish".green end end
Public Instance Methods
build()
click to toggle source
# File lib/tuya/ci/core/odm_build.rb, line 78 def build # 开始预编译 raise "template config is invalid".red if @template_config.nil? || @template_config.empty? # 检查、创建分支 check_branch() # 根据备份 重置podfile reset_podfile() # 根据配置 更新podfile 更新modules.json update_podfile_and_moodule_config() # pod update pod_update() # 根据pods,生成config_modules.json中的modules部分 puts "ODM Builder setup_modules in Pods" @module_config.setup_modules() # 更新config_module.json @module_config.save() # if @is_initial TYCiCore::Git.git_commit_modify("feat: ODM builder config update") TYCiCore::Git.git_push puts "ODM builder config commit finish".green # end end
check_branch()
click to toggle source
def test
reset_podfile() update_podfile_and_moodule_config() @module_config.save()
end
# File lib/tuya/ci/core/odm_build.rb, line 115 def check_branch # 切换/创建 分支 TYCiCore::Git.git_checkout_branch(@base_branch) unless TYCiCore::Git.git_current_branch == @base_branch || TYCiCore::Git.git_current_branch == @build_branch TYCiCore::Git.git_checkout_branch(@build_branch) unless TYCiCore::Git.git_current_branch == @build_branch puts "ODM builder checkout branch finish".green end
default_biz_kit_name(type)
click to toggle source
# File lib/tuya/ci/core/odm_build.rb, line 242 def default_biz_kit_name(type) # 根据所给type,返回默认模块的biz名 @default_config[type.to_s]["biz"] unless @default_config[type.to_s].nil? || @default_config[type.to_s].empty? end
default_module_name(type)
click to toggle source
# File lib/tuya/ci/core/odm_build.rb, line 236 def default_module_name(type) # 根据所给type,返回默认模块名 @default_config[type.to_s]["module"] unless @default_config[type.to_s].nil? || @default_config[type.to_s].empty? end
default_skeleton_name(type)
click to toggle source
# File lib/tuya/ci/core/odm_build.rb, line 239 def default_skeleton_name(type) # 根据所给type,返回默认模块的骨架名 @default_config[type.to_s]["skeleton"] unless @default_config[type.to_s].nil? || @default_config[type.to_s].empty? end
pod_update()
click to toggle source
# File lib/tuya/ci/core/odm_build.rb, line 214 def pod_update if @group_spec_url.nil? || @group_spec_url.empty? TYCiCore::EXE.exe('pod', 'update') else home = ENV["HOME"] repo_local = "#{home}/.cocoapods/repos/#{@group_spec}" # TYCiCore::EXE.exe('pod', %W'repo add #{@group_spec} #{@group_spec_url}') unless File.exist?repo_local if !File.exist?repo_local `pod repo add #{@group_spec} #{@group_spec_url}` end pod_commands = [ %W(repo update #{@group_spec}), %W(update --no-repo-update) ] TYCiCore::EXE.multi_exe('pod', pod_commands, true) puts "ODM builder pod update finish".green end end
reset_podfile()
click to toggle source
# File lib/tuya/ci/core/odm_build.rb, line 123 def reset_podfile podfile_backup_path = "./.podfile_backup" podfile_path = "./Podfile" if File.exist? podfile_backup_path podfile = File.open(podfile_path, "w") podfile << File.read(podfile_backup_path) podfile.close else podfile_backup = File.new(podfile_backup_path, "w") podfile_backup << File.read(podfile_path) podfile_backup.close end end
update_podfile_and_moodule_config()
click to toggle source
# File lib/tuya/ci/core/odm_build.rb, line 138 def update_podfile_and_moodule_config @module_config = TYCiCore::ODMConfigModules.new() @module_config.update_config("scheme", @group_name) unless @group_name.nil? || @group_name.empty? @module_config.content["tabs"].clear podfile = TYCiCore::Podfile.new() podfile.source_add(@group_spec_url) unless @group_spec_url.nil? || @group_spec_url.empty? @template_config["groups"].each { |group_info| group = group_info["group"] # 模块分组 1-基础模块 2-Tab模块3-自定义模块 modules = group_info["modules"] modules.each { |module_info| type = module_info["type"] # 业务类型 1-登录,2-首页,3-场景,4-我的,5-application 100-其他 name = module_info["name"] version = module_info["version"] depends = module_info["depends"] if group == 2 @module_config.content["tabs"] << name puts "ODM Builder Add Tabs #{name}" end if type == 1 @module_config.content["login"] = name elsif type == 5 @module_config.content["application"] = name end default_name = default_module_name(type) default_skeleton = default_skeleton_name(type) default_biz = default_biz_kit_name(type) # bizkit暂时不需要移除 pod_add_module = (depends.nil? || depends.empty?) ? Array.new : depends pod_add_module << {"name" => name, "version" => version} pod_delete_module = Array.new pod_delete_module << {"name" => default_skeleton} unless default_skeleton.nil? || default_skeleton.empty? if !default_name.nil? && !default_name.empty? if default_biz.nil? || default_biz.empty? # 添加mix,mix到 default模块 @module_config.add_mix(name, default_name) unless name == default_name else is_dependency = false depends.each {|item| if item["name"] == default_biz is_dependency = true break end } unless depends.nil? || depends.empty? if !is_dependency # 添加mix, mix到 biz模块 (可能是基于sdk开发) @module_config.add_mix(name, default_biz) end pod_delete_module << {"name" => default_name} end end podfile.update(nil, pod_delete_module) unless pod_delete_module.nil? || pod_delete_module.empty? # 确保先删除查,再添加 podfile.update(pod_add_module, nil) unless pod_add_module.nil? || pod_add_module.empty? puts "ODM Builder delteModule:#{pod_delete_module} addedModule:#{pod_add_module}".green unless (pod_delete_module.nil? || pod_delete_module.empty?) && (pod_add_module.nil? || pod_add_module.empty?) } } @module_config.content["tabSelect"] = @module_config.content["tabs"][0] unless @module_config.content["tabs"].nil? || @module_config.content["tabs"].empty? podfile.save puts "ODM builder config update finish".green end
validate(config)
click to toggle source
# File lib/tuya/ci/core/odm_build.rb, line 61 def validate(config) result_bool = false if config.nil? || config.empty? raise "template_config is empty" elsif config["tid"] == 0 raise "tid is necessary in template_config" elsif config["baseBranch"].nil? || config["baseBranch"].empty? raise "base branch is necessary in template_config" elsif config["branchName"].nil? || config["branchName"].empty? raise "branch name is necessary in template_config" else result_bool = true end puts "odm prebuild validate success".green if result_bool result_bool end