Class: Appship::Builder
- Inherits:
-
Object
- Object
- Appship::Builder
- Defined in:
- lib/appship/builder.rb
Instance Attribute Summary collapse
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
Instance Method Summary collapse
- #build!(options) ⇒ Object
- #find_cached_app!(options) ⇒ Object
-
#initialize(runner: Runner.new) ⇒ Builder
constructor
A new instance of Builder.
- #package!(options) ⇒ Object
- #upload!(options) ⇒ Object
Constructor Details
Instance Attribute Details
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
5 6 7 |
# File 'lib/appship/builder.rb', line 5 def runner @runner end |
Instance Method Details
#build!(options) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/appship/builder.rb', line 11 def build!() target = () scheme = required!([:scheme], "--scheme 或配置 scheme") configuration = [:configuration] || "Debug" sdk = [:sdk] || "iphoneos" output = File.([:output] || File.join("build", "#{scheme}-#{configuration}.ipa")) temp_root = nil managed_paths = [] if [:archive_path] archive_path = File.([:archive_path]) else temp_root = Dir.mktmpdir("appship-") archive_path = File.join(temp_root, "#{scheme}.xcarchive") managed_paths << archive_path end if [:export_path] export_path = File.([:export_path]) else temp_root ||= Dir.mktmpdir("appship-") export_path = File.join(temp_root, "export") managed_paths << export_path end begin runner.require_command!("xcodebuild", "需要安装 Xcode 命令行工具") FileUtils.rm_rf(archive_path) if File.exist?(archive_path) && .fetch(:clean, true) FileUtils.rm_rf(export_path) if File.exist?(export_path) && .fetch(:clean, true) FileUtils.mkdir_p(File.dirname(archive_path)) FileUtils.mkdir_p(export_path) archive!(target, scheme, configuration, sdk, archive_path, ) export!(archive_path, export_path, ) ipa = Dir[File.join(export_path, "*.ipa")].first raise CommandError, "导出完成但未找到 IPA: #{export_path}" unless ipa final_ipa = File.(ipa) if [:badge] Ipa.apply_badge!(final_ipa, assets: [:assets], app_icon: [:app_icon], text: [:badge], runner: runner) end FileUtils.mkdir_p(File.dirname(output)) unless File.(output) == final_ipa FileUtils.rm_f(output) if File.exist?(output) FileUtils.mv(final_ipa, output) end puts "✅ IPA 已生成: #{output}" upload_if_requested!(output, ) output ensure FileUtils.rm_rf(temp_root) if temp_root && ![:keep_temporary] end end |
#find_cached_app!(options) ⇒ Object
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 94 95 96 97 98 99 |
# File 'lib/appship/builder.rb', line 68 def find_cached_app!() target = () scheme = required!([:scheme], "--scheme 或缓存中的 project_name") sdk = [:sdk] || "iphoneos" app_name = required!([:app_name], "缓存中的 app_name 或 --app-name") runner.require_command!("xcodebuild", "需要安装 Xcode 命令行工具") target_flag = target.keys.first == :workspace ? "-workspace" : "-project" configurations = [[:configuration], "Debug", "Release"].compact.uniq configurations.each do |configuration| begin settings = runner.capture!(["xcodebuild", target_flag, target.values.first, "-scheme", scheme, "-configuration", configuration, "-sdk", sdk, "-showBuildSettings"]) rescue CommandError next end products_dir = settings.lines.filter_map do |line| next unless line.include?("BUILT_PRODUCTS_DIR") && line.include?("=") line.split("=", 2).last.strip end.first next if products_dir.to_s.empty? app_path = File.join(products_dir, "#{app_name}.app") next unless File.directory?(app_path) [:configuration] = configuration return app_path end raise CommandError, "未找到缓存 App(已检查配置: #{configurations.join(", ")})" end |
#package!(options) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/appship/builder.rb', line 101 def package!() app = File.(required!([:app], "--app")) raise ConfigurationError, ".app 不存在: #{app}" unless File.directory?(app) output = File.([:output] || File.join(Dir.pwd, "#{File.basename(app, ".app")}.ipa")) runner.require_command!("zip", "macOS 通常自带 zip") runner.require_command!("unzip", "macOS 通常自带 unzip") if [:badge] Ipa.package!(app, output: output, badge: [:badge], assets: [:assets], app_icon: [:app_icon], runner: runner) puts "✅ IPA 已生成: #{output}" upload_if_requested!(output, ) output end |
#upload!(options) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/appship/builder.rb', line 114 def upload!() file = File.(required!([:file], "IPA 文件路径")) raise ConfigurationError, "文件不存在: #{file}" unless File.file?(file) result = Uploader.new().upload!(file) Display.upload_result(result, file: file, options: ) result end |