lib/jekyll/webpack.rb in jekyll-webpack-0.2.2 vs lib/jekyll/webpack.rb in jekyll-webpack-0.2.3

- old
+ new

@@ -18,9 +18,29 @@ runtime_error = stdout =~ /ERROR in|SyntaxError/ raise Error, stderr if stderr.size > 0 raise Error, stdout if !runtime_error.nil? + + cleanup(site) + end + + def self.cleanup(site) + cleanup_files = site.config.dig('webpack', 'cleanup_files') + + if cleanup_files + if Array === cleanup_files + cleanup_files.each do |dest_for_clean| + if Dir.exists?(File.expand_path(dest_for_clean, site.dest)) + FileUtils.rm_rf(File.expand_path(dest_for_clean, site.dest)) + end + end + else + if Dir.exists?(File.expand_path(cleanup_files, site.dest)) + FileUtils.rm_rf(File.expand_path(dest_src_for_clean, site.dest)) + end + end + end end end end Jekyll::Hooks.register :site, :post_write do |site|