diff --git a/middleman-core/features/clean_build.feature b/middleman-core/features/clean_build.feature index fd8e1c4a..e5254df4 100644 --- a/middleman-core/features/clean_build.feature +++ b/middleman-core/features/clean_build.feature @@ -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 | diff --git a/middleman-core/fixtures/clean-nested-app/config.rb b/middleman-core/fixtures/clean-nested-app/config.rb index de126643..e0438734 100644 --- a/middleman-core/fixtures/clean-nested-app/config.rb +++ b/middleman-core/fixtures/clean-nested-app/config.rb @@ -1,3 +1 @@ -set :build_dir, "sub/dir" - - +set :build_dir, "sub/dir" \ No newline at end of file diff --git a/middleman-core/fixtures/clean-nested-app/source/nested/nested.html b/middleman-core/fixtures/clean-nested-app/source/nested/nested.html new file mode 100644 index 00000000..40816a2b --- /dev/null +++ b/middleman-core/fixtures/clean-nested-app/source/nested/nested.html @@ -0,0 +1 @@ +Hi \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/cli/build.rb b/middleman-core/lib/middleman-core/cli/build.rb index e068d3ac..a3261d2e 100644 --- a/middleman-core/lib/middleman-core/cli/build.rb +++ b/middleman-core/lib/middleman-core/cli/build.rb @@ -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