From 149f6ffa5b7dbde64299f93b877fe502f571a3e3 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Fri, 31 May 2013 21:20:15 -0400 Subject: [PATCH] fix builder not cleaning empty directories --- middleman-core/features/clean_build.feature | 23 ++++++++++++++++--- .../fixtures/clean-nested-app/config.rb | 4 +--- .../source/nested/nested.html | 1 + .../lib/middleman-core/cli/build.rb | 13 ++++------- 4 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 middleman-core/fixtures/clean-nested-app/source/nested/nested.html 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