Class: Fastlane::Actions::GpUpdateMetadataSourceAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::GpUpdateMetadataSourceAction
- Defined in:
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.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
165 166 167 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 165 def self. ['Automattic'] end |
.available_options ⇒ Object
129 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 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 129 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
28 29 30 31 32 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 28 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
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 73 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 :whats_new @blocks.push Fastlane::Helper::WhatsNewMetadataBlock.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
68 69 70 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 68 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.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 38 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
121 122 123 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 121 def self.description 'Updates a .po file with new data from .txt files' end |
.details ⇒ Object
125 126 127 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 125 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
109 110 111 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 109 def self.is_block_id(line) line.start_with?('msgctxt') end |
.is_comment(line) ⇒ Object
113 114 115 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 113 def self.is_comment(line) line.start_with?('#') end |
.is_supported?(platform) ⇒ Boolean
169 170 171 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 169 def self.is_supported?(platform) true end |
.output ⇒ Object
158 159 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 158 def self.output end |
.return_value ⇒ Object
161 162 163 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 161 def self.return_value # If your method provides a return value, you can describe here what it does end |
.run(params) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 10 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
62 63 64 65 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 62 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
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb', line 96 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 |