fix builder not cleaning empty directories
This commit is contained in:
parent
9d50cad910
commit
149f6ffa5b
4 changed files with 27 additions and 14 deletions
|
@ -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/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/about.html |
|
||||
| sub/dir/nested/nested.html |
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
set :build_dir, "sub/dir"
|
||||
|
||||
|
||||
set :build_dir, "sub/dir"
|
|
@ -0,0 +1 @@
|
|||
Hi
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue