Class: Deliver::CommandsGenerator

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods
Defined in:
deliver/lib/deliver/commands_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.force_overwrite_metadata?(options, path) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'deliver/lib/deliver/commands_generator.rb', line 36

def self.force_overwrite_metadata?(options, path)
  res = options[:force]
  res ||= ENV["DELIVER_FORCE_OVERWRITE"] # for backward compatibility
  res ||= UI.confirm("Do you want to overwrite existing metadata on path '#{File.expand_path(path)}'?") if UI.interactive?
  res
end

.startObject



16
17
18
# File 'deliver/lib/deliver/commands_generator.rb', line 16

def self.start
  self.new.run
end

Instance Method Details

#deliverfile_options(skip_verification: false) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'deliver/lib/deliver/commands_generator.rb', line 20

def deliverfile_options(skip_verification: false)
  available_options = Deliver::Options.available_options
  return available_options unless skip_verification

  # These don't matter for downloading metadata, so verification can be skipped
  irrelevant_options_keys = [:ipa, :pkg, :app_rating_config_path]

  available_options.each do |opt|
    next unless irrelevant_options_keys.include?(opt.key)
    opt.verify_block = nil
    opt.conflicting_options = nil
  end

  return available_options
end

#runObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
94
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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
# File 'deliver/lib/deliver/commands_generator.rb', line 43

def run
  program :name, 'deliver'
  program :version, Fastlane::VERSION
  program :description, Deliver::DESCRIPTION
  program :help, 'Author', 'Felix Krause <[email protected]>'
  program :help, 'Website', 'https://fastlane.tools'
  program :help, 'Documentation', 'https://docs.fastlane.tools/actions/deliver/'
  program :help_formatter, :compact

  global_option('--verbose') { FastlaneCore::Globals.verbose = true }

  always_trace!

  command :run do |c|
    c.syntax = 'fastlane deliver'
    c.description = 'Upload metadata and binary to iTunes Connect'

    FastlaneCore::CommanderGenerator.new.generate(deliverfile_options, command: c)

    c.action do |args, options|
      options = FastlaneCore::Configuration.create(deliverfile_options, options.__hash__)
      loaded = options.load_configuration_file("Deliverfile")

      # Check if we already have a deliver setup in the current directory
      loaded = true if options[:description] || options[:ipa] || options[:pkg]
      loaded = true if File.exist?(File.join(FastlaneCore::FastlaneFolder.path || ".", "metadata"))
      unless loaded
        if UI.confirm("No deliver configuration found in the current directory. Do you want to setup deliver?")
          is_swift = UI.confirm("Would you like to use Swift instead of Ruby?")
          require 'deliver/setup'
          Deliver::Runner.new(options) # to login...
          Deliver::Setup.new.run(options, is_swift: is_swift)
          return 0
        end
      end

      Deliver::Runner.new(options).run
    end
  end

  command :submit_build do |c|
    c.syntax = 'fastlane deliver submit_build'
    c.description = 'Submit a specific build-nr for review, use latest for the latest build'

    FastlaneCore::CommanderGenerator.new.generate(deliverfile_options, command: c)

    c.action do |args, options|
      options = FastlaneCore::Configuration.create(deliverfile_options, options.__hash__)
      options.load_configuration_file("Deliverfile")
      options[:submit_for_review] = true
      options[:build_number] = "latest" unless options[:build_number]
      Deliver::Runner.new(options).run
    end
  end

  command :init do |c|
    c.syntax = 'fastlane deliver init'
    c.description = 'Create the initial `deliver` configuration based on an existing app'

    FastlaneCore::CommanderGenerator.new.generate(deliverfile_options, command: c)

    c.action do |args, options|
      if File.exist?("Deliverfile") || File.exist?("fastlane/Deliverfile")
        UI.important("You already have a running deliver setup in this directory")
        return 0
      end

      require 'deliver/setup'

      options = FastlaneCore::Configuration.create(deliverfile_options, options.__hash__)
      options[:run_precheck_before_submit] = false # precheck doesn't need to run during init

      Deliver::Runner.new(options) # to login...
      Deliver::Setup.new.run(options)
    end
  end

  command :generate_summary do |c|
    c.syntax = 'fastlane deliver generate_summary'
    c.description = 'Generate HTML Summary without uploading/downloading anything'

    FastlaneCore::CommanderGenerator.new.generate(deliverfile_options, command: c)

    c.action do |args, options|
      options = FastlaneCore::Configuration.create(deliverfile_options, options.__hash__)
      options.load_configuration_file("Deliverfile")
      Deliver::Runner.new(options)
      html_path = Deliver::GenerateSummary.new.run(options)
      UI.success("Successfully generated HTML report at '#{html_path}'")
      system("open '#{html_path}'") unless options[:force]
    end
  end

  command :download_screenshots do |c|
    c.syntax = 'fastlane deliver download_screenshots'
    c.description = "Downloads all existing screenshots from iTunes Connect and stores them in the screenshots folder"

    FastlaneCore::CommanderGenerator.new.generate(deliverfile_options, command: c)

    c.action do |args, options|
      options = FastlaneCore::Configuration.create(deliverfile_options(skip_verification: true), options.__hash__)
      options.load_configuration_file("Deliverfile")
      Deliver::Runner.new(options, skip_version: true) # to login...
      containing = FastlaneCore::Helper.fastlane_enabled_folder_path
      path = options[:screenshots_path] || File.join(containing, 'screenshots')
      Deliver::DownloadScreenshots.run(options, path)
    end
  end

  command :download_metadata do |c|
    c.syntax = 'fastlane deliver download_metadata'
    c.description = "Downloads existing metadata and stores it locally. This overwrites the local files."

    FastlaneCore::CommanderGenerator.new.generate(deliverfile_options, command: c)

    c.action do |args, options|
      options = FastlaneCore::Configuration.create(deliverfile_options(skip_verification: true), options.__hash__)
      options.load_configuration_file("Deliverfile")
      Deliver::Runner.new(options) # to login...
      containing = FastlaneCore::Helper.fastlane_enabled_folder_path
      path = options[:metadata_path] || File.join(containing, 'metadata')
      res = Deliver::CommandsGenerator.force_overwrite_metadata?(options, path)
      return 0 unless res

      require 'deliver/setup'
      v = options[:app].latest_version
      if options[:app_version].to_s.length > 0
        v = options[:app].live_version if v.version != options[:app_version]
        if v.version != options[:app_version]
          raise "Neither the current nor live version match specified app_version \"#{options[:app_version]}\""
        end
      end

      Deliver::Setup.new.(v, path)
    end
  end

  default_command(:run)

  run!
end