appship 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 512f49f01b45fb318992c5dff4df86626d61aea2c57818556763fc869ecee047
4
+ data.tar.gz: 949c652229a3c30bf38d1e0727fb30be191b93e9198da561a7648592a0ca2687
5
+ SHA512:
6
+ metadata.gz: 4884ca69b0efaf1ab59bd0ecd660d755b93c762545b578b6e30547c613d77ee8e65972efa6783aca244c27951980b45506f09cb4005bf27f2f5fa4905220521e
7
+ data.tar.gz: 7a108e44ed054b191a7d6dd5f78316a2cccc49b2298a6f18135d408aecf87e2c8370480ad640c3a1baa6bc2cbbad406f327c1a8b3c34705794838a6717902533
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 YJExpand
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Appship
2
+
3
+ Appship 是一款面向 iOS 开发者的命令行自动化工具,旨在简化应用从构建、打包到内测分发的完整流程。
4
+
5
+ 它支持自动构建和导出 IPA,并将应用上传至蒲公英(Pgyer)或 fir.im,同时提供 API Key、访问密码和项目配置管理。上传完成后,终端会输出应用版本、密码状态及下载链接,方便团队快速进行测试和分发。
6
+
7
+ ### 构建耗时对比
8
+
9
+ ```mermaid
10
+ gantt
11
+ title IPA 构建耗时对比
12
+ dateFormat X
13
+ axisFormat %S 秒
14
+ section 构建方式
15
+ 使用真机缓存包(39.91 秒) :cache, 0, 40
16
+ 重新构建(4 分 1.42 秒) :rebuild, 0, 241
17
+ ```
18
+
19
+ 使用真机缓存包约 ​**39.91 秒**​,重新构建约 ​**4 分 1.42 秒**​,缓存模式约快 ​**6 倍**​。
20
+
21
+ ## 安装
22
+
23
+ ```
24
+ gem install appship
25
+
26
+ export PATH="$(ruby -e 'print Gem.user_dir')/bin:$PATH"
27
+ ```
28
+
29
+ ### 环境依赖
30
+
31
+ 如果需要图标角标,还需要 ImageMagick:
32
+
33
+ ```bash
34
+ brew install imagemagick
35
+ ```
36
+
37
+ 检查环境:
38
+
39
+ ```bash
40
+ appship doctor
41
+ ```
42
+
43
+ ## 快速开始
44
+
45
+ 在 Xcode 工程目录执行:
46
+
47
+ ```bash
48
+ appship pgyer
49
+
50
+ appship fir
51
+ ```
52
+
53
+ 等待片刻...
54
+
55
+ ```
56
+ =======================================================
57
+ 🎉 发布完成 🎉
58
+ =======================================================
59
+ 分发平台: fir.im
60
+ 应用名称: Demo
61
+ 应用类型: iOS
62
+ 版本信息: 1.0.0(42)
63
+ 更新描述: xxx
64
+ 访问密码: xxx
65
+ 下载链接: https://fir.im/abc123
66
+ =======================================================
67
+ ```
68
+
69
+ ## 其他用法
70
+
71
+ 更换安装密码
72
+
73
+ ```
74
+ appship pgyer -password xxx
75
+
76
+ appship fir -password xxx
77
+ ```
78
+
79
+ 更换上传秘钥
80
+
81
+ ```
82
+ appship pgyer -key xxx
83
+
84
+ appship fir -key xxx
85
+ ```
86
+
87
+ ## 待办
88
+
89
+ ```
90
+ 1、补充消息机器人
91
+ 2、自定义消息格式
92
+ 3、其他分发平台
93
+ ...
94
+ ```
data/exe/appship ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "appship"
5
+
6
+ Appship::CLI.start(ARGV)
@@ -0,0 +1,175 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Appship
4
+ module Badger
5
+ module_function
6
+
7
+ def apply!(app, assets:, app_icon:, text:, runner: Runner.new)
8
+ raise ConfigurationError, ".app 不存在: #{app}" unless File.directory?(app)
9
+
10
+ magick = Runner.which("magick") || Runner.which("convert")
11
+ unless magick
12
+ raise ConfigurationError, "添加图标角标需要 ImageMagick(brew install imagemagick)"
13
+ end
14
+ runner.require_command!("xcrun", "需要安装 Xcode")
15
+
16
+ font = resolve_font
17
+ raise ConfigurationError, "未找到可用字体文件,无法生成图标角标" unless font
18
+
19
+ label = text.to_s.strip
20
+ raise ConfigurationError, "角标文字不能为空" if label.empty?
21
+
22
+ modified = regenerate_assets_car!(app, assets, app_icon || "AppIcon", label, magick, font, runner)
23
+ modified ||= badge_loose_icons!(app, label, magick, font, runner)
24
+ raise Error, "未能修改 AppIcon" unless modified
25
+
26
+ resign!(app, runner)
27
+ puts "✅ 已添加 #{label} 图标角标并重新签名"
28
+ true
29
+ end
30
+
31
+ def regenerate_assets_car!(app, assets, app_icon, text, magick, font, runner)
32
+ return false unless assets && File.directory?(assets) && File.file?(File.join(app, "Assets.car"))
33
+ runner.capture!(["xcrun", "--find", "actool"])
34
+
35
+ root = Dir.mktmpdir("appship-assets-")
36
+ begin
37
+ catalog_name = File.basename(File.expand_path(assets))
38
+ copied_catalog = File.join(root, catalog_name)
39
+ FileUtils.cp_r(File.expand_path(assets), copied_catalog)
40
+ icon_set = locate_icon_set(copied_catalog, app_icon)
41
+ return false unless icon_set
42
+
43
+ count = 0
44
+ Dir[File.join(icon_set, "*.png")].each do |png|
45
+ count += 1 if badge_png!(png, text, magick, font, root)
46
+ end
47
+ return false if count.zero?
48
+
49
+ compiled = File.join(root, "compiled")
50
+ FileUtils.mkdir_p(compiled)
51
+ partial = File.join(root, "partial.plist")
52
+ runner.run!(["xcrun", "actool", "--output-format", "human-readable-text", "--app-icon", app_icon,
53
+ "--compile", compiled, "--platform", "iphoneos", "--minimum-deployment-target", "13.0",
54
+ "--target-device", "iphone", "--target-device", "ipad", "--compress-pngs",
55
+ "--output-partial-info-plist", partial, copied_catalog])
56
+ return false unless File.file?(File.join(compiled, "Assets.car"))
57
+
58
+ FileUtils.cp(File.join(compiled, "Assets.car"), File.join(app, "Assets.car"))
59
+ Dir[File.join(compiled, "AppIcon*.png")].each do |png|
60
+ FileUtils.cp(png, app)
61
+ end
62
+ puts " ✅ Assets.car 已重新编译(#{count} 个图标尺寸)"
63
+ true
64
+ rescue CommandError
65
+ puts " ⚠️ Assets.car 重编失败,将尝试处理 IPA 内的松散图标"
66
+ false
67
+ ensure
68
+ FileUtils.rm_rf(root)
69
+ end
70
+ end
71
+
72
+ def badge_loose_icons!(app, text, magick, font, runner)
73
+ work = Dir.mktmpdir("appship-icon-")
74
+ count = 0
75
+ Dir[File.join(app, "**", "AppIcon*.png")].each do |png|
76
+ count += 1 if badge_png!(png, text, magick, font, work)
77
+ end
78
+ puts " ℹ️ 已处理 #{count} 个松散 AppIcon PNG" if count.positive?
79
+ count.positive?
80
+ ensure
81
+ FileUtils.rm_rf(work) if work
82
+ end
83
+
84
+ def locate_icon_set(catalog, app_icon)
85
+ candidate = File.join(catalog, "#{app_icon}.appiconset")
86
+ return candidate if File.directory?(candidate)
87
+
88
+ Dir[File.join(catalog, "**", "*.appiconset")].first
89
+ end
90
+
91
+ def badge_png!(png, text, magick, font, work)
92
+ FileUtils.mkdir_p(work)
93
+ normalized = File.join(work, "normalized-#{Process.pid}-#{File.basename(png)}")
94
+ label = File.join(work, "label-#{Process.pid}-#{File.basename(png)}")
95
+ rotated = File.join(work, "rotated-#{Process.pid}-#{File.basename(png)}")
96
+
97
+ # pngcrush 不是所有 Xcode 环境都提供;ImageMagick 可直接处理普通 PNG。
98
+ FileUtils.cp(png, normalized)
99
+ dimension_output, dimension_status = Open3.capture2(magick, "-format", "%w %h", normalized, "info:")
100
+ return false unless dimension_status.success?
101
+ dimensions = dimension_output.split.map(&:to_i)
102
+ image_width = dimensions[0]
103
+ return false unless image_width && image_width.positive?
104
+
105
+ band_width = [(image_width * 0.60).to_i, 1].max
106
+ band_height = [(image_width * 0.16).to_i, 1].max
107
+ point_size = [(image_width * 0.10).to_i, 8].max
108
+ debug_x = (image_width * 0.60).to_i
109
+ debug_y = -(band_height * 0.8).to_i
110
+
111
+ unless system(magick, "-background", "#4CAF50", "-size", "#{band_width}x#{band_height}", "-pointsize", point_size.to_s,
112
+ "-fill", "white", "-font", font, "-gravity", "center", "caption:#{text}", label,
113
+ out: File::NULL, err: File::NULL)
114
+ return false
115
+ end
116
+ unless system(magick, "-background", "none", label, "-rotate", "45", rotated,
117
+ out: File::NULL, err: File::NULL)
118
+ return false
119
+ end
120
+ unless system(magick, normalized, rotated, "-geometry", "+#{debug_x}+#{debug_y}", "-composite", "-alpha", "remove", png,
121
+ out: File::NULL, err: File::NULL)
122
+ return false
123
+ end
124
+ true
125
+ ensure
126
+ [normalized, label, rotated].compact.each { |file| FileUtils.rm_f(file) }
127
+ end
128
+
129
+ def resolve_font
130
+ candidates = [
131
+ "/System/Library/Fonts/Supplemental/Arial Bold.ttf",
132
+ "/System/Library/Fonts/HelveticaNeue.ttc",
133
+ "/System/Library/Fonts/Helvetica.ttc",
134
+ "/System/Library/Fonts/SFNS.ttf",
135
+ "/Library/Fonts/Arial.ttf"
136
+ ]
137
+ candidates.find { |file| File.file?(file) }
138
+ end
139
+
140
+ def resign!(app, runner)
141
+ codesign_stdout, codesign_stderr, codesign_status = Open3.capture3("codesign", "-dvv", app)
142
+ unless codesign_status.success?
143
+ raise CommandError, "无法读取 App 签名信息: #{codesign_stderr}"
144
+ end
145
+ authority = (codesign_stdout + codesign_stderr).lines.find { |line| line.start_with?("Authority=") }&.split("=", 2)&.last&.strip
146
+ identities = runner.capture!(["security", "find-identity", "-v", "-p", "codesigning"]).lines.filter_map do |line|
147
+ match = line.match(/([0-9A-F]{40})\s+"([^"]+)"/)
148
+ match && { sha: match[1], name: match[2] }
149
+ end
150
+ identity = identities.find { |item| authority && item[:name].include?(authority) } || identities.first
151
+ raise ConfigurationError, "找不到可用的代码签名身份,无法重新签名" unless identity
152
+
153
+ puts " 🔏 重新签名: #{identity[:name]}"
154
+ entitlements = File.join(Dir.mktmpdir("appship-entitlements-"), "entitlements.plist")
155
+ begin
156
+ stdout, _stderr, status = Open3.capture3("codesign", "-d", "--entitlements", ":-", app)
157
+ File.write(entitlements, stdout) if status.success? && !stdout.strip.empty?
158
+
159
+ nested = Dir[File.join(app, "Frameworks", "*")] + Dir[File.join(app, "PlugIns", "*")]
160
+ nested.select! { |path| File.file?(path) || File.directory?(path) }
161
+ nested.sort_by { |path| -path.count(File::SEPARATOR) }.each do |path|
162
+ runner.run!(["codesign", "--force", "--sign", identity[:sha], "--timestamp=none", path])
163
+ end
164
+
165
+ args = ["codesign", "--force", "--sign", identity[:sha], "--timestamp=none"]
166
+ args += ["--entitlements", entitlements] if File.file?(entitlements) && !File.zero?(entitlements)
167
+ args << app
168
+ runner.run!(args)
169
+ runner.run!(["codesign", "--verify", "--deep", "--strict", app])
170
+ ensure
171
+ FileUtils.rm_rf(File.dirname(entitlements))
172
+ end
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,295 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Appship
4
+ class Builder
5
+ attr_reader :runner
6
+
7
+ def initialize(runner: Runner.new)
8
+ @runner = runner
9
+ end
10
+
11
+ def build!(options)
12
+ target = target_options(options)
13
+ scheme = required!(options[:scheme], "--scheme 或配置 scheme")
14
+ configuration = options[:configuration] || "Debug"
15
+ sdk = options[:sdk] || "iphoneos"
16
+ output = File.expand_path(options[:output] || File.join("build", "#{scheme}-#{configuration}.ipa"))
17
+ temp_root = nil
18
+ managed_paths = []
19
+
20
+ if options[:archive_path]
21
+ archive_path = File.expand_path(options[:archive_path])
22
+ else
23
+ temp_root = Dir.mktmpdir("appship-")
24
+ archive_path = File.join(temp_root, "#{scheme}.xcarchive")
25
+ managed_paths << archive_path
26
+ end
27
+
28
+ if options[:export_path]
29
+ export_path = File.expand_path(options[:export_path])
30
+ else
31
+ temp_root ||= Dir.mktmpdir("appship-")
32
+ export_path = File.join(temp_root, "export")
33
+ managed_paths << export_path
34
+ end
35
+
36
+ begin
37
+ runner.require_command!("xcodebuild", "需要安装 Xcode 命令行工具")
38
+ FileUtils.rm_rf(archive_path) if File.exist?(archive_path) && options.fetch(:clean, true)
39
+ FileUtils.rm_rf(export_path) if File.exist?(export_path) && options.fetch(:clean, true)
40
+ FileUtils.mkdir_p(File.dirname(archive_path))
41
+ FileUtils.mkdir_p(export_path)
42
+
43
+ archive!(target, scheme, configuration, sdk, archive_path, options)
44
+ export!(archive_path, export_path, options)
45
+
46
+ ipa = Dir[File.join(export_path, "*.ipa")].first
47
+ raise CommandError, "导出完成但未找到 IPA: #{export_path}" unless ipa
48
+
49
+ final_ipa = File.expand_path(ipa)
50
+ if options[:badge]
51
+ Ipa.apply_badge!(final_ipa, assets: options[:assets], app_icon: options[:app_icon], text: options[:badge], runner: runner)
52
+ end
53
+
54
+ FileUtils.mkdir_p(File.dirname(output))
55
+ unless File.expand_path(output) == final_ipa
56
+ FileUtils.rm_f(output) if File.exist?(output)
57
+ FileUtils.mv(final_ipa, output)
58
+ end
59
+ puts "✅ IPA 已生成: #{output}"
60
+
61
+ upload_if_requested!(output, options)
62
+ output
63
+ ensure
64
+ FileUtils.rm_rf(temp_root) if temp_root && !options[:keep_temporary]
65
+ end
66
+ end
67
+
68
+ def find_cached_app!(options)
69
+ target = target_options(options)
70
+ scheme = required!(options[:scheme], "--scheme 或缓存中的 project_name")
71
+ sdk = options[:sdk] || "iphoneos"
72
+ app_name = required!(options[:app_name], "缓存中的 app_name 或 --app-name")
73
+
74
+ runner.require_command!("xcodebuild", "需要安装 Xcode 命令行工具")
75
+ target_flag = target.keys.first == :workspace ? "-workspace" : "-project"
76
+ configurations = [options[:configuration], "Debug", "Release"].compact.uniq
77
+ configurations.each do |configuration|
78
+ begin
79
+ settings = runner.capture!(["xcodebuild", target_flag, target.values.first, "-scheme", scheme,
80
+ "-configuration", configuration, "-sdk", sdk, "-showBuildSettings"])
81
+ rescue CommandError
82
+ next
83
+ end
84
+ products_dir = settings.lines.filter_map do |line|
85
+ next unless line.include?("BUILT_PRODUCTS_DIR") && line.include?("=")
86
+
87
+ line.split("=", 2).last.strip
88
+ end.first
89
+ next if products_dir.to_s.empty?
90
+
91
+ app_path = File.join(products_dir, "#{app_name}.app")
92
+ next unless File.directory?(app_path)
93
+
94
+ options[:configuration] = configuration
95
+ return app_path
96
+ end
97
+
98
+ raise CommandError, "未找到缓存 App(已检查配置: #{configurations.join(", ")})"
99
+ end
100
+
101
+ def package!(options)
102
+ app = File.expand_path(required!(options[:app], "--app"))
103
+ raise ConfigurationError, ".app 不存在: #{app}" unless File.directory?(app)
104
+
105
+ output = File.expand_path(options[:output] || File.join(Dir.pwd, "#{File.basename(app, ".app")}.ipa"))
106
+ runner.require_command!("zip", "macOS 通常自带 zip")
107
+ runner.require_command!("unzip", "macOS 通常自带 unzip") if options[:badge]
108
+ Ipa.package!(app, output: output, badge: options[:badge], assets: options[:assets], app_icon: options[:app_icon], runner: runner)
109
+ puts "✅ IPA 已生成: #{output}"
110
+ upload_if_requested!(output, options)
111
+ output
112
+ end
113
+
114
+ def upload!(options)
115
+ file = File.expand_path(required!(options[:file], "IPA 文件路径"))
116
+ raise ConfigurationError, "文件不存在: #{file}" unless File.file?(file)
117
+
118
+ result = Uploader.new(options).upload!(file)
119
+ Display.upload_result(result, file: file, options: options)
120
+ result
121
+ end
122
+
123
+ private
124
+
125
+ def target_options(options)
126
+ workspace = options[:workspace]
127
+ project = options[:project]
128
+ if workspace && project
129
+ raise ConfigurationError, "--workspace 和 --project 不能同时指定"
130
+ end
131
+ if workspace.nil? && project.nil?
132
+ raise ConfigurationError, "请指定 --workspace 或 --project"
133
+ end
134
+
135
+ key = workspace ? :workspace : :project
136
+ path = File.expand_path(options[key])
137
+ raise ConfigurationError, "工程文件不存在: #{path}" unless File.exist?(path)
138
+ { key => path }
139
+ end
140
+
141
+ def archive!(target, scheme, configuration, sdk, archive_path, options)
142
+ argv = ["xcodebuild", "archive", target.keys.first == :workspace ? "-workspace" : "-project", target.values.first,
143
+ "-scheme", scheme, "-configuration", configuration, "-sdk", sdk,
144
+ "-destination", "generic/platform=iOS", "-archivePath", archive_path]
145
+ argv += ["-allowProvisioningUpdates"] if options.fetch(:allow_provisioning_updates, true)
146
+ argv += ["-skipPackagePluginValidation"] if options.fetch(:skip_package_plugin_validation, true)
147
+ argv += ["-skipMacroValidation"] if options.fetch(:skip_macro_validation, true)
148
+ argv << "BUILD_ACTIVE_RESOURCES_ONLY=NO"
149
+ puts "🔨 开始归档 #{scheme} (#{configuration})..."
150
+ runner.run!(argv)
151
+ end
152
+
153
+ def export!(archive_path, export_path, options)
154
+ plist_path = options[:export_options_plist]
155
+ temporary_plist = nil
156
+ unless plist_path
157
+ temporary_plist = Tempfile.new(["appship-export-options", ".plist"])
158
+ temporary_plist.write(export_options_plist(options))
159
+ temporary_plist.close
160
+ plist_path = temporary_plist.path
161
+ end
162
+
163
+ argv = ["xcodebuild", "-exportArchive", "-archivePath", archive_path, "-exportPath", export_path,
164
+ "-exportOptionsPlist", File.expand_path(plist_path)]
165
+ argv << "-allowProvisioningUpdates" if options.fetch(:allow_provisioning_updates, true)
166
+ puts "📦 导出 IPA..."
167
+ runner.run!(argv)
168
+ ensure
169
+ temporary_plist&.unlink
170
+ end
171
+
172
+ def export_options_plist(options)
173
+ method = options[:export_method] || "development"
174
+ team_id = options[:team_id]
175
+ team_xml = team_id ? "\n\t<key>teamID</key>\n\t<string>#{xml_escape(team_id)}</string>" : ""
176
+ <<~PLIST
177
+ <?xml version="1.0" encoding="UTF-8"?>
178
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
179
+ <plist version="1.0">
180
+ <dict>
181
+ \t<key>method</key>
182
+ \t<string>#{xml_escape(method)}</string>
183
+ \t<key>signingStyle</key>
184
+ \t<string>#{options[:signing_style] || "automatic"}</string>
185
+ \t<key>compileBitcode</key>
186
+ \t<false/>
187
+ \t<key>thinning</key>
188
+ \t<string>&lt;none&gt;</string>#{team_xml}
189
+ </dict>
190
+ </plist>
191
+ PLIST
192
+ end
193
+
194
+ def upload_if_requested!(file, options)
195
+ return unless options[:upload]
196
+
197
+ result = Uploader.new(options).upload!(file)
198
+ Display.upload_result(result, file: file, options: options)
199
+ end
200
+
201
+ def required!(value, name)
202
+ return value unless value.nil? || value.to_s.empty?
203
+
204
+ raise ConfigurationError, "缺少参数: #{name}"
205
+ end
206
+
207
+ def xml_escape(value)
208
+ value.to_s.gsub("&", "&amp;").gsub("<", "&lt;").gsub(">", "&gt;").gsub('"', "&quot;").gsub("'", "&apos;")
209
+ end
210
+ end
211
+
212
+ module Display
213
+ module_function
214
+
215
+ def upload_result(result, file:, options: {})
216
+ if result.is_a?(Hash) && result["provider"] == "fir"
217
+ fir_upload_result(result, file: file, options: options)
218
+ return
219
+ end
220
+
221
+ data = result.is_a?(Hash) ? (result["data"] || result) : {}
222
+ key = deep_find(data, "buildKey")
223
+ name = deep_find(data, "buildName") || options[:app_name] || File.basename(file, File.extname(file))
224
+ build_type = deep_find(data, "buildType") || File.extname(file).delete_prefix(".").downcase
225
+ build_type_name = %w[2 apk android].include?(build_type.to_s.downcase) ? "Android" : "iOS"
226
+ version = deep_find(data, "buildVersion")
227
+ build_version = deep_find(data, "buildBuildVersion")
228
+ version_info = if version && !version.to_s.empty?
229
+ build_version && !build_version.to_s.empty? ? "#{version}(#{build_version})" : version.to_s
230
+ end
231
+ build_file_size = deep_find(data, "buildFileSize")
232
+ build_size_mb = if build_file_size && !build_file_size.to_s.empty?
233
+ format("%.1fMB", build_file_size.to_f / 1_048_576)
234
+ end
235
+ build_updated = deep_find(data, "buildUpdated")
236
+ configuration = options[:configuration] || "未知"
237
+ description = options[:interactive_content] || options[:description] || ""
238
+ password = options[:password]
239
+ password ||= ENV[options[:password_env]] if options[:password_env]
240
+ password ||= "未设置"
241
+ url = key ? "https://www.pgyer.com/#{key}" : "https://www.pgyer.com/"
242
+
243
+ puts ""
244
+ puts "======================================================="
245
+ puts " 🎉 发布完成 🎉 "
246
+ puts "======================================================="
247
+ puts "应用名称: #{name}"
248
+ puts "应用类型: #{build_type_name}"
249
+ puts "版本信息: #{version_info}" if version_info
250
+ puts "构建模式: #{configuration}"
251
+ puts "应用大小: #{build_size_mb}" if build_size_mb
252
+ puts "更新时间: #{build_updated}" if build_updated && !build_updated.to_s.empty?
253
+ puts "更新描述: #{description}"
254
+ puts "安装密码: #{password}"
255
+ puts "下载链接: #{url}"
256
+ puts "======================================================="
257
+ end
258
+
259
+ def fir_upload_result(result, file:, options: {})
260
+ data = result["data"].is_a?(Hash) ? result["data"] : result
261
+ name = data["name"] || options[:app_name] || File.basename(file, File.extname(file))
262
+ type = data["type"].to_s == "android" ? "Android" : "iOS"
263
+ version = data["version"]
264
+ build = data["build"]
265
+ version_info = if version && !version.to_s.empty?
266
+ build && !build.to_s.empty? ? "#{version}(#{build})" : version.to_s
267
+ end
268
+
269
+ puts ""
270
+ puts "======================================================="
271
+ puts " 🎉 发布完成 🎉 "
272
+ puts "======================================================="
273
+ puts "分发平台: fir.im"
274
+ puts "应用名称: #{name}"
275
+ puts "应用类型: #{type}"
276
+ puts "版本信息: #{version_info}" if version_info
277
+ puts "更新描述: #{options[:description] || ""}"
278
+ puts "访问密码: #{data["password_protected"] ? "已设置" : "未设置"}"
279
+ puts "下载链接: #{result["url"]}"
280
+ puts "======================================================="
281
+ end
282
+
283
+ def deep_find(value, wanted_key)
284
+ return nil unless value.is_a?(Hash) || value.is_a?(Array)
285
+ return value[wanted_key] if value.is_a?(Hash) && value.key?(wanted_key)
286
+
287
+ enum = value.is_a?(Hash) ? value.values : value
288
+ enum.each do |child|
289
+ found = deep_find(child, wanted_key)
290
+ return found unless found.nil?
291
+ end
292
+ nil
293
+ end
294
+ end
295
+ end