Fix build --clean and generally make it more robust by dealing with absolute Pathnames instead of regexing paths.

This commit is contained in:
Ben Hollis 2012-01-04 00:21:44 -08:00
parent c5063c1e35
commit 14581c126d

View file

@ -144,14 +144,14 @@ module Middleman::Cli
# Remove files which were not built in this cycle # Remove files which were not built in this cycle
# @return [void] # @return [void]
def clean! def clean!
files = @cleaning_queue.select { |q| File.file? q } files = @cleaning_queue.select { |q| q.file? }
directories = @cleaning_queue.select { |q| File.directory? q } directories = @cleaning_queue.select { |q| q.directory? }
files.each do |f| files.each do |f|
base.remove_file f, :force => true base.remove_file f, :force => true
end end
directories = directories.sort_by {|d| d.length }.reverse! directories = directories.sort_by {|d| d.to_s.length }.reverse!
directories.each do |d| directories.each do |d|
base.remove_file d, :force => true if directory_empty? d base.remove_file d, :force => true if directory_empty? d
@ -168,7 +168,7 @@ module Middleman::Cli
# @param [String] directory # @param [String] directory
# @return [Boolean] # @return [Boolean]
def directory_empty?(directory) def directory_empty?(directory)
Dir[File.join(directory, "*")].empty? directory.children.empty?
end end
# Get a list of all the paths in the destination folder and save them # Get a list of all the paths in the destination folder and save them
@ -179,7 +179,7 @@ module Middleman::Cli
Find.find(@destination) do |path| Find.find(@destination) do |path|
next if path.match(/\/\./) && !path.match(/\.htaccess/) next if path.match(/\/\./) && !path.match(/\.htaccess/)
unless path == destination unless path == destination
@cleaning_queue << path.sub(@destination, destination[/([^\/]+?)$/]) @cleaning_queue << Pathname.new(path)
end end
end if File.exist?(@destination) end if File.exist?(@destination)
end end
@ -219,11 +219,11 @@ module Middleman::Cli
file_destination = base.tilt_template(file_source, file_destination) file_destination = base.tilt_template(file_source, file_destination)
@cleaning_queue.delete(file_destination) if cleaning? @cleaning_queue.delete(Pathname.new(file_destination).realpath) if cleaning?
end end
end end
end end
# Alias "b" to "build" # Alias "b" to "build"
Base.map({ "b" => "build" }) Base.map({ "b" => "build" })
end end