Class: Fastlane::Actions::AppiconAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::AppiconAction
- Defined in:
- lib/fastlane/plugin/appicon/actions/appicon_action.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .needed_icons ⇒ Object
- .needed_icons_messages_extension ⇒ Object
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
163 164 165 |
# File 'lib/fastlane/plugin/appicon/actions/appicon_action.rb', line 163 def self. ["@NeoNacho"] end |
.available_options ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/fastlane/plugin/appicon/actions/appicon_action.rb', line 167 def self. [ 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: :appicon_messages_name, env_name: "APPICON_MESSAGES_NAME", default_value: 'AppIcon.stickersiconset', 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), FastlaneCore::ConfigItem.new(key: :messages_extension, env_name: "APPICON_MESSAGES_EXTENSION", default_value: false, description: "App icon is generated for Messages extension", optional: true, type: Boolean), FastlaneCore::ConfigItem.new(key: :minimagick_cli, env_name: "APPICON_MINIMAGICK_CLI", description: "Set MiniMagick CLI (auto picked by default). Values are: graphicsmagick, imagemagick", optional: true, type: String, verify_block: proc do |value| av = %w(graphicsmagick imagemagick) UI.user_error!("Unsupported minimagick cli '#{value}', must be: #{av}") unless av.include?(value) end) ] end |
.description ⇒ Object
159 160 161 |
# File 'lib/fastlane/plugin/appicon/actions/appicon_action.rb', line 159 def self.description "Generate required icon sizes and iconset from a master application icon" end |
.is_supported?(platform) ⇒ Boolean
223 224 225 |
# File 'lib/fastlane/plugin/appicon/actions/appicon_action.rb', line 223 def self.is_supported?(platform) [:ios, :mac, :macos, :caros, :rocketos].include?(platform) end |
.needed_icons ⇒ Object
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 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fastlane/plugin/appicon/actions/appicon_action.rb', line 7 def self.needed_icons { universal: { '1x' => ['2732x2732'], '2x' => ['2732x2732'], '3x' => ['2732x2732'] }, 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'] }, :macos => { '1x' => ['16x16', '32x32', '128x128', '256x256', '512x512'], '2x' => ['16x16', '32x32', '128x128', '256x256', '512x512'], } } end |
.needed_icons_messages_extension ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fastlane/plugin/appicon/actions/appicon_action.rb', line 49 def self. { iphone: { '2x' => ['60x45'], '3x' => ['60x45'] }, ipad: { '2x' => ['67x50', '74x55'] }, messages: { '2x' => ['27x20', '32x24'], '3x' => ['27x20', '32x24'] }, ios_marketing: { '1x' => ['1024x768'] } } end |
.run(params) ⇒ Object
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 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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/fastlane/plugin/appicon/actions/appicon_action.rb', line 68 def self.run(params) fname = params[:appicon_image_file] basename = File.basename(fname, File.extname(fname)) Helper::AppiconHelper.set_cli(params[:minimagick_cli]) = params[:messages_extension] basepath = Pathname.new(File.join(params[:appicon_path], ? params[:appicon_messages_name] : params[:appicon_name])) image = MiniMagick::Image.open(fname) if Helper::AppiconHelper.check_input_image_size(image, 1024, 768) else Helper::AppiconHelper.check_input_image_size(image, 1024, 1024) end # Convert image to png image.format 'png' # remove alpha channel if params[:remove_alpha] image.alpha 'remove' end # Recreate the base path FileUtils.rm_rf(basepath) FileUtils.mkdir_p(basepath) images = [] icons = Helper::AppiconHelper.get_needed_icons(params[:appicon_devices], ? self. : self.needed_icons, false) icons.each do |icon| width = icon['width'] height = icon['height'] filename = basename unless icon['device'] == 'universal' filename += "-#{width.to_i}x#{height.to_i}" end filename += ".png" # downsize icon # "!" resizes to exact size (needed for messages extension) 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 = { 'idiom' => icon['device'], 'filename' => filename, 'scale' => icon['scale'] } # if device is messages, we need to set it to universal if icon['device'] == 'messages' info['idiom'] = 'universal' info['platform'] = 'ios' end # if device is ios_marketing but we are generating messages extension app, set the idiom correctly if icon['device'] == 'ios_marketing' && info['platform'] = 'ios' end unless icon['device'] == 'universal' info['size'] = icon['size'] end 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' } } File.write(File.join(basepath, 'Contents.json'), JSON.pretty_generate(contents)) UI.success("Successfully stored app icon at '#{basepath}'") end |