Class: Deliver::DetectValues

Inherits:
Object
  • Object
show all
Defined in:
deliver/lib/deliver/detect_values.rb

Instance Method Summary collapse

Instance Method Details

#ensure_folders_created(options) ⇒ Object



64
65
66
67
# File 'deliver/lib/deliver/detect_values.rb', line 64

def ensure_folders_created(options)
  FileUtils.mkdir_p(options[:screenshots_path])
  FileUtils.mkdir_p(options[:metadata_path])
end

#find_app(options) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'deliver/lib/deliver/detect_values.rb', line 41

def find_app(options)
  app_identifier = options[:app_identifier]
  app_id = options[:app] if app_identifier.to_s.empty?

  if !app_identifier.to_s.empty?
    app = Spaceship::ConnectAPI::App.find(app_identifier)
  elsif !app_id.kind_of?(Spaceship::ConnectAPI::App) && !app_id.to_s.empty?
    app = Spaceship::ConnectAPI::App.get(app_id: app_id)
  end

  Deliver.cache[:app] = app

  unless app
    UI.user_error!("Could not find app with app identifier '#{options[:app_identifier]}' in your App Store Connect account (#{options[:username]} - Team: #{Spaceship::Tunes.client.team_id})")
  end
end

#find_app_identifier(options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'deliver/lib/deliver/detect_values.rb', line 25

def find_app_identifier(options)
  return if options[:app_identifier]

  if options[:ipa]
    identifier = FastlaneCore::IpaFileAnalyser.fetch_app_identifier(options[:ipa])
  elsif options[:pkg]
    identifier = FastlaneCore::PkgFileAnalyser.fetch_app_identifier(options[:pkg])
  end

  options[:app_identifier] = identifier if identifier.to_s.length > 0
  options[:app_identifier] ||= UI.input("The Bundle Identifier of your App: ")
rescue => ex
  UI.error("#{ex.message}\n#{ex.backtrace.join('\n')}")
  UI.user_error!("Could not infer your App's Bundle Identifier")
end

#find_folders(options) ⇒ Object



58
59
60
61
62
# File 'deliver/lib/deliver/detect_values.rb', line 58

def find_folders(options)
  containing = Helper.fastlane_enabled? ? FastlaneCore::FastlaneFolder.path : '.'
  options[:screenshots_path] ||= File.join(containing, 'screenshots')
  options[:metadata_path] ||= File.join(containing, 'metadata')
end

#find_platform(options) ⇒ Object



82
83
84
85
86
87
88
# File 'deliver/lib/deliver/detect_values.rb', line 82

def find_platform(options)
  if options[:ipa]
    options[:platform] ||= FastlaneCore::IpaFileAnalyser.fetch_app_platform(options[:ipa])
  elsif options[:pkg]
    options[:platform] = 'osx'
  end
end

#find_version(options) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'deliver/lib/deliver/detect_values.rb', line 69

def find_version(options)
  return if options[:app_version]

  if options[:ipa]
    options[:app_version] ||= FastlaneCore::IpaFileAnalyser.fetch_app_version(options[:ipa])
  elsif options[:pkg]
    options[:app_version] ||= FastlaneCore::PkgFileAnalyser.fetch_app_version(options[:pkg])
  end
rescue => ex
  UI.error("#{ex.message}\n#{ex.backtrace.join('\n')}")
  UI.user_error!("Could not infer your app's version")
end

#run!(options, skip_params = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'deliver/lib/deliver/detect_values.rb', line 12

def run!(options, skip_params = {})
  Deliver.cache = {}

  find_platform(options)
  find_app_identifier(options)
  find_app(options)
  find_folders(options)
  ensure_folders_created(options)
  find_version(options) unless skip_params[:skip_version]

  verify_languages!(options)
end

#verify_languages!(options) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'deliver/lib/deliver/detect_values.rb', line 90

def verify_languages!(options)
  languages = options[:languages]
  return unless languages

  # 2020-08-24 - Available locales are not available as an endpoint in App Store Connect
  # Update with Spaceship::Tunes.client.available_languages.sort (as long as endpoint is available)
  all_languages = Deliver::Languages::ALL_LANGUAGES
  diff = languages - all_languages

  unless diff.empty?
    UI.user_error!("The following languages are invalid and cannot be activated: #{diff.join(',')}\n\nValid languages are: #{all_languages}")
  end
end