Module: Appship::Display

Defined in:
lib/appship/builder.rb

Class Method Summary collapse

Class Method Details

.deep_find(value, wanted_key) ⇒ Object



283
284
285
286
287
288
289
290
291
292
293
# File 'lib/appship/builder.rb', line 283

def deep_find(value, wanted_key)
  return nil unless value.is_a?(Hash) || value.is_a?(Array)
  return value[wanted_key] if value.is_a?(Hash) && value.key?(wanted_key)

  enum = value.is_a?(Hash) ? value.values : value
  enum.each do |child|
    found = deep_find(child, wanted_key)
    return found unless found.nil?
  end
  nil
end

.fir_upload_result(result, file:, options: {}) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/appship/builder.rb', line 259

def fir_upload_result(result, file:, options: {})
  data = result["data"].is_a?(Hash) ? result["data"] : result
  name = data["name"] || options[:app_name] || File.basename(file, File.extname(file))
  type = data["type"].to_s == "android" ? "Android" : "iOS"
  version = data["version"]
  build = data["build"]
  version_info = if version && !version.to_s.empty?
                   build && !build.to_s.empty? ? "#{version}(#{build})" : version.to_s
                 end

  puts ""
  puts "======================================================="
  puts "                   🎉 发布完成 🎉                      "
  puts "======================================================="
  puts "分发平台: fir.im"
  puts "应用名称: #{name}"
  puts "应用类型: #{type}"
  puts "版本信息: #{version_info}" if version_info
  puts "更新描述: #{options[:description] || ""}"
  puts "访问密码: #{data["password_protected"] ? "已设置" : "未设置"}"
  puts "下载链接: #{result["url"]}"
  puts "======================================================="
end

.upload_result(result, file:, options: {}) ⇒ Object



215
216
217
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
# File 'lib/appship/builder.rb', line 215

def upload_result(result, file:, options: {})
  if result.is_a?(Hash) && result["provider"] == "fir"
    fir_upload_result(result, file: file, options: options)
    return
  end

  data = result.is_a?(Hash) ? (result["data"] || result) : {}
  key = deep_find(data, "buildKey")
  name = deep_find(data, "buildName") || options[:app_name] || File.basename(file, File.extname(file))
  build_type = deep_find(data, "buildType") || File.extname(file).delete_prefix(".").downcase
  build_type_name = %w[2 apk android].include?(build_type.to_s.downcase) ? "Android" : "iOS"
  version = deep_find(data, "buildVersion")
  build_version = deep_find(data, "buildBuildVersion")
  version_info = if version && !version.to_s.empty?
                   build_version && !build_version.to_s.empty? ? "#{version}(#{build_version})" : version.to_s
                 end
  build_file_size = deep_find(data, "buildFileSize")
  build_size_mb = if build_file_size && !build_file_size.to_s.empty?
                    format("%.1fMB", build_file_size.to_f / 1_048_576)
                  end
  build_updated = deep_find(data, "buildUpdated")
  configuration = options[:configuration] || "未知"
  description = options[:interactive_content] || options[:description] || ""
  password = options[:password]
  password ||= ENV[options[:password_env]] if options[:password_env]
  password ||= "未设置"
  url = key ? "https://www.pgyer.com/#{key}" : "https://www.pgyer.com/"

  puts ""
  puts "======================================================="
  puts "                   🎉 发布完成 🎉                      "
  puts "======================================================="
  puts "应用名称: #{name}"
  puts "应用类型: #{build_type_name}"
  puts "版本信息: #{version_info}" if version_info
  puts "构建模式: #{configuration}"
  puts "应用大小: #{build_size_mb}" if build_size_mb
  puts "更新时间: #{build_updated}" if build_updated && !build_updated.to_s.empty?
  puts "更新描述: #{description}"
  puts "安装密码: #{password}"
  puts "下载链接: #{url}"
  puts "======================================================="
end