Class: Frameit::Runner

Inherits:
Object
  • Object
show all
Defined in:
frameit/lib/frameit/runner.rb

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



10
11
12
13
14
15
# File 'frameit/lib/frameit/runner.rb', line 10

def initialize
  downloader = FrameDownloader.new
  unless downloader.frames_exist?
    downloader.download_frames
  end
end

Instance Method Details

#create_config(screenshot_path) ⇒ Object

Loads the config (colors, background, texts, etc.) Don’t use this method to access the actual text and use ‘fetch_texts` instead



84
85
86
87
88
89
90
91
92
93
94
95
# File 'frameit/lib/frameit/runner.rb', line 84

def create_config(screenshot_path)
  # Screengrab pulls screenshots to a different folder location
  # frameit only handles two levels of folders, to not break
  # compatibility with Supply we look into a different path for Android
  # Issue https://github.com/fastlane/fastlane/issues/16289
  config_path = File.join(File.expand_path("..", screenshot_path), "Framefile.json")
  config_path = File.join(File.expand_path("../..", screenshot_path), "Framefile.json") unless File.exist?(config_path)
  config_path = File.join(File.expand_path("../../../..", screenshot_path), "Framefile.json") unless File.exist?(config_path)
  file = ConfigParser.new.load(config_path)
  return {} unless file # no config file at all
  file.fetch_value(screenshot_path)
end

#editor(screenshot, config) ⇒ Object



74
75
76
77
78
79
80
# File 'frameit/lib/frameit/runner.rb', line 74

def editor(screenshot, config)
  if screenshot.mac?
    return MacEditor.new(screenshot, config)
  else
    return Editor.new(screenshot, config, Frameit.config[:debug_mode])
  end
end

#run(path, color = nil, platform = nil) ⇒ Object



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
# File 'frameit/lib/frameit/runner.rb', line 17

def run(path, color = nil, platform = nil)
  unless color
    color = Frameit::Color::SILVER if Frameit.config[:white] || Frameit.config[:silver]
    color = Frameit::Color::GOLD if Frameit.config[:gold]
    color = Frameit::Color::ROSE_GOLD if Frameit.config[:rose_gold]
  end

  screenshots = Dir.glob("#{path}/**/*.{png,PNG}").uniq # uniq because thanks to {png,PNG} there are duplicates

  if screenshots.count > 0
    screenshots.each do |full_path|
      next if skip_path?(full_path)

      begin
        config = create_config(full_path)
        screenshot = Screenshot.new(full_path, color, config, platform)

        next if skip_up_to_date?(screenshot)

        editor = editor(screenshot, config)

        if editor.should_skip?
          UI.message("Skipping framing of screenshot #{screenshot.path}.  No title provided in your Framefile.json or title.strings.")
        else
          Helper.show_loading_indicator("Framing screenshot '#{full_path}'")
          editor.frame!
        end
      rescue => ex
        UI.error(ex.to_s)
        UI.error("Backtrace:\n\t#{ex.backtrace.join("\n\t")}") if FastlaneCore::Globals.verbose?
      end
    end
  else
    UI.error("Could not find screenshots in current directory: '#{File.expand_path(path)}'")
  end
end

#skip_path?(path) ⇒ Boolean

Returns:



54
55
56
57
58
59
60
61
62
63
64
# File 'frameit/lib/frameit/runner.rb', line 54

def skip_path?(path)
  return true if path.include?("_framed.png")
  return true if path.include?(".itmsp/") # a package file, we don't want to modify that
  return true if path.include?("device_frames/") # these are the device frames the user is using
  device = path.rpartition('/').last.partition('-').first # extract device name
  if device.downcase.include?("watch")
    UI.error("Apple Watch screenshots are not framed: '#{path}'")
    return true # we don't care about watches right now
  end
  false
end

#skip_up_to_date?(screenshot) ⇒ Boolean

Returns:



66
67
68
69
70
71
72
# File 'frameit/lib/frameit/runner.rb', line 66

def skip_up_to_date?(screenshot)
  if !screenshot.outdated? && Frameit.config[:resume]
    UI.message("Skipping framing of screenshot #{screenshot.path} because its framed file seems up-to-date.")
    return true
  end
  false
end