Class: Everywhere::Commands::Icon

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/everywhere/commands/icon.rb

Overview

Generate platform-native app icons from a single source PNG — the same pipeline every build uses, exposed on its own for previewing and CI.

Instance Method Summary collapse

Instance Method Details

#call(source: nil, root: ".", output: nil) ⇒ Object



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
# File 'lib/everywhere/commands/icon.rb', line 20

def call(source: nil, root: ".", output: nil, **)
  root_path = File.expand_path(root)
  source ||= default_source(root_path)
  UI.die!("no source PNG — pass one or set app.icon in everywhere.yml") unless source
  UI.die!("source PNG not found: #{source}") unless File.exist?(source)

  out = File.expand_path(output || File.join(root_path, "dist", "icons"))
  FileUtils.mkdir_p(out)
  UI.step("generating icons from #{File.basename(source)}#{out.sub("#{Dir.pwd}/", "")}")

  master = File.join(out, "AppIcon-macos.png")
  unless Everywhere::Icon.macos_master(source, master)
    UI.die!("couldn't read #{File.basename(source)} — expected an 8-bit RGB/RGBA PNG")
  end
  UI.ok("macOS master  #{rel(master, out)} #{UI.dim("(inset + squircle, 1024px)")}")

  Everywhere::Icon.write_icns(master, File.join(out, "AppIcon.icns"))
  UI.ok("macOS icon    AppIcon.icns")

  Everywhere::Icon.write_ico(source, File.join(out, "icon.ico"))
  UI.ok("Windows icon  icon.ico")

  pngs = Everywhere::Icon.write_png_set(source, File.join(out, "linux"))
  UI.ok("Linux icons   linux/ #{UI.dim("(#{pngs.size} sizes)")}")

  UI.success("icons written to #{out.sub("#{Dir.pwd}/", "")}")
end