Class: Fastlane::Actions::UpdateInfoPlistAction

Inherits:
Fastlane::Action show all
Defined in:
lib/fastlane/actions/update_info_plist.rb

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, details, output, sh, step_text

Class Method Details

.authorObject



80
81
82
# File 'lib/fastlane/actions/update_info_plist.rb', line 80

def self.author
  'tobiasstrebitzer'
end

.available_optionsObject



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
# File 'lib/fastlane/actions/update_info_plist.rb', line 51

def self.available_options
  [
    
    FastlaneCore::ConfigItem.new(key: :xcodeproj,
                                 env_name: "FL_UPDATE_PLIST_PROJECT_PATH",
                                 description: "Path to your Xcode project",
                                 optional: true,
                                 verify_block: Proc.new do |value|
                                  raise "Please pass the path to the project, not the workspace".red if value.include?"workspace"
                                  raise "Could not find Xcode project".red unless File.exists?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :plist_path,
                                 env_name: "FL_UPDATE_PLIST_PATH",
                                 description: "Path to info plist",
                                 verify_block: Proc.new do |value|
                                   raise "Invalid plist file".red unless value[-6..-1].downcase == ".plist"
                                 end),
    FastlaneCore::ConfigItem.new(key: :app_identifier,
                                 env_name: 'FL_UPDATE_PLIST_APP_IDENTIFIER',
                                 description: 'The App Identifier of your app',
                                 default_value: ENV['PRODUCE_APP_IDENTIFIER'],
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :display_name,
                                 env_name: 'FL_UPDATE_PLIST_DISPLAY_NAME',
                                 description: 'The Display Name of your app',
                                 optional: true)
  ]
end

.descriptionObject



47
48
49
# File 'lib/fastlane/actions/update_info_plist.rb', line 47

def self.description
  'Update a Info.plist file with bundle identifier and display name'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/fastlane/actions/update_info_plist.rb', line 43

def self.is_supported?(platform)
  [:ios].include?(platform)
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/actions/update_info_plist.rb', line 7

def self.run(params)
  require 'plist'
          
  # Check if parameters are set
  if params[:app_identifier] or params[:display_name]
    
    # Assign folder from parameter or search for xcodeproj file
    folder = params[:xcodeproj] || Dir["*.xcodeproj"].first
  
    # Read existing plist file 
    info_plist_path = File.join(folder, "..", params[:plist_path])
    raise "Couldn't find info plist file at path '#{params[:plist_path]}'".red unless File.exists?(info_plist_path)
    plist = Plist::parse_xml(info_plist_path)
    
    # Update plist values
    plist['CFBundleIdentifier'] = params[:app_identifier] if params[:app_identifier]
    plist['CFBundleDisplayName'] = params[:display_name] if params[:display_name]
    
    # Write changes to file
    plist_string = Plist::Emit.dump(plist)
    File.write(info_plist_path, plist_string)
    
    Helper.log.info "Updated #{params[:plist_path]} 💾.".green
    plist_string
  else
    Helper.log.warn("You haven't specified any parameters to update your plist.")
    false
  end
  
end