Class: Fastlane::Actions::AnUpdateMetadataSourceAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::AnUpdateMetadataSourceAction
- Defined in:
- lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb
Documentation collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .output ⇒ Object
- .return_value ⇒ Object
Class Method Summary collapse
-
.check_source_files(source_files) ⇒ Object
Verifies that all the source files are available to this action.
-
.create_block_parsers(release_version, block_files) ⇒ Object
Creates the block instances.
-
.create_target_file_path(orig_file_path) ⇒ Object
Generates the temp file path.
-
.create_temp_po(params) ⇒ Object
Creates a temp po file merging new data for known tags and the data already in the original .po fo the others.
- .is_block_id(line) ⇒ Object
- .is_comment(line) ⇒ Object
- .run(params) ⇒ Object
-
.swap_po(orig_file_path, temp_file_path) ⇒ Object
Deletes the old po and moves the temp one to the final location.
-
.write_target_block(fw, line) ⇒ Object
Manages tags depending on the type.
Class Method Details
.authors ⇒ Object
166 167 168 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 166 def self. ['Automattic'] end |
.available_options ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 130 def self. # Define all options your action supports. # Below a few examples [ FastlaneCore::ConfigItem.new(key: :po_file_path, env_name: 'FL_UPDATE_METADATA_SOURCE_PO_FILE_PATH', description: 'The path of the .po file to update', type: String, verify_block: proc do |value| UI.user_error!("No .po file path for UpdateMetadataSourceAction given, pass using `po_file_path: 'file path'`") unless value && !value.empty? UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value) end), FastlaneCore::ConfigItem.new(key: :release_version, env_name: 'FL_UPDATE_METADATA_SOURCE_RELEASE_VERSION', description: 'The release version of the app (to use to mark the release notes)', verify_block: proc do |value| UI.user_error!("No relase version for UpdateMetadataSourceAction given, pass using `release_version: 'version'`") unless value && !value.empty? end), FastlaneCore::ConfigItem.new(key: :source_files, env_name: 'FL_UPDATE_METADATA_SOURCE_SOURCE_FILES', description: 'The hash with the path to the source files and the key to use to include their content', type: Hash, verify_block: proc do |value| UI.user_error!("No source file hash for UpdateMetadataSourceAction given, pass using `source_files: 'source file hash'`") unless value && !value.empty? end), ] end |
.check_source_files(source_files) ⇒ Object
Verifies that all the source files are available to this action
29 30 31 32 33 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 29 def self.check_source_files(source_files) source_files.each_value do |file_path| UI.user_error!("Couldn't find file at path '#{file_path}'") unless File.exist?(file_path) end end |
.create_block_parsers(release_version, block_files) ⇒ Object
Creates the block instances
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 74 def self.create_block_parsers(release_version, block_files) @blocks = [] # Inits default handler @blocks.push Fastlane::Helper::UnknownMetadataBlock.new # Init special handlers block_files.each do |key, file_path| case key when :release_note @blocks.push Fastlane::Helper::ReleaseNoteMetadataBlock.new(key, file_path, release_version) when :release_note_short @blocks.push Fastlane::Helper::ReleaseNoteShortMetadataBlock.new(key, file_path, release_version) else @blocks.push Fastlane::Helper::StandardMetadataBlock.new(key, file_path) end end # Sets the default @current_block = @blocks[0] end |
.create_target_file_path(orig_file_path) ⇒ Object
Generates the temp file path
69 70 71 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 69 def self.create_target_file_path(orig_file_path) "#{File.dirname(orig_file_path)}/#{File.basename(orig_file_path, '.*')}.tmp" end |
.create_temp_po(params) ⇒ Object
Creates a temp po file merging new data for known tags and the data already in the original .po fo the others.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 39 def self.create_temp_po(params) orig = params[:po_file_path] target = create_target_file_path(orig) # Clear if older exists FileUtils.rm_f(target) # Create the new one begin File.open(target, 'a') do |fw| File.open(orig, 'r').each do |fr| write_target_block(fw, fr) end end rescue StandardError FileUtils.rm_f(target) raise end target end |
.description ⇒ Object
122 123 124 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 122 def self.description 'Updates a .po file with new data from .txt files' end |
.details ⇒ Object
126 127 128 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 126 def self.details 'You can use this action to update the .po file that contains the string to load to GlotPress for localization.' end |
.is_block_id(line) ⇒ Object
110 111 112 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 110 def self.is_block_id(line) line.start_with?('msgctxt') end |
.is_comment(line) ⇒ Object
114 115 116 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 114 def self.is_comment(line) line.start_with?('#') end |
.is_supported?(platform) ⇒ Boolean
170 171 172 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 170 def self.is_supported?(platform) [:android].include?(platform) end |
.output ⇒ Object
159 160 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 159 def self.output end |
.return_value ⇒ Object
162 163 164 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 162 def self.return_value # If your method provides a return value, you can describe here what it does end |
.run(params) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 11 def self.run(params) # fastlane will take care of reading in the parameter and fetching the environment variable: UI. "Parameter .po file path: #{params[:po_file_path]}" UI. "Release version: #{params[:release_version]}" # Init create_block_parsers(params[:release_version], params[:source_files]) # Do check_source_files(params[:source_files]) temp_po_name = create_temp_po(params) swap_po(params[:po_file_path], temp_po_name) UI. "File #{params[:po_file_path]} updated!" end |
.swap_po(orig_file_path, temp_file_path) ⇒ Object
Deletes the old po and moves the temp one to the final location
63 64 65 66 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 63 def self.swap_po(orig_file_path, temp_file_path) FileUtils.rm_f(orig_file_path) File.rename(temp_file_path, orig_file_path) end |
.write_target_block(fw, line) ⇒ Object
Manages tags depending on the type
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb', line 97 def self.write_target_block(fw, line) if is_block_id(line) key = line.split[1].tr('\"', '') @blocks.each do |block| @current_block = block if block.is_handler_for(key) end end @current_block = @blocks.first if is_comment(line) @current_block.handle_line(fw, line) end |