Class: Deliver::UploadScreenshots
- Inherits:
-
Object
- Object
- Deliver::UploadScreenshots
- Defined in:
- deliver/lib/deliver/upload_screenshots.rb
Overview
upload screenshots to App Store Connect
Instance Method Summary collapse
- #collect_screenshots(options) ⇒ Object
- #collect_screenshots_for_languages(path, ignore_validation) ⇒ Object
- #upload(options, screenshots) ⇒ Object
Instance Method Details
#collect_screenshots(options) ⇒ Object
81 82 83 84 |
# File 'deliver/lib/deliver/upload_screenshots.rb', line 81 def collect_screenshots() return [] if [:skip_screenshots] return collect_screenshots_for_languages([:screenshots_path], [:ignore_language_directory_validation]) end |
#collect_screenshots_for_languages(path, ignore_validation) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'deliver/lib/deliver/upload_screenshots.rb', line 86 def collect_screenshots_for_languages(path, ignore_validation) screenshots = [] extensions = '{png,jpg,jpeg}' available_languages = Spaceship::Tunes.client.available_languages.each_with_object({}) do |lang, lang_hash| lang_hash[lang.downcase] = lang end Loader.language_folders(path, ignore_validation).each do |lng_folder| language = File.basename(lng_folder) # Check to see if we need to traverse multiple platforms or just a single platform if language == Loader::APPLE_TV_DIR_NAME || language == Loader::IMESSAGE_DIR_NAME screenshots.concat(collect_screenshots_for_languages(File.join(path, language), ignore_validation)) next end files = Dir.glob(File.join(lng_folder, "*.#{extensions}"), File::FNM_CASEFOLD).sort next if files.count == 0 prefer_framed = Dir.glob(File.join(lng_folder, "*_framed.#{extensions}"), File::FNM_CASEFOLD).count > 0 UI.important("Framed screenshots are detected! 🖼 Non-framed screenshot files may be skipped. 🏃") if prefer_framed language_dir_name = File.basename(lng_folder) if available_languages[language_dir_name.downcase].nil? UI.user_error!("#{language_dir_name} is not an available language. Please verify that your language codes are available in iTunesConnect. See https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/iTunesConnect_Guide/Chapters/AppStoreTerritories.html for more information.") end language = available_languages[language_dir_name.downcase] files.each do |file_path| is_framed = file_path.downcase.include?("_framed.") is_watch = file_path.downcase.include?("watch") if prefer_framed && !is_framed && !is_watch UI.important("🏃 Skipping screenshot file: #{file_path}") next end screenshots << AppScreenshot.new(file_path, language) end end return screenshots end |
#upload(options, screenshots) ⇒ Object
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 39 40 41 42 43 44 45 46 47 48 49 50 51 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 |
# File 'deliver/lib/deliver/upload_screenshots.rb', line 10 def upload(, screenshots) return if [:skip_screenshots] return if [:edit_live] app = [:app] v = app.edit_version(platform: [:platform]) UI.user_error!("Could not find a version to edit for app '#{app.name}'") unless v UI.("Starting with the upload of screenshots...") screenshots_per_language = screenshots.group_by(&:language) if [:overwrite_screenshots] UI.("Removing all previously uploaded screenshots...") # First, clear all previously uploaded screenshots screenshots_per_language.keys.each do |language| # We have to nil check for languages not activated next if v.screenshots[language].nil? v.screenshots[language].each_with_index do |t, index| v.upload_screenshot!(nil, t.sort_order, t.language, t.device_type, t.) end end end # Now, fill in the new ones indized = {} # per language and device type enabled_languages = screenshots_per_language.keys if enabled_languages.count > 0 v.create_languages(enabled_languages) lng_text = "language" lng_text += "s" if enabled_languages.count != 1 Helper.show_loading_indicator("Activating #{lng_text} #{enabled_languages.join(', ')}...") v.save! # This refreshes the app version from iTC after enabling a localization v = app.edit_version Helper.hide_loading_indicator end screenshots_per_language.each do |language, screenshots_for_language| UI.("Uploading #{screenshots_for_language.length} screenshots for language #{language}") screenshots_for_language.each do |screenshot| indized[screenshot.language] ||= {} indized[screenshot.language][screenshot.formatted_name] ||= 0 indized[screenshot.language][screenshot.formatted_name] += 1 # we actually start with 1... wtf iTC index = indized[screenshot.language][screenshot.formatted_name] if index > 10 UI.error("Too many screenshots found for device '#{screenshot.formatted_name}' in '#{screenshot.language}', skipping this one (#{screenshot.path})") next end UI.("Uploading '#{screenshot.path}'...") v.upload_screenshot!(screenshot.path, index, screenshot.language, screenshot.device_type, screenshot.) end # ideally we should only save once, but itunes server can't cope it seems # so we save per language. See issue #349 Helper.show_loading_indicator("Saving changes") v.save! # Refresh app version to start clean again. See issue #9859 v = app.edit_version Helper.hide_loading_indicator end UI.success("Successfully uploaded screenshots to App Store Connect") end |