1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00

fix builder not cleaning empty directories

This commit is contained in:
Thomas Reynolds 2013-05-31 21:20:15 -04:00
parent 9d50cad910
commit 149f6ffa5b
4 changed files with 27 additions and 14 deletions

View file

@ -17,11 +17,28 @@ Feature: Build Clean
And the file "build/index.html" should contain "Comment in layout"
Scenario: Clean build an app with newly ignored files and a nested output directory
Given a fixture app "clean-nested-app"
When a file named "config.rb" with:
"""
set :build_dir, "sub/dir"
"""
Given a built app at "clean-nested-app" with flags "--no-clean"
Then a directory named "sub/dir" should exist
Then the following directories should exist:
| sub/dir |
| sub/dir/nested |
Then the following files should exist:
| sub/dir/about.html |
When I append to "config.rb" with "ignore 'about.html'"
| sub/dir/nested/nested.html |
When a file named "config.rb" with:
"""
set :build_dir, "sub/dir"
ignore 'about.html'
ignore 'nested/*'
"""
Given a built app at "clean-nested-app"
Then the following directories should not exist:
| sub/dir/nested |
Then the following files should not exist:
| sub/dir/about.html |
| sub/dir/nested/nested.html |

View file

@ -1,3 +1 @@
set :build_dir, "sub/dir"

View file

@ -205,17 +205,14 @@ module Middleman::Cli
# Remove files which were not built in this cycle
# @return [void]
def clean!
files = @cleaning_queue.select { |q| q.file? }
directories = @cleaning_queue.select { |q| q.directory? }
files.each do |f|
@cleaning_queue.select { |q| q.file? }.each do |f|
base.remove_file f, :force => true
end
directories = directories.sort_by {|d| d.to_s.length }.reverse!
directories.each do |d|
base.remove_file d, :force => true if directory_empty? d
Dir[File.join(@destination, "**", "*")].select { |d|
File.directory?(d)
}.each do |d|
base.remove_file d, :force => true if directory_empty? Pathname(d)
end
end