Class: Fastlane::SetupIos
- Inherits:
-
Setup
- Object
- Setup
- Fastlane::SetupIos
show all
- Defined in:
- lib/fastlane/setup/setup_ios.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Setup
#is_android?, #is_ios?, #show_analytics
Instance Attribute Details
#app_identifier ⇒ Object
Returns the value of attribute app_identifier.
14
15
16
|
# File 'lib/fastlane/setup/setup_ios.rb', line 14
def app_identifier
@app_identifier
end
|
#app_name ⇒ Object
Returns the value of attribute app_name.
15
16
17
|
# File 'lib/fastlane/setup/setup_ios.rb', line 15
def app_name
@app_name
end
|
#apple_id ⇒ Object
Returns the value of attribute apple_id.
6
7
8
|
# File 'lib/fastlane/setup/setup_ios.rb', line 6
def apple_id
@apple_id
end
|
#dev_portal_team ⇒ Object
Returns the value of attribute dev_portal_team.
11
12
13
|
# File 'lib/fastlane/setup/setup_ios.rb', line 11
def dev_portal_team
@dev_portal_team
end
|
#itc_ref ⇒ Object
Returns the value of attribute itc_ref.
9
10
11
|
# File 'lib/fastlane/setup/setup_ios.rb', line 9
def itc_ref
@itc_ref
end
|
#itc_team ⇒ Object
Returns the value of attribute itc_team.
12
13
14
|
# File 'lib/fastlane/setup/setup_ios.rb', line 12
def itc_team
@itc_team
end
|
#portal_ref ⇒ Object
Returns the value of attribute portal_ref.
8
9
10
|
# File 'lib/fastlane/setup/setup_ios.rb', line 8
def portal_ref
@portal_ref
end
|
#project ⇒ Object
Returns the value of attribute project.
5
6
7
|
# File 'lib/fastlane/setup/setup_ios.rb', line 5
def project
@project
end
|
the tools that are already enabled
4
5
6
|
# File 'lib/fastlane/setup/setup_ios.rb', line 4
def tools
@tools
end
|
Instance Method Details
#ask_for_app_identifier ⇒ Object
154
155
156
|
# File 'lib/fastlane/setup/setup_ios.rb', line 154
def ask_for_app_identifier
self.app_identifier = UI.input("App Identifier (com.krausefx.app): ")
end
|
#ask_for_apple_id ⇒ Object
150
151
152
|
# File 'lib/fastlane/setup/setup_ios.rb', line 150
def ask_for_apple_id
self.apple_id ||= UI.input("Your Apple ID (e.g. [email protected]): ")
end
|
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/fastlane/setup/setup_ios.rb', line 87
def ask_to_enable_other_tools
if self.itc_ref.nil? && self.portal_ref.nil?
wants_to_create_app = agree('Would you like to create your app on iTunes Connect and the Developer Portal? (y/n)', true)
if wants_to_create_app
create_app_if_necessary
detect_if_app_is_available end
end
if self.itc_ref && self.portal_ref
wants_to_setup_deliver = agree("Do you want to setup 'deliver', which is used to upload app screenshots, app metadata and app updates to the App Store? This requires the app to be in the App Store already. (y/n)".yellow, true)
enable_deliver if wants_to_setup_deliver
end
end
|
#copy_existing_files ⇒ Object
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/fastlane/setup/setup_ios.rb', line 139
def copy_existing_files
files_to_copy.each do |current|
current = File.join(File.expand_path('..', FastlaneFolder.path), current)
next unless File.exist?(current)
file_name = File.basename(current)
to_path = File.join(folder, file_name)
UI.success("Moving '#{current}' to '#{to_path}'")
FileUtils.mv(current, to_path)
end
end
|
#create_app_if_necessary ⇒ Object
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/fastlane/setup/setup_ios.rb', line 193
def create_app_if_necessary
UI.important "Creating the app on iTunes Connect and the Apple Developer Portal"
require 'produce'
config = {} FastlaneCore::Project.detect_projects(config)
project = FastlaneCore::Project.new(config)
produce_options_hash = {
app_name: project.app_name,
app_identifier: self.app_identifier
}
Produce.config = FastlaneCore::Configuration.create(Produce::Options.available_options, produce_options_hash)
begin
ENV['PRODUCE_APPLE_ID'] = Produce::Manager.start_producing
rescue => exception
if exception.to_s.include?("The App Name you entered has already been used")
UI.important("It looks like that #{project.app_name} has already been taken by someone else, please enter an alternative.")
Produce.config[:app_name] = UI.input("App Name: ")
Produce.config[:skip_devcenter] = true ENV['PRODUCE_APPLE_ID'] = Produce::Manager.start_producing
end
end
end
|
#default_setup ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/fastlane/setup/setup_ios.rb', line 66
def default_setup
copy_existing_files
generate_appfile(manually: false)
detect_installed_tools if self.itc_ref.nil? && self.portal_ref.nil?
create_app_if_necessary
end
enable_deliver
generate_fastfile(manually: false)
show_analytics
end
|
#detect_if_app_is_available ⇒ Object
Detect if the app was created on the Dev Portal / iTC
179
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/fastlane/setup/setup_ios.rb', line 179
def detect_if_app_is_available
require 'spaceship'
UI.important "Verifying if app is available on the Apple Developer Portal and iTunes Connect..."
UI.message "Starting login with user '#{self.apple_id}'"
Spaceship.login(self.apple_id, nil)
self.dev_portal_team = Spaceship.select_team
self.portal_ref = Spaceship::App.find(self.app_identifier)
Spaceship::Tunes.login(@apple_id, nil)
self.itc_team = Spaceship::Tunes.select_team
self.itc_ref = Spaceship::Application.find(self.app_identifier)
end
|
217
218
219
220
221
222
|
# File 'lib/fastlane/setup/setup_ios.rb', line 217
def detect_installed_tools
self.tools = {}
self.tools[:snapshot] = File.exist?(File.join(folder, 'Snapfile'))
self.tools[:cocoapods] = File.exist?(File.join(File.expand_path('..', folder), 'Podfile'))
self.tools[:carthage] = File.exist?(File.join(File.expand_path('..', folder), 'Cartfile'))
end
|
#enable_deliver ⇒ Object
224
225
226
227
228
229
230
231
|
# File 'lib/fastlane/setup/setup_ios.rb', line 224
def enable_deliver
UI.message("Loading up 'deliver', this might take a few seconds")
require 'deliver'
require 'deliver/setup'
options = FastlaneCore::Configuration.create(Deliver::Options.available_options, {})
Deliver::Runner.new(options) Deliver::Setup.new.run(options)
end
|
#files_to_copy ⇒ Object
135
136
137
|
# File 'lib/fastlane/setup/setup_ios.rb', line 135
def files_to_copy
['Deliverfile', 'deliver', 'screenshots', 'metadata']
end
|
#folder ⇒ Object
260
261
262
|
# File 'lib/fastlane/setup/setup_ios.rb', line 260
def folder
FastlaneFolder.path
end
|
#generate_appfile(manually: false) ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/fastlane/setup/setup_ios.rb', line 158
def generate_appfile(manually: false)
template = File.read("#{Fastlane::ROOT}/lib/assets/AppfileTemplate")
if manually
ask_for_app_identifier
ask_for_apple_id
end
template.gsub!('[[DEV_PORTAL_TEAM_ID]]', self.dev_portal_team) if self.dev_portal_team
itc_team = self.itc_team ? "itc_team_id \"#{self.itc_team}\" # iTunes Connect Team ID\n" : ""
template.gsub!('[[ITC_TEAM]]', itc_team)
template.gsub!('[[APP_IDENTIFIER]]', self.app_identifier)
template.gsub!('[[APPLE_ID]]', self.apple_id)
path = File.join(folder, 'Appfile')
File.write(path, template)
UI.success("Created new file '#{path}'. Edit it to manage your preferred app metadata information.")
end
|
#generate_fastfile(manually: false) ⇒ Object
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
258
|
# File 'lib/fastlane/setup/setup_ios.rb', line 233
def generate_fastfile(manually: false)
scheme = self.project.schemes.first unless manually
template = File.read("#{Fastlane::ROOT}/lib/assets/DefaultFastfileTemplate")
scheme = UI.input("Optional: The scheme name of your app (If you don't need one, just hit Enter): ") unless scheme
if scheme.length > 0
template.gsub!('[[SCHEME]]', "(scheme: \"#{scheme}\")")
else
template.gsub!('[[SCHEME]]', "")
end
template.gsub!('snapshot', '# snapshot') unless self.tools[:snapshot]
template.gsub!('cocoapods', '') unless self.tools[:cocoapods]
template.gsub!('carthage', '') unless self.tools[:carthage]
template.gsub!('[[FASTLANE_VERSION]]', Fastlane::VERSION)
self.tools.each do |key, value|
UI.message("'#{key}' enabled.".magenta) if value
UI.important("'#{key}' not enabled.") unless value
end
path = File.join(folder, 'Fastfile')
File.write(path, template)
UI.success("Created new file '#{path}'. Edit it to manage your own deployment lanes.")
end
|
#handle_exception(exception: nil) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/fastlane/setup/setup_ios.rb', line 52
def handle_exception(exception: nil)
UI.error('Error occurred with the setup program! Reverting changes now!')
restore_previous_state
raise exception
end
|
#manual_setup ⇒ Object
78
79
80
81
82
83
84
85
|
# File 'lib/fastlane/setup/setup_ios.rb', line 78
def manual_setup
copy_existing_files
generate_appfile(manually: true)
detect_installed_tools ask_to_enable_other_tools
generate_fastfile(manually: true)
show_analytics
end
|
#print_config_table ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/fastlane/setup/setup_ios.rb', line 109
def print_config_table
rows = []
rows << ["Apple ID", self.apple_id]
rows << ["App Name", self.app_name]
rows << ["App Identifier", self.app_identifier]
rows << [(self.project.is_workspace ? "Workspace" : "Project"), self.project.path]
require 'terminal-table'
puts ""
puts Terminal::Table.new(rows: rows, title: "Detected Values")
puts ""
unless self.itc_ref
UI.important "This app identifier doesn't exist on iTunes Connect yet, it will be created for you"
end
unless self.portal_ref
UI.important "This app identifier doesn't exist on the Apple Developer Portal yet, it will be created for you"
end
end
|
#restore_previous_state ⇒ Object
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
# File 'lib/fastlane/setup/setup_ios.rb', line 264
def restore_previous_state
files_to_copy.each do |current|
from_path = File.join(folder, current)
to_path = File.basename(current)
if File.exist?(from_path)
UI.important("Moving '#{from_path}' to '#{to_path}'")
FileUtils.mv(from_path, to_path)
end
end
UI.important("Deleting the 'fastlane' folder")
FileUtils.rm_rf(folder)
end
|
#run ⇒ Object
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
|
# File 'lib/fastlane/setup/setup_ios.rb', line 17
def run
if FastlaneFolder.setup? and !Helper.is_test?
UI.important("Fastlane already set up at path #{folder}")
return
end
show_infos
FastlaneFolder.create_folder! unless Helper.is_test?
is_manual_setup = false
begin
setup_project
ask_for_apple_id
detect_if_app_is_available
print_config_table
if UI.confirm("Please confirm the above values")
default_setup
else
is_manual_setup = true
manual_setup
end
UI.success('Successfully finished setting up fastlane')
rescue => ex if is_manual_setup
handle_exception(exception: ex)
else
UI.error(ex.to_s)
UI.error('An error occured during the setup process. Falling back to manual setup!')
try_manual_setup
end
end
end
|
#setup_project ⇒ Object
101
102
103
104
105
106
107
|
# File 'lib/fastlane/setup/setup_ios.rb', line 101
def setup_project
config = {}
FastlaneCore::Project.detect_projects(config)
self.project = FastlaneCore::Project.new(config)
self.app_identifier = self.project.default_app_identifier self.app_name = self.project.default_app_name end
|
#show_infos ⇒ Object
129
130
131
132
133
|
# File 'lib/fastlane/setup/setup_ios.rb', line 129
def show_infos
UI.success('This setup will help you get up and running in no time.')
UI.success("fastlane will check what tools you're already using and set up")
UI.success('the tool automatically for you. Have fun! ')
end
|
#try_manual_setup ⇒ Object
60
61
62
63
64
|
# File 'lib/fastlane/setup/setup_ios.rb', line 60
def try_manual_setup
manual_setup
rescue => ex
handle_exception(exception: ex)
end
|