Class: Fastlane::Actions::AppiconAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/appicon/actions/appicon_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



105
106
107
# File 'lib/fastlane/plugin/appicon/actions/appicon_action.rb', line 105

def self.authors
  ["@NeoNacho"]
end

.available_optionsObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/fastlane/plugin/appicon/actions/appicon_action.rb', line 109

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :appicon_image_file,
                            env_name: "APPICON_IMAGE_FILE",
                         description: "Path to a square image file, at least 1024x1024",
                            optional: false,
                                type: String,
                       default_value: Dir["fastlane/metadata/app_icon.png"].last), # that's the default when using fastlane to manage app metadata
    FastlaneCore::ConfigItem.new(key: :appicon_devices,
                            env_name: "APPICON_DEVICES",
                       default_value: [:iphone],
                         description: "Array of device idioms to generate icons for",
                            optional: true,
                                type: Array),
    FastlaneCore::ConfigItem.new(key: :appicon_path,
                            env_name: "APPICON_PATH",
                       default_value: 'Assets.xcassets',
                         description: "Path to the Asset catalogue for the generated iconset",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :appicon_name,
                            env_name: "APPICON_NAME",
                       default_value: 'AppIcon.appiconset',
                         description: "Name of the appiconset inside the asset catalogue",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :remove_alpha,
                            env_name: "REMOVE_ALPHA",
                       default_value: false,
                         description: "Remove the alpha channel from generated PNG",
                            optional: true,
                                type: Boolean)
  ]
end

.descriptionObject



101
102
103
# File 'lib/fastlane/plugin/appicon/actions/appicon_action.rb', line 101

def self.description
  "Generate required icon sizes and iconset from a master application icon"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/fastlane/plugin/appicon/actions/appicon_action.rb', line 144

def self.is_supported?(platform)
  [:ios, :mac, :macos, :caros, :rocketos].include?(platform)
end

.needed_iconsObject



4
5
6
7
8
9
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
# File 'lib/fastlane/plugin/appicon/actions/appicon_action.rb', line 4

def self.needed_icons
  {
    iphone: {
      '2x' => ['20x20', '29x29', '40x40', '60x60'],
      '3x' => ['20x20', '29x29', '40x40', '60x60']
    },
    ipad: {
      '1x' => ['20x20', '29x29', '40x40', '76x76'],
      '2x' => ['20x20', '29x29', '40x40', '76x76', '83.5x83.5']
    },
    :ios_marketing => {
      '1x' => ['1024x1024']
    },
    :watch => {
      '2x' => [
                ['24x24', 'notificationCenter', '38mm'],
                ['27.5x27.5', 'notificationCenter', '42mm'],
                ['29x29', 'companionSettings'],
                ['40x40', 'appLauncher', '38mm'],
                ['44x44', 'appLauncher', '40mm'],
                ['50x50', 'appLauncher', '44mm'],
                ['86x86', 'quickLook', '38mm'],
                ['98x98', 'quickLook', '42mm'],
                ['108x108', 'quickLook', '44mm']
              ],
      '3x' => [['29x29', 'companionSettings']]
    },
    :watch_marketing => {
      '1x' => ['1024x1024']
    }
  }
end

.run(params) ⇒ Object



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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/fastlane/plugin/appicon/actions/appicon_action.rb', line 37

def self.run(params)
  fname = params[:appicon_image_file]
  basename = File.basename(fname, File.extname(fname))
  basepath = Pathname.new(File.join(params[:appicon_path], params[:appicon_name]))

  require 'mini_magick'
  image = MiniMagick::Image.open(fname)

  Helper::AppiconHelper.check_input_image_size(image, 1024)

  # Convert image to png
  image.format 'png'

  # remove alpha channel
  if params[:remove_alpha]
    image.alpha 'remove'
  end

  # Create the base path
  FileUtils.mkdir_p(basepath)

  images = []

  icons = Helper::AppiconHelper.get_needed_icons(params[:appicon_devices], self.needed_icons, false)
  icons.each do |icon|
    width = icon['width']
    height = icon['height']
    filename = "#{basename}-#{width.to_i}x#{height.to_i}.png"

    # downsize icon
    image.resize "#{width}x#{height}"

    # Don't write change/created times into the PNG properties
    # so unchanged files don't have different hashes.
    image.define("png:exclude-chunks=date,time")

    image.write basepath + filename

    info = {
      'size' => icon['size'],
      'idiom' => icon['device'],
      'filename' => filename,
      'scale' => icon['scale']
    }

    info['role'] = icon['role'] unless icon['role'].nil?
    info['subtype'] = icon['subtype'] unless icon['subtype'].nil?

    images << info
  end

  contents = {
    'images' => images,
    'info' => {
      'version' => 1,
      'author' => 'fastlane'
    }
  }

  require 'json'
  File.write(File.join(basepath, 'Contents.json'), JSON.pretty_generate(contents))
  UI.success("Successfully stored app icon at '#{basepath}'")
end