Class: Fastlane::Actions::AndroidChangeStringAppNameAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/android_change_string_app_name/actions/android_change_string_app_name_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



36
37
38
# File 'lib/fastlane/plugin/android_change_string_app_name/actions/android_change_string_app_name_action.rb', line 36

def self.authors
  ["MaximusMcCann"]
end

.available_optionsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fastlane/plugin/android_change_string_app_name/actions/android_change_string_app_name_action.rb', line 48

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :newName,
                            env_name: "",
                         description: "The new name for the app",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :stringsFile,
                            env_name: "",
                         description: "Optional custom location for strings.xml",
                            optional: false,
                                type: String,
                       default_value: "app/src/main/res/values/strings.xml")
  ]
end

.descriptionObject



32
33
34
# File 'lib/fastlane/plugin/android_change_string_app_name/actions/android_change_string_app_name_action.rb', line 32

def self.description
  "Change the app_name in the strings.xml file & revert method"
end

.detailsObject



44
45
46
# File 'lib/fastlane/plugin/android_change_string_app_name/actions/android_change_string_app_name_action.rb', line 44

def self.details
  "Change the app_name in the strings.xml file & revert method"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/fastlane/plugin/android_change_string_app_name/actions/android_change_string_app_name_action.rb', line 70

def self.is_supported?(platform)
  platform == :android
end

.outputObject



64
65
66
67
68
# File 'lib/fastlane/plugin/android_change_string_app_name/actions/android_change_string_app_name_action.rb', line 64

def self.output
  [
    ['ANDROID_CHANGE_STRING_APP_NAME_ORIGINAL_NAME', 'The original app name.']
  ]
end

.return_valueObject



40
41
42
# File 'lib/fastlane/plugin/android_change_string_app_name/actions/android_change_string_app_name_action.rb', line 40

def self.return_value
  # If your method provides a return value, you can describe here what it does
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
# File 'lib/fastlane/plugin/android_change_string_app_name/actions/android_change_string_app_name_action.rb', line 7

def self.run(params)
  require 'nokogiri'

  newName = params[:newName]
  stringsFile = params[:stringsFile]

  doc = File.open(stringsFile) { |f|
    @doc = Nokogiri::XML(f)

    originalName = nil

    @doc.css("resources string[@name=app_name]").each do |response_node|
      originalName = response_node.content
      response_node.content = newName

      UI.message("Updating app name to: #{newName}")
    end

    Actions.lane_context[SharedValues::ANDROID_CHANGE_STRING_APP_NAME_ORIGINAL_NAME] = originalName

    File.write(stringsFile, @doc.to_xml)
  }

end