Class: Fastlane::Actions::UpdatePlistAction

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

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, deprecated_notes, lane_context, method_missing, other_action, output, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorObject



59
60
61
# File 'fastlane/lib/fastlane/actions/update_plist.rb', line 59

def self.author
  ["rishabhtayal", "matthiaszarzecki"]
end

.available_optionsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'fastlane/lib/fastlane/actions/update_plist.rb', line 45

def self.available_options
  [

    FastlaneCore::ConfigItem.new(key: :plist_path,
                                 env_name: "FL_UPDATE_PLIST_PATH",
                                 description: "Path to plist file",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :block,
                                 type: :string_callback,
                                 description: 'A block to process plist with custom logic')

  ]
end

.categoryObject



110
111
112
# File 'fastlane/lib/fastlane/actions/update_plist.rb', line 110

def self.category
  :project
end

.descriptionObject



37
38
39
# File 'fastlane/lib/fastlane/actions/update_plist.rb', line 37

def self.description
  'Update a plist file'
end

.detailsObject



41
42
43
# File 'fastlane/lib/fastlane/actions/update_plist.rb', line 41

def self.details
  "This action allows you to modify any value inside any `plist` file."
end

.example_codeObject



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

def self.example_code
  [
    'update_plist( # Updates the CLIENT_ID and GOOGLE_APP_ID string entries in the plist-file
      plist_path: "path/to/your_plist_file.plist",
      block: proc do |plist|
        plist[:CLIENT_ID] = "new_client_id"
        plist[:GOOGLE_APP_ID] = "new_google_app_id"
      end
    )',
    'update_plist( # Sets a boolean entry
      plist_path: "path/to/your_plist_file.plist",
      block: proc do |plist|
        plist[:boolean_entry] = true
      end
    )',
    'update_plist( # Sets a number entry
      plist_path: "path/to/your_plist_file.plist",
      block: proc do |plist|
        plist[:number_entry] = 13
      end
    )',
    'update_plist( # Sets an array-entry with multiple sub-types
      plist_path: "path/to/your_plist_file.plist",
      block: proc do |plist|
        plist[:array_entry] = ["entry_01", true, 1243]
      end
    )',
    'update_plist( # The block can contain logic too
      plist_path: "path/to/your_plist_file.plist",
      block: proc do |plist|
        if options[:environment] == "production"
          plist[:CLIENT_ID] = "new_client_id_production"
        else
          plist[:CLIENT_ID] = "new_client_id_development"
        end
      end
    )',
    'update_plist( # Advanced processing: find URL scheme for particular key and replace value
      plist_path: "path/to/Info.plist",
      block: proc do |plist|
        urlScheme = plist["CFBundleURLTypes"].find{|scheme| scheme["CFBundleURLName"] == "com.acme.default-url-handler"}
        urlScheme[:CFBundleURLSchemes] = ["acme-production"]
      end
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



33
34
35
# File 'fastlane/lib/fastlane/actions/update_plist.rb', line 33

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

def self.run(params)
  require 'xcodeproj'

  if params[:plist_path].nil?
    UI.user_error!("You must specify a plist path")
  end

  # Read existing plist file
  plist_path = params[:plist_path]

  UI.user_error!("Couldn't find plist file at path '#{plist_path}'") unless File.exist?(plist_path)
  plist = Xcodeproj::Plist.read_from_path(plist_path)

  params[:block].call(plist) if params[:block]

  # Write changes to file
  Xcodeproj::Plist.write_to_path(plist, plist_path)

  UI.success("Updated #{params[:plist_path]} 💾.")
  File.read(plist_path)
end