Created
March 24, 2010 20:24
-
-
Save JackDanger/342746 to your computer and use it in GitHub Desktop.
crazy-compress your ./vendor dir
This file contains 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
namespace :prune do | |
desc "Delete all unnecessary files from vendored Rails" | |
task :rails do | |
require 'fileutils' | |
list = Dir.glob("vendor/rails/*/test") | |
FileUtils.rm_rf list, :verbose => true unless list.empty? | |
end | |
desc "Trim whitespace and full-line comments from all vendored ruby source" | |
task :ruby_source do | |
patterns = [ | |
'/^ *#[^\{].*$/g', # remove lines that are just comments (not #{} interpolation) | |
'/^ *$/d', # remove lines that are all whitespace | |
's/^ *\(.*\)$/\1/g' # remove whitespace before content | |
].map {|p| " -e #{p.inspect} "}.join | |
compress = %Q{sed -i '' #{patterns}} | |
require 'fileutils' | |
iterate = proc do |directory| | |
Dir.glob("#{directory}/*").each do |item| | |
if File.directory?(item) | |
iterate.call(item) | |
elsif item =~ /\.rb$/ | |
system "#{compress} #{item}" | |
end | |
end | |
end | |
iterate.call "vendor" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment