Class: KCommercial::KCPipeline::RunDemo
- Inherits:
-
Object
- Object
- KCommercial::KCPipeline::RunDemo
- Defined in:
- lib/KCommercialPipeline/core/app_demo.rb
Instance Attribute Summary collapse
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#app_version ⇒ Object
Returns the value of attribute app_version.
-
#build_type ⇒ Object
Returns the value of attribute build_type.
-
#demo_config ⇒ Object
Returns the value of attribute demo_config.
-
#keep_task_id ⇒ Object
Returns the value of attribute keep_task_id.
-
#slices ⇒ Object
Returns the value of attribute slices.
Instance Method Summary collapse
- #change_appspec_config(file_path) ⇒ Object
-
#change_slice_config(file_path) ⇒ Object
修改demo证书配置文件.
- #demo ⇒ Object
-
#initialize(build_type = "Debug", app_id, keep_task_id, slices) ⇒ RunDemo
constructor
A new instance of RunDemo.
- #prepare_build ⇒ Object
-
#read_app_version ⇒ Object
读取SDK版本号.
- #run ⇒ Object
Constructor Details
#initialize(build_type = "Debug", app_id, keep_task_id, slices) ⇒ RunDemo
Returns a new instance of RunDemo.
39 40 41 42 43 44 |
# File 'lib/KCommercialPipeline/core/app_demo.rb', line 39 def initialize(build_type = "Debug",app_id,keep_task_id,slices) @build_type = build_type @app_id = app_id @keep_task_id = keep_task_id || 0 @slices = slices || [] end |
Instance Attribute Details
#app_id ⇒ Object
Returns the value of attribute app_id.
34 35 36 |
# File 'lib/KCommercialPipeline/core/app_demo.rb', line 34 def app_id @app_id end |
#app_version ⇒ Object
Returns the value of attribute app_version.
36 37 38 |
# File 'lib/KCommercialPipeline/core/app_demo.rb', line 36 def app_version @app_version end |
#build_type ⇒ Object
Returns the value of attribute build_type.
33 34 35 |
# File 'lib/KCommercialPipeline/core/app_demo.rb', line 33 def build_type @build_type end |
#demo_config ⇒ Object
Returns the value of attribute demo_config.
35 36 37 |
# File 'lib/KCommercialPipeline/core/app_demo.rb', line 35 def demo_config @demo_config end |
#keep_task_id ⇒ Object
Returns the value of attribute keep_task_id.
37 38 39 |
# File 'lib/KCommercialPipeline/core/app_demo.rb', line 37 def keep_task_id @keep_task_id end |
#slices ⇒ Object
Returns the value of attribute slices.
38 39 40 |
# File 'lib/KCommercialPipeline/core/app_demo.rb', line 38 def slices @slices end |
Instance Method Details
#change_appspec_config(file_path) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/KCommercialPipeline/core/app_demo.rb', line 95 def change_appspec_config(file_path) lines = File.readlines(file_path).map do |line| if line.include? "CocoaDepot::AppSpecification.new do |s|" <<eof CocoaDepot::AppSpecification.new do |s| #ipa包配置 s.export_options = { "compileBitcode" => false, "destination" => "export", "method" => "enterprise", "provisioningProfiles" => { "#{@demo_config.bundle_identifier}" => "#{@demo_config.provisioning_profile}" }, "signingCertificate" => "#{@demo_config.code_sign_identity}", "signingStyle" => "#{@demo_config.code_sign_style}", "teamID" => "#{@demo_config.development_team}", "uploadSymbols" => true } eof elsif line.include?(":name => \"Toggle Build\",") " :name => \"\"" #删除编译脚本,解决报错 elsif line.include?(":script =>") || line.include?(":execution_position => :before_compile,") "##{line}" elsif line.include?("MARKETING_VERSION") unless line.include?(",\n") " \"MARKETING_VERSION\" => \"#{@app_version}\"\n" else " \"MARKETING_VERSION\" => \"#{@app_version}\",\n" end elsif line.include?("CURRENT_PROJECT_VERSION") unless line.include?(",\n") " \"CURRENT_PROJECT_VERSION\" => \"#{@keep_task_id}\"\n" else " \"CURRENT_PROJECT_VERSION\" => \"#{@keep_task_id}\",\n" end else line end end File.open(file_path, "w+") do |file| file.write lines.join("") end end |
#change_slice_config(file_path) ⇒ Object
修改demo证书配置文件
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/KCommercialPipeline/core/app_demo.rb', line 65 def change_slice_config(file_path) lines = File.readlines(file_path).map do |line| if line.include? "slice.main_target do |t|" <<eof slice.main_target do |t| t.bundle_identifier = "#{@demo_config.bundle_identifier}" t.build_settings "Debug" do |debug| debug.code_sign_style = "#{@demo_config.code_sign_style}" debug.code_sign_identity = "#{@demo_config.code_sign_identity}" debug.development_team = "#{@demo_config.development_team}" debug.provisioning_profile = "#{@demo_config.provisioning_profile}" debug.provisioning_profile_specifier = "#{@demo_config.provisioning_profile_specifier}" end t.build_settings "Release" do |release| release.development_team = "#{@demo_config.development_team}" release.code_sign_style = "#{@demo_config.code_sign_style}" release.code_sign_identity = "#{@demo_config.code_sign_identity}" release.provisioning_profile = "#{@demo_config.provisioning_profile}" release.provisioning_profile_specifier = "#{@demo_config.provisioning_profile_specifier}" end eof else line end end File.open(file_path, "w+") do |file| file.write lines.join("") end end |
#demo ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/KCommercialPipeline/core/app_demo.rb', line 139 def demo KCommercial::UI.info "准备打#{@build_type}包..." slice_path = "" unless @slices.empty? paths = @slices.join(",") slice_path = "--slices=#{paths}" end command = "cocoadepot-runner app build -c #{@build_type} #{slice_path} #{@demo_config.demo_name}" KCommercial::UI.debug command KCommercial::UI.info "开始打包......请耐心等待" output = `#{command}` KCommercial::UI.info output unless $?.exitstatus.zero? raise '打包失败' end KCommercial::UI.success "打包成功!" end |
#prepare_build ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/KCommercialPipeline/core/app_demo.rb', line 46 def prepare_build @app_id_ = @app_id || Application.instance.app_id cfg_json = KimConfig.configs["app_build"] raise "未配置#{@app_id} app打包证书" unless cfg_json @demo_config = RunDemoConfig.new(cfg_json) root_path = Pathname(Dir.pwd) app_slice_path = "#{root_path}/Apps/#{demo_config.demo_name}/#{demo_config.demo_name}.slice" app_appspec_path = "#{root_path}/Apps/#{demo_config.demo_name}/#{demo_config.demo_name}.appspec" raise "未配置对应app xcodebuild 配置" unless FileTest.exist?(app_slice_path) || FileTest.exist?(app_appspec_path) @app_version = read_app_version change_slice_config(app_slice_path) change_appspec_config(app_appspec_path) end |
#read_app_version ⇒ Object
读取SDK版本号
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 |
# File 'lib/KCommercialPipeline/core/app_demo.rb', line 158 def read_app_version() = <<EOF "version_cfg" : { "file_path" : "Oversea/KCOverseaAdsUtilities/Auto/Classes/Version/KCOverseaAdsUtilitiesVersion.h", "version_key" : "KCOverseaAdsUtilitiesComponentVersion" } EOF if @demo_config.version_cfg.nil? KCommercial::UI.error "请在根目录.pipeline app_build下添加如下配置#{}" return "1.0.0" end version_file_path = "#{Pathname(Dir.pwd)/@demo_config.version_cfg['file_path']}" version_key = @demo_config.version_cfg['version_key'] if version_file_path.nil? || version_key.nil? KCommercial::UI.error "请在根目录.pipeline app_build下添加如下配置#{}" return "1.0.0" end version_string = "" File.readlines(version_file_path).each do |line| version_string = line if line.include?(version_key) end regular = /@\".*\"/ match_data = version_string.match(regular) app_version = match_data.to_s.gsub!('@','').gsub!('"','') || "1.0.0" app_version end |
#run ⇒ Object
187 188 189 190 |
# File 'lib/KCommercialPipeline/core/app_demo.rb', line 187 def run prepare_build demo end |