Created
May 14, 2014 14:24
-
-
Save jordanthomas/1fd54d059e26516fd2f6 to your computer and use it in GitHub Desktop.
Screenshots of your project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# Script to checkout each revision of a middleman project and take a screenshot. | |
require 'fileutils' | |
commits = `git rev-list master`.split("\n").reverse | |
resolution = '1400x900' | |
url = 'http://127.0.0.1:4567/' | |
step = 20 # Step by this many commits after each screenshot. | |
wd = Dir.getwd | |
out = File.join('./', 'screenshots') | |
count = 0 | |
Kernel.at_exit { | |
Dir.chdir(wd) | |
`git checkout -q master` | |
if pid | |
Process.kill(:SIGINT, pid) | |
Process.wait(pid) | |
end | |
} | |
FileUtils.mkdir_p(out) | |
(0...commits.length).step(step).each do |i| | |
commit = commits[i] | |
short_sha = commit[0,10] | |
sequence = "%04d" % count | |
count = count + 1 | |
puts "Checking out #{short_sha}..." | |
`git checkout -q #{commit}` | |
timestamp = `git show #{commit} -s --date relative --format="%ad"` | |
`bundle install` | |
# Start middeman and capture PID | |
pid = Process.spawn('bundle exec middleman server') | |
sleep(5) # Give Middleman a moment to fire up. | |
puts "Creating screenshot of #{url}..." | |
Dir.chdir(out) | |
`capturejs -u #{url} -V #{resolution} -o #{sequence}.png` | |
# Kill middleman and wait for it to exit. | |
Process.kill(:SIGINT, pid) | |
Process.wait(pid) | |
# Write the commit's timestamp onto the screenshot. If you don't have office | |
# installed you might pick a different font. | |
`convert #{sequence}.png -font /Library/Fonts/Microsoft/Arial\\ Bold.ttf -pointsize 50 -draw "gravity northeast fill black text 50,50 '#{timestamp}'" #{sequence}.png` | |
Dir.chdir(wd) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment