Class: Fastlane::Actions::UpdateUrlSchemesAction

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

Constant Summary

Constants inherited from Fastlane::Action

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

Class Method Summary collapse

Methods inherited from Fastlane::Action

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

Class Method Details

.authorsObject



96
97
98
# File 'fastlane/lib/fastlane/actions/update_url_schemes.rb', line 96

def self.authors
  ['kmikael']
end

.available_optionsObject



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

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :path,
      env_name: 'FL_UPDATE_URL_SCHEMES_PATH',
      description: 'The Plist file\'s path',
      is_string: true,
      optional: false,
      verify_block: proc do |path|
        UI.user_error!("Could not find plist at path '#{path}'") unless File.exist?(path)
      end
    ),

    FastlaneCore::ConfigItem.new(
      key: :url_schemes,
      env_name: "FL_UPDATE_URL_SCHEMES_SCHEMES",
      description: 'The new URL schemes',
      is_string: false,
      optional: true,
      verify_block: proc do |url_schemes|
        string = "The URL schemes must be an array of strings, got '#{url_schemes}'."
        verify_schemes!(url_schemes, string)
      end
    ),

    FastlaneCore::ConfigItem.new(key: :update_url_schemes,
      description: "Block that is called to update schemes with current schemes passed in as parameter",
      optional: true,
      is_string: false)
  ]
end

.categoryObject



119
120
121
# File 'fastlane/lib/fastlane/actions/update_url_schemes.rb', line 119

def self.category
  :project
end

.descriptionObject



48
49
50
# File 'fastlane/lib/fastlane/actions/update_url_schemes.rb', line 48

def self.description
  'Updates the URL schemes in the given Info.plist'
end

.detailsObject



84
85
86
87
88
89
90
# File 'fastlane/lib/fastlane/actions/update_url_schemes.rb', line 84

def self.details
  [
    "This action allows you to update the URL schemes of the app before building it.",
    "For example, you can use this to set a different url scheme for the alpha",
    "or beta version of the app."
  ].join("\n")
end

.example_codeObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'fastlane/lib/fastlane/actions/update_url_schemes.rb', line 104

def self.example_code
  [
    'update_url_schemes(
      path: "path/to/Info.plist",
      url_schemes: ["com.myapp"]
    )',
    'update_url_schemes(
      path: "path/to/Info.plist",
      update_url_schemes: proc do |schemes|
        schemes + ["anotherscheme"]
      end
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



100
101
102
# File 'fastlane/lib/fastlane/actions/update_url_schemes.rb', line 100

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

.outputObject



92
93
94
# File 'fastlane/lib/fastlane/actions/update_url_schemes.rb', line 92

def self.output
  []
end

.run(params) ⇒ Object



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

def self.run(params)
  path = params[:path]
  url_schemes = params[:url_schemes]
  update_url_schemes = params[:update_url_schemes]

  hash = Plist.parse_xml(path)

  # Create CFBundleURLTypes array with empty scheme if none exist
  unless hash['CFBundleURLTypes']
    hash['CFBundleURLTypes'] = [{
      'CFBundleTypeRole' => 'Editor',
      'CFBundleURLSchemes' => []
    }]
  end

  # Updates schemes with update block if exists
  # Else updates with array of strings if exist
  # Otherwise shows error to user
  if update_url_schemes
    new_schemes = update_url_schemes.call(hash['CFBundleURLTypes'].first['CFBundleURLSchemes'])

    # Verify array of strings
    string = "The URL schemes must be an array of strings, got '#{new_schemes}'."
    verify_schemes!(new_schemes, string)

    hash['CFBundleURLTypes'].first['CFBundleURLSchemes'] = new_schemes
  elsif url_schemes
    hash['CFBundleURLTypes'].first['CFBundleURLSchemes'] = url_schemes
  else
    UI.user_error!("No `url_schemes` or `update_url_schemes` provided")
  end
  File.write(path, Plist::Emit.dump(hash))
end

.verify_schemes!(url_schemes, error_message) ⇒ Object



40
41
42
43
44
45
46
# File 'fastlane/lib/fastlane/actions/update_url_schemes.rb', line 40

def self.verify_schemes!(url_schemes, error_message)
  UI.user_error!(error_message) unless url_schemes.kind_of?(Array)

  url_schemes.each do |url_scheme|
    UI.user_error!(error_message) unless url_scheme.kind_of?(String)
  end
end