Class: Fastlane::Actions::IosMergeStringsFilesAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



70
71
72
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 70

def self.authors
  ['Automattic']
end

.available_optionsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 43

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :paths_to_merge,
      env_name: 'FL_IOS_MERGE_STRINGS_FILES_PATHS_TO_MERGE',
      description: 'A hash of the paths of all the `.strings` files to merge into the `destination`, with the prefix to be used for their keys as associated value',
      type: Hash,
      optional: false
    ),
    FastlaneCore::ConfigItem.new(
      key: :destination,
      env_name: 'FL_IOS_MERGE_STRINGS_FILES_DESTINATION',
      description: 'The path of the `.strings` file to merge the other ones into',
      type: String,
      optional: false
    ),
  ]
end

.descriptionObject



24
25
26
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 24

def self.description
  'Merge multiple `.strings` files into one'
end

.detailsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 28

def self.details
  <<~DETAILS
    Merge multiple `.strings` files into another one.

    Especially useful to prepare a single `.strings` file merging string files like `InfoPlist.strings` 

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 74

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

.return_typeObject



62
63
64
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 62

def self.return_type
  :array_of_strings
end

.return_valueObject



66
67
68
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 66

def self.return_value
  'The list of duplicate keys (after prefix has been added to each) found while merging the various `.strings` files'
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_strings_files.rb', line 4

def self.run(params)
  destination = params[:destination]
  # Include the destination as the first of the files (without key prefixes) to be included in the merged result
  all_paths_list = { destination => nil }.merge(params[:paths_to_merge])

  UI.message "Merging strings files #{all_paths_list.inspect}"

  File.write(destination, '') unless File.exist?(destination) # Create empty destination file if it does not exist yet
  duplicates = Fastlane::Helper::Ios::L10nHelper.merge_strings(paths: all_paths_list, output_path: params[:destination])
  duplicates.each do |dup_key|
    UI.important "Duplicate key found while merging the `.strings` files: `#{dup_key}`"
  end
  UI.important 'Tip: To avoid those key conflicts, you might want to consider providing different prefixes in the `Hash` you used for the `paths:` parameter.' unless duplicates.empty?
  duplicates
end