/
Rakefile
75 lines (59 loc) 路 2.5 KB
/
Rakefile
1
2
3
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
36
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
require 'colored'
require 'mini_magick'
require 'json'
DEVICES_TO_SKIP = [
"Apple iMac Retina.png", # we don't currently support iMac
"Apple iMac.png" # we don't currently support iMac
]
task :generate_device_frames do
MiniMagick.configure do |config|
config.validate_on_create = false
end
puts "Download and extract the latest devices from Facebook"
puts ""
puts " http://facebook.design/devices"
puts ""
confirm
puts "Move the content of the zip file into './raw'"
mkdir("raw") unless File.directory?("raw")
system("open ./raw")
confirm
# Let's find all the image resources we need and copy it into the correct directory
current_time = Time.now.to_i.to_s
output = File.join("output", current_time)
sh "rm -rf output"
mkdir_p(output) unless File.directory?(output)
image_assets = []
(Dir["raw/Phones/Apple*/Device/*.png"] + Dir["raw/Computers/Apple*/Device/*.png"] + Dir["raw/Tablets/Apple*/Device/*.png"]).each do |current_raw|
next if DEVICES_TO_SKIP.include?(File.basename(current_raw))
cp(current_raw, output)
output_file_path = File.join(output, File.basename(current_raw))
convert_image_resource(output_file_path)
image_assets << File.basename(current_raw)
end
raise "Could not find any images, make sure to copy all extracted files into ./raw" if image_assets.count < 10
File.write(File.join(output, "files.json"), image_assets.to_json)
puts "Wrote names of available files to files.json"
File.write(File.join(output, "version.txt"), current_time)
puts "Wrote the current time stamp to version.txt"
cp("offsets.json", File.join(output, "offsets.json"))
puts "Copied over offsets.json"
cp_r(output, "output/latest")
system("open ./output")
puts "Done writing all the things to './output', please upload both the 'latest' and the time stamp '#{current_time}' folder to GitHub".green
puts "To do so, clone https://github.com/fastlane/frameit-frames, make sure to check out the `gh-pages` branch".green
puts "and overwrite the 'latest' folder, and copy the time stamp folder into the root.".green
puts "Push the changes, and run `frameit update_frames` to ensure everything worked as expected".green
end
def confirm
puts "Press any key when you're ready to continue".yellow
gets
end
# This will remove the white space around the actual frame
def convert_image_resource(path)
puts "Updating and trimming image file '#{path}'"
image = MiniMagick::Image.open(path)
image.trim
image.write(path)
end
task :default => [:generate_device_frames]