Created
November 17, 2009 19:39
-
-
Save briandonahue/237200 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'Albacore' | |
require 'fileutils' | |
class DeepCopy | |
include Logging | |
attr_accessor :source_dir, :dest_dir, :extensions, :includes, :excludes | |
def initialize | |
super() | |
@extensions = [] | |
@includes = [] | |
@excludes = [] | |
end | |
def copy | |
return if @source_dir.nil? | |
return if @dest_dir.nil? | |
copy_files_recursively @source_dir, @dest_dir, @extensions, @includes, @excludes | |
end | |
private | |
def copy_files_recursively(source_dir, dest_dir, file_exts, includes, excludes) | |
files = FileList.new | |
base_pattern = "#{source_dir}**/" | |
unless file_exts.empty? | |
file_exts.each do |ext| | |
files.include("#{base_pattern}*.#{ext}") | |
end | |
end | |
unless excludes.empty? | |
excludes.each do |exclude_pattern| | |
files.exclude("#{base_pattern}#{exclude_pattern}") | |
end | |
end | |
unless includes.empty? | |
includes.each do |include_pattern| | |
files.exclude("#{base_pattern}#{include_pattern}") | |
end | |
end | |
files.each do |file| | |
copy_path = File.join(dest_dir, file.gsub(source_dir, "")) | |
sub_dir = File.dirname(copy_path) | |
mkdir_p sub_dir unless (Dir.exists?(sub_dir)) | |
cp file, copy_path | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "Copy website files to deployment folder" | |
task :website_dist do | |
create_webproject_distributable(WEBSITE_SRC, DEPLOY_DIR) | |
end | |
def create_webproject_distributable(web_src, deploy_root) | |
rm_r deploy_root if Dir.exists?(deploy_root) | |
dc = DeepCopy.new | |
dc.extensions = ["dll", "aspx", "ascx", "svc", "asmx", "ashx", "asax", "config", | |
"resx", "jpg", "gif", "png", "css", "js", "swf", "lic", "xml"] | |
dc.excludes = ["obj/**", "upload/**"] | |
dc.source_dir = web_src | |
dc.dest_dir = File.join(deploy_root, web_src) | |
dc.copy | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment