4
5
6
7
8
9
10
11
12
13
14
15
16
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
|
# File 'fastlane/lib/fastlane/actions/update_app_identifier.rb', line 4
def self.run(params)
require 'plist'
require 'xcodeproj'
info_plist_key = 'INFOPLIST_FILE'
identifier_key = 'PRODUCT_BUNDLE_IDENTIFIER'
info_plist_path = resolve_path(params[:plist_path], params[:xcodeproj])
UI.user_error!("Couldn't find info plist file at path '#{params[:plist_path]}'") unless File.exist?(info_plist_path)
plist = Plist.parse_xml(info_plist_path)
app_id_equals_bundle_id = %W($(#{identifier_key}) ${#{identifier_key}}).include?(plist['CFBundleIdentifier'])
if app_id_equals_bundle_id
project_path = params[:xcodeproj]
project = Xcodeproj::Project.open(project_path)
configs = project.objects.select { |obj| obj.isa == 'XCBuildConfiguration' && !obj.build_settings[identifier_key].nil? }
UI.user_error!("Info plist uses #{identifier_key}, but xcodeproj does not") if configs.empty?
configs = configs.select { |obj| resolve_path(obj.build_settings[info_plist_key], params[:xcodeproj]) == info_plist_path }
UI.user_error!("Xcodeproj doesn't have configuration with info plist #{params[:plist_path]}.") if configs.empty?
configs.each do |c|
c.build_settings[identifier_key] = params[:app_identifier]
end
project.save
UI.success("Updated #{params[:xcodeproj]} 💾.")
else
plist['CFBundleIdentifier'] = params[:app_identifier]
plist_string = Plist::Emit.dump(plist)
File.write(info_plist_path, plist_string)
UI.success("Updated #{params[:plist_path]} 💾.")
end
end
|