diff --git a/middleman-core/features/clean_build.feature b/middleman-core/features/clean_build.feature index e70d5d3e..e9400558 100644 --- a/middleman-core/features/clean_build.feature +++ b/middleman-core/features/clean_build.feature @@ -3,29 +3,39 @@ Feature: Build Clean Given a fixture app "clean-app" And app "clean-app" is using config "empty" And a successfully built app at "clean-app" + Then the following files should exist: + | build/index.html | + | build/should_be_ignored.html | + | build/should_be_ignored2.html | + | build/should_be_ignored3.html | And app "clean-app" is using config "complications" - Given a successfully built app at "clean-app" with flags "--clean" - When I cd to "build" Then the following files should not exist: - | should_be_ignored.html | - | should_be_ignored2.html | - | should_be_ignored3.html | - And the file "index.html" should contain "Comment in layout" + | build/should_be_ignored.html | + | build/should_be_ignored2.html | + | build/should_be_ignored3.html | + And the file "build/index.html" should contain "Comment in layout" Scenario: Clean an app with directory indexes Given a successfully built app at "clean-dir-app" - When I cd to "build" Then the following files should exist: - | about/index.html | - + | build/about/index.html | Given a successfully built app at "clean-dir-app" with flags "--clean" - When I cd to "build" Then the following files should exist: - | about/index.html | - + | build/about/index.html | + Scenario: Clean build an app that's never been built Given a successfully built app at "clean-dir-app" with flags "--clean" - When I cd to "build" Then the following files should exist: - | about/index.html | + | build/about/index.html | + + Scenario: Clean build an app with newly ignored files and a nested output directory + Given a built app at "clean-nested-app" + Then a directory named "sub/dir" should exist + Then the following files should exist: + | sub/dir/about.html | + When I append to "config.rb" with "ignore 'about.html'" + Given a built app at "clean-nested-app" with flags "--clean" + Then the following files should not exist: + | sub/dir/about.html | + diff --git a/middleman-core/fixtures/clean-dir-app/config.rb b/middleman-core/fixtures/clean-dir-app/config.rb index f343b291..065e6f0e 100644 --- a/middleman-core/fixtures/clean-dir-app/config.rb +++ b/middleman-core/fixtures/clean-dir-app/config.rb @@ -1 +1,2 @@ -activate :directory_indexes \ No newline at end of file +activate :directory_indexes + diff --git a/middleman-core/fixtures/clean-nested-app/config.rb b/middleman-core/fixtures/clean-nested-app/config.rb new file mode 100644 index 00000000..de126643 --- /dev/null +++ b/middleman-core/fixtures/clean-nested-app/config.rb @@ -0,0 +1,3 @@ +set :build_dir, "sub/dir" + + diff --git a/middleman-core/fixtures/clean-nested-app/source/about.html b/middleman-core/fixtures/clean-nested-app/source/about.html new file mode 100644 index 00000000..c4c4ce51 --- /dev/null +++ b/middleman-core/fixtures/clean-nested-app/source/about.html @@ -0,0 +1 @@ +Fun times \ 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 4d84bbec..1cc766bc 100644 --- a/middleman-core/lib/middleman-core/cli/build.rb +++ b/middleman-core/lib/middleman-core/cli/build.rb @@ -144,14 +144,14 @@ module Middleman::Cli # Remove files which were not built in this cycle # @return [void] def clean! - files = @cleaning_queue.select { |q| File.file? q } - directories = @cleaning_queue.select { |q| File.directory? q } + files = @cleaning_queue.select { |q| q.file? } + directories = @cleaning_queue.select { |q| q.directory? } files.each do |f| base.remove_file f, :force => true end - directories = directories.sort_by {|d| d.length }.reverse! + directories = directories.sort_by {|d| d.to_s.length }.reverse! directories.each do |d| base.remove_file d, :force => true if directory_empty? d @@ -168,7 +168,7 @@ module Middleman::Cli # @param [String] directory # @return [Boolean] def directory_empty?(directory) - Dir[File.join(directory, "*")].empty? + directory.children.empty? end # Get a list of all the paths in the destination folder and save them @@ -179,7 +179,7 @@ module Middleman::Cli Find.find(@destination) do |path| next if path.match(/\/\./) && !path.match(/\.htaccess/) unless path == destination - @cleaning_queue << path.sub(@destination, destination[/([^\/]+?)$/]) + @cleaning_queue << Pathname.new(path) end end if File.exist?(@destination) end @@ -219,11 +219,11 @@ module Middleman::Cli file_destination = base.tilt_template(file_source, file_destination) - @cleaning_queue.delete(file_destination) if cleaning? + @cleaning_queue.delete(Pathname.new(file_destination).realpath) if cleaning? end end end # Alias "b" to "build" Base.map({ "b" => "build" }) -end \ No newline at end of file +end diff --git a/middleman-core/lib/middleman-core/step_definitions/builder_steps.rb b/middleman-core/lib/middleman-core/step_definitions/builder_steps.rb index 16fad844..e52c57bd 100644 --- a/middleman-core/lib/middleman-core/step_definitions/builder_steps.rb +++ b/middleman-core/lib/middleman-core/step_definitions/builder_steps.rb @@ -2,12 +2,16 @@ require 'fileutils' Given /^app "([^\"]*)" is using config "([^\"]*)"$/ do |path, config_name| target = File.join(PROJECT_ROOT_PATH, "fixtures", path) - config_path = File.join(target, "config-#{config_name}.rb") + config_path = File.join(current_dir, "config-#{config_name}.rb") config_dest = File.join(current_dir, "config.rb") FileUtils.cp(config_path, config_dest) end Given /^a fixture app "([^\"]*)"$/ do |path| + # This step can be reentered from several places but we don't want + # to keep re-copying and re-cd-ing into ever-deeper directories + next if File.basename(current_dir) == path + step %Q{a directory named "#{path}"} target_path = File.join(PROJECT_ROOT_PATH, "fixtures", path)