Created
February 4, 2010 17:06
-
-
Save jdlich/294874 to your computer and use it in GitHub Desktop.
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
# encoding: utf-8 | |
desc 'Removes all stray files from the output directory' | |
task :clean_all do | |
puts '=== Removing stray files from output directory…' | |
# Get static files | |
static_files = Dir['assets/**/*'].select { |f| File.file?(f) }.map { |f| f.sub(/^assets\//, 'output/') } | |
# Get compiled files | |
site = Nanoc3::Site.new('.') | |
site.load_data | |
compiled_files = site.items.map do |item| | |
item.reps.map do |rep| | |
rep.raw_path | |
end | |
end.flatten.compact.select { |f| File.file?(f) } | |
# Get present files | |
present_files = Dir['output/**/*'].select { |f| File.file?(f) } | |
# Remove stray files | |
stray_files = present_files - static_files - compiled_files | |
stray_files.each { |f| FileUtils.rm(f) } | |
# TODO Remove empty directories | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment