lib/marv/builder.rb in marv-0.3.0 vs lib/marv/builder.rb in marv-0.3.1
- old
+ new
@@ -65,11 +65,13 @@
end
# Empty out the build directory
def clean_build_directory
# create build path if it does not exist
- FileUtils.mkdir_p(@project.build_path) unless File.exists?(@project.build_path)
+ unless File.exists?(@project.build_path)
+ FileUtils.mkdir_p(@project.build_path)
+ end
# Empty the build path
FileUtils.rm_rf Dir.glob(File.join(@project.build_path, '*'))
end
def clean_templates
@@ -77,11 +79,15 @@
Dir.glob(File.join(@project.build_path, '*.php')).each do |path|
FileUtils.rm path unless path.include?('functions.php')
end
end
- def copy_templates
+ def copy_templates(clean=nil)
+ unless clean.nil?
+ clean_templates
+ end
+
template_paths.each do |template_path|
# Skip directories
next if File.directory?(template_path)
if template_path.end_with?('.erb')
@@ -96,18 +102,30 @@
end
end
def clean_functions
#remove functions php
- FileUtils.rm File.join(@project.build_path, 'functions.php') if File.exists?(File.join(@project.build_path, 'functions.php'))
+ if File.exists?(File.join(@project.build_path, 'functions.php'))
+ FileUtils.rm File.join(@project.build_path, 'functions.php')
+ end
# Remove plugin file
- FileUtils.rm File.join(@project.build_path, @project.project_php_file) if File.exists?(@project.project_php_file)
+ if File.exists?(@project.project_php_file)
+ FileUtils.rm File.join(@project.build_path, @project.project_php_file)
+ end
# Remove functions folder
- FileUtils.rm_rf File.join(@project.build_path, 'functions') if File.directory?(File.join(@project.build_path, 'functions'))
+ if File.directory?(File.join(@project.build_path, 'functions'))
+ FileUtils.rm_rf File.join(@project.build_path, 'functions')
+ end
end
- def copy_functions
+ def copy_functions(clean=nil)
+ # Clean functions
+ unless clean.nil?
+ clean_functions
+ end
+
+ # Copy functions
functions_erb_path = File.join(@functions_path, 'functions.php.erb')
functions_php_path = File.join(@functions_path, 'functions.php')
plugin_php_path = File.join(@functions_path, @project.project_php_file)
if File.exists?(functions_erb_path)
@@ -125,51 +143,65 @@
[functions_erb_path, functions_php_path, plugin_php_path].include?(filename)
end
unless functions_paths.empty?
# Create the functions folder in the build directory
- FileUtils.mkdir_p(File.join(@project.build_path, 'functions'))
+ unless File.directory?(File.join(@project.build_path, 'functions'))
+ FileUtils.mkdir_p(File.join(@project.build_path, 'functions'))
+ end
# Iterate over all files in source/functions, skipping the actual functions.php file
- paths = Dir.glob(File.join(@functions_path, '**', '*')).reject {|filename| [functions_erb_path, functions_php_path, plugin_php_path].include?(filename) }
+ paths = Dir.glob(File.join(@functions_path, '**', '*')).reject do |filename|
+ [functions_erb_path, functions_php_path, plugin_php_path].include?(filename)
+ end
copy_paths_with_erb(paths, @functions_path, File.join(@project.build_path, 'functions'))
end
end
def clean_includes
FileUtils.rm_rf File.join(@project.build_path, 'includes')
end
- def copy_includes
+ def copy_includes(clean=nil)
+ # Clean Includes
+ unless clean.nil?
+ clean_includes
+ end
+
+ # Copy includes
unless Dir.glob(File.join(@includes_path, '*')).empty?
# Create the includes folder in the build directory
- FileUtils.mkdir(File.join(@project.build_path, 'includes'))
+ unless File.directory?(File.join(@project.build_path, 'includes'))
+ FileUtils.mkdir(File.join(@project.build_path, 'includes'))
+ end
# Iterate over all files in source/includes, so we can exclude if necessary
paths = Dir.glob(File.join(@includes_path, '**', '*'))
copy_paths_with_erb(paths, @includes_path, File.join(@project.build_path, 'includes'))
end
end
- def clean_folders
- Dir.glob(File.join(@project.source_path, '*')).each do |folder|
- unless [@assets_path, @templates_path, @functions_path, @includes_path].include?(folder)
- if File.directory?(folder)
- relative_path = folder.gsub(@project.source_path, '')
- destination = File.join(@project.build_path, relative_path)
+ def clean_folders(folder)
+ # Clean folder
+ relative_path = folder.gsub(@project.source_path, '')
+ destination = File.join(@project.build_path, relative_path)
- FileUtils.rm_rf destination
- end
- end
- end
+ FileUtils.rm_rf destination
end
- def copy_folders
- Dir.glob(File.join(@project.source_path, '*')).each do |folder|
- unless [@assets_path, @templates_path, @functions_path, @includes_path].include?(folder)
- if File.directory?(folder)
+ def copy_folders(clean=nil)
+ folders = Dir.glob(File.join(@project.source_path, '*'))
+
+ folders.each do |folder|
+ if File.directory?(folder)
+ unless [@assets_path, @templates_path, @functions_path, @includes_path].include?(folder)
+ # Clean folders
+ unless clean.nil?
+ clean_folders(folder)
+ end
+ # Copy folders
paths = Dir.glob(File.join(folder, '**', '*'))
copy_paths_with_erb(paths, @project.source_path, @project.build_path)
end
end
end
@@ -177,11 +209,17 @@
def clean_images
FileUtils.rm_rf File.join(@project.build_path, 'images')
end
- def build_assets
+ def build_assets(clean=nil)
+ # Clean images
+ unless clean.nil?
+ clean_images
+ end
+
+ # Build assets
default_assets = [['style.css'], ['admin.css'], ['javascripts', 'theme.js'], ['javascripts', 'admin.js']]
additional_assets = @project.config[:additional_assets]
if additional_assets
assets = default_assets + additional_assets
@@ -213,10 +251,12 @@
init_sprockets
end
end
# Copy the images directory over
- FileUtils.cp_r(File.join(@assets_path, 'images'), @project.build_path) if File.exists?(File.join(@assets_path, 'images'))
+ if File.directory?(File.join(@assets_path, 'images'))
+ FileUtils.cp_r(File.join(@assets_path, 'images'), @project.build_path)
+ end
# Check for screenshot and move it into main build directory
Dir.glob(File.join(@project.build_path, 'images', '*')).each do |filename|
if filename.index(/screenshot\.(png|jpg|jpeg|gif)/)
FileUtils.mv(filename, @project.build_path + File::SEPARATOR )