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:
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"
|
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
|
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"
|
Given a built app at "clean-nested-app" with flags "--no-clean"
|
||||||
Then a directory named "sub/dir" should exist
|
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:
|
Then the following files should exist:
|
||||||
| sub/dir/about.html |
|
| 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"
|
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:
|
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
|
# Remove files which were not built in this cycle
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def clean!
|
def clean!
|
||||||
files = @cleaning_queue.select { |q| q.file? }
|
@cleaning_queue.select { |q| q.file? }.each do |f|
|
||||||
directories = @cleaning_queue.select { |q| q.directory? }
|
|
||||||
|
|
||||||
files.each do |f|
|
|
||||||
base.remove_file f, :force => true
|
base.remove_file f, :force => true
|
||||||
end
|
end
|
||||||
|
|
||||||
directories = directories.sort_by {|d| d.to_s.length }.reverse!
|
Dir[File.join(@destination, "**", "*")].select { |d|
|
||||||
|
File.directory?(d)
|
||||||
directories.each do |d|
|
}.each do |d|
|
||||||
base.remove_file d, :force => true if directory_empty? d
|
base.remove_file d, :force => true if directory_empty? Pathname(d)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue