Module: Deliver::Loader

Defined in:
deliver/lib/deliver/loader.rb

Defined Under Namespace

Classes: LanguageFolder

Constant Summary collapse

APPLE_TV_DIR_NAME =

The directory ‘appleTV’ and ‘iMessage` are special folders that will cause our screenshot gathering code to iterate through it as well searching for language folders.

"appleTV".freeze
IMESSAGE_DIR_NAME =
"iMessage".freeze
DEFAULT_DIR_NAME =
"default".freeze
EXPANDABLE_DIR_NAMES =
[APPLE_TV_DIR_NAME, IMESSAGE_DIR_NAME].freeze
SPECIAL_DIR_NAMES =
[APPLE_TV_DIR_NAME, IMESSAGE_DIR_NAME, DEFAULT_DIR_NAME].freeze
SUPPLY_DIR_NAME =

Some exception directories may exist from other actions that should not be iterated through

"android".freeze
FRAMEIT_FONTS_DIR_NAME =
"fonts".freeze
META_DIR_NAMES =
UploadMetadata::ALL_META_SUB_DIRS.map(&:downcase)
EXCEPTION_DIRECTORIES =
(META_DIR_NAMES << SUPPLY_DIR_NAME << FRAMEIT_FONTS_DIR_NAME).freeze

Class Method Summary collapse

Class Method Details

.language_folders(root, ignore_validation, expand_sub_folders = false) ⇒ Array<LanguageFolder>

Returns the list of language folders

Parameters:

  • roort (String)

    A directory path to get the list of language folders

  • ignore_validation (Boolean)

    Set false not to raise the error when finding invalid folder name

  • expand_sub_folders (Boolean) (defaults to: false)

    Set true to expand special folders; such as “iMessage” to nested language folders

Returns:



125
126
127
128
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
# File 'deliver/lib/deliver/loader.rb', line 125

def self.language_folders(root, ignore_validation, expand_sub_folders = false)
  folders = Dir.glob(File.join(root, '*'))
               .select { |path| File.directory?(path) }
               .map { |path| LanguageFolder.new(path, nested: false) }
               .reject(&:skip?)

  selected_folders, rejected_folders = folders.partition(&:valid?)

  if !ignore_validation && !rejected_folders.empty?
    rejected_folders = rejected_folders.map(&:basename)
    UI.user_error!("Unsupported directory name(s) for screenshots/metadata in '#{root}': #{rejected_folders.join(', ')}" \
                   "\nValid directory names are: #{LanguageFolder.allowed_directory_names_with_case}" \
                   "\n\nEnable 'ignore_language_directory_validation' to prevent this validation from happening")
  end

  # Expand selected_folders for the special directories
  if expand_sub_folders
    selected_folders = selected_folders.flat_map do |folder|
      if folder.expandable?
        Dir.glob(File.join(folder.path, '*'))
           .select { |p| File.directory?(p) }
           .map { |p| LanguageFolder.new(p, nested: true) }
           .select(&:valid?)
      else
        folder
      end
    end
  end

  selected_folders
end

.load_app_screenshots(root, ignore_validation) ⇒ Array<Deliver::AppScreenshot>

Returns the list of valid app screenshot. When detecting invalid screenshots, this will cause an error.

Parameters:

  • root (String)

    A directory path

  • ignore_validation (String)

    Set false not to raise the error when finding invalid folder name

Returns:



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
# File 'deliver/lib/deliver/loader.rb', line 86

def self.load_app_screenshots(root, ignore_validation)
  screenshots = language_folders(root, ignore_validation, true).flat_map do |language_folder|
    paths = if language_folder.framed_file_paths.count > 0
              UI.important("Framed screenshots are detected! 🖼 Non-framed screenshot files may be skipped. 🏃")
              # watchOS screenshots can be picked up even when framed ones were found since frameit doesn't support watchOS screenshots
              framed_or_watch, skipped = language_folder.file_paths.partition { |path| path.downcase.include?('framed') || path.downcase.include?('watch') }
              skipped.each { |path| UI.important("🏃 Skipping screenshot file: #{path}") }
              framed_or_watch
            else
              language_folder.file_paths
            end
    paths.map { |path| AppScreenshot.new(path, language_folder.language) }
  end

  errors = []
  valid_screenshots = screenshots.select { |screenshot| Deliver::AppScreenshotValidator.validate(screenshot, errors) }

  errors_to_skip, errors_to_crash = errors.partition(&:to_skip)

  unless errors_to_skip.empty?
    UI.important("🏃 Screenshots to be skipped are detected!")
    errors_to_skip.each { |error| UI.message(error) }
  end

  unless errors_to_crash.empty?
    UI.important("🚫 Invalid screenshots were detected! Here are the reasons:")
    errors_to_crash.each { |error| UI.error(error) }
    UI.user_error!("Canceled uploading screenshots. Please check the error messages above and fix the screenshots.")
  end

  valid_screenshots
end