Skip to content

Instantly share code, notes, and snippets.

@phiggins phiggins/css_diff.rb
Created Jun 29, 2016

Embed
What would you like to do?
branches = %w[ master switch-to-sassc ]
tmp = Pathname.new(Dir.tmpdir)
branches.each do |branch|
asset_dir = tmp + "assets_#{branch}"
if asset_dir.exist?
puts "#{asset_dir} exists, skipping"
next
end
FileUtils.rm_rf Rails.root + "tmp/cache"
FileUtils.rm_rf Rails.root + "public/assets"
print "precompiling #{branch}... "
puts(Benchmark.realtime {
system "git checkout #{branch} && rake assets:precompile", out: IO::NULL, err: IO::NULL
})
FileUtils.mv (Rails.root + "public/assets"), asset_dir
end
first, second = *branches.map { |branch|
Dir[tmp + "assets_#{branch}" + "**" + "*.css"].sort
}
first.zip(second).each do |file1, file2|
puts "diffing:"
puts file1
puts file2
# Remove lines of just whitespace
#[file1, file2].each { |file| `sed -i "/^\s*$/d" #{file}` }
# Remove comments
#[file1, file2].each { |file| `sed -i "|^/\*|d" #{file}` }
css_diff = `css-diff #{file1} #{file2}`
if css_diff.strip == "true"
puts `diff --text --ignore-space-change --report-identical-files #{file1} #{file2}`
else
puts "Files are syntactically identical."
end
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.