bin/ios-png-check in ios-png-check-1.0.0 vs bin/ios-png-check in ios-png-check-1.1.0

- old
+ new

@@ -1,35 +1,52 @@ #!/usr/bin/env ruby require 'rubygems' +require 'escape' require 'fileutils' # Main block def main files_wo_1x_version = [] files_wo_2x_version = [] size_errors = [] + empty_files = [] png_files = Dir.glob('*.png') png_files.each { |png_file| name_parts = png_file.split(/[@\.]/) + # next if name_parts.include? "&" + png_file_size = File.size?(png_file) + unless png_file_size + empty_files << png_file + next + end + v1x_exists = false v2x_exists = false if name_parts.length == 3 then v1_name = "#{name_parts[0]}.#{name_parts[2]}" v2_name = "#{name_parts[0]}@2x.#{name_parts[2]}" v1x_exists = File.exists?(v1_name) v2x_exists = File.exists?(v2_name) files_wo_1x_version << png_file unless v1x_exists - + + v2_file_size = File.size?(v2_name) + unless v2_file_size + empty_files << v2_name + next + end + if v1x_exists and v2x_exists then - v1_info = `file #{v1_name}`.match(/(\d+) x (\d+)/) - v2_info = `file #{v2_name}`.match(/(\d+) x (\d+)/) + cmd1 = Escape.shell_command(["file", v1_name]) + cmd2 = Escape.shell_command(["file", v2_name]) + v1_info = `#{cmd1}`.match(/(\d+) x (\d+)/) + v2_info = `#{cmd2}`.match(/(\d+) x (\d+)/) v1w = v1_info[1].to_i v1h = v1_info[2].to_i v2w = v2_info[1].to_i v2h = v2_info[2].to_i v2w_expected = v1w * 2 @@ -44,10 +61,16 @@ v1_name = "#{name_parts[0]}.#{name_parts[1]}" v2_name = "#{name_parts[0]}@2x.#{name_parts[1]}" v1x_exists = File.exists?(v1_name) v2x_exists = File.exists?(v2_name) files_wo_2x_version << png_file unless v2x_exists + + v1_file_size = File.size?(v1_name) + unless v1_file_size + empty_files << v1_name + next + end end } if png_files.empty? then puts "HEY, THERE'S NO PNG FILES IN THE CURRENT FOLDER." @@ -71,9 +94,16 @@ end unless size_errors.empty? then puts "INVALID IMAGE SIZES DETECTED FOR THE FOLLOWING FILES =================" puts size_errors + puts + is_all_okay = false + end + + unless empty_files.empty? then + puts "IMAGE FILES OF ZERO SIZE =============================================" + puts empty_files puts is_all_okay = false end if is_all_okay then