Merge pull request #227 from bhollis/clean

Fix "build --clean" when the output path is a nested directory
This commit is contained in:
Thomas Reynolds 2012-01-05 00:49:40 -08:00
commit 1746a4bf25
6 changed files with 42 additions and 23 deletions

View file

@ -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 |

View file

@ -1 +1,2 @@
activate :directory_indexes
activate :directory_indexes

View file

@ -0,0 +1,3 @@
set :build_dir, "sub/dir"

View file

@ -0,0 +1 @@
Fun times

View file

@ -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
end

View file

@ -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)