Skip to content

Instantly share code, notes, and snippets.

@trak3r
Forked from JackDanger/prune_vendor.rake
Created March 25, 2010 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trak3r/343055 to your computer and use it in GitHub Desktop.
Save trak3r/343055 to your computer and use it in GitHub Desktop.
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