Adding: CLI -C --clean build option.
This commit is contained in:
parent
62e27a7a08
commit
2d41468ad4
2 changed files with 39 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
require "thor"
|
require "thor"
|
||||||
require "thor/group"
|
require "thor/group"
|
||||||
require 'rack/test'
|
require 'rack/test'
|
||||||
|
require 'find'
|
||||||
|
|
||||||
SHARED_SERVER = Middleman.server
|
SHARED_SERVER = Middleman.server
|
||||||
SHARED_SERVER.set :environment, :build
|
SHARED_SERVER.set :environment, :build
|
||||||
|
@ -182,11 +183,13 @@ module Middleman
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
handle_path(file_source)
|
dequeue_file handle_path(file_source)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute!
|
def execute!
|
||||||
|
queue_current_paths @destination
|
||||||
|
|
||||||
handle_directory(source) do |path|
|
handle_directory(source) do |path|
|
||||||
file_name = path.gsub(SHARED_SERVER.views + "/", "")
|
file_name = path.gsub(SHARED_SERVER.views + "/", "")
|
||||||
if file_name == "layouts"
|
if file_name == "layouts"
|
||||||
|
@ -197,6 +200,40 @@ module Middleman
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
clean_up_queue if base.options.has_key?("clean") && base.options["clean"]
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def clean_up_queue
|
||||||
|
files = @cleaning_queue.select { |q| File.file? q }
|
||||||
|
directories = @cleaning_queue.select { |q| File.directory? q }
|
||||||
|
|
||||||
|
files.each { |f| base.remove_file f, config }
|
||||||
|
|
||||||
|
directories.sort_by! {|d| d.length }.reverse!
|
||||||
|
|
||||||
|
directories.each do |d|
|
||||||
|
base.remove_file(d, config) if directory_empty? d
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def directory_empty?(directory)
|
||||||
|
Dir["#{directory}/*"].empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
def queue_current_paths(destination)
|
||||||
|
@cleaning_queue = []
|
||||||
|
Find.find(destination) do |path|
|
||||||
|
unless path == destination
|
||||||
|
@cleaning_queue << @relative_destination + path.sub(destination,'')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def dequeue_file(path)
|
||||||
|
@cleaning_queue.delete_if {|q| q == path }
|
||||||
|
return path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -50,6 +50,7 @@ module Middleman
|
||||||
|
|
||||||
desc "build", "Builds the static site for deployment"
|
desc "build", "Builds the static site for deployment"
|
||||||
method_option :relative, :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
|
method_option :relative, :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
|
||||||
|
method_option :clean, :type => :boolean, :aliases => "-c", :default => false, :desc => 'Builds a clean project removing any orpahand files or directories'
|
||||||
method_option :glob, :type => :string, :aliases => "-g", :default => nil, :desc => 'Build a subset of the project'
|
method_option :glob, :type => :string, :aliases => "-g", :default => nil, :desc => 'Build a subset of the project'
|
||||||
def build
|
def build
|
||||||
v1_check
|
v1_check
|
||||||
|
|
Loading…
Reference in a new issue