lib/hanami/assets/precompiler.rb in hanami-assets-0.2.1 vs lib/hanami/assets/precompiler.rb in hanami-assets-0.3.0
- old
+ new
@@ -1,5 +1,6 @@
+require 'fileutils'
require 'hanami/assets/compiler'
module Hanami
module Assets
# Precompile all the assets, coming from all the applications and third
@@ -28,26 +29,39 @@
# Start the process
#
# @since 0.1.0
# @api private
def run
- clear_public_directory
+ clear_assets_directory
precompile
end
private
- # @since 0.1.0
+ # @since 0.3.0
# @api private
- def clear_public_directory
- public_directory = @configuration.public_directory
- public_directory.rmtree if public_directory.exist?
+ def clear_assets_directory
+ delete @configuration.manifest_path
+ delete @configuration.destination_directory
end
+ # @since 0.3.0
+ # @api private
+ def clear_manifest(manifest)
+ JSON.load(manifest).each do |_, asset_hash|
+ asset_file_name = @configuration.public_directory.join(asset_hash['target'])
+ asset_file_name.unlink if asset_file_name.exist?
+ end
+ rescue JSON::ParserError
+ $stderr.puts 'Non JSON manifest found and unlinked.'
+ ensure
+ manifest.unlink
+ end
+
# @since 0.1.0
# @api private
- def precompile
+ def precompile # rubocop:disable Metrics/MethodLength
applications.each do |duplicate|
config = if duplicate.respond_to?(:configuration)
duplicate.configuration
else
duplicate
@@ -62,11 +76,20 @@
end
# @since 0.1.0
# @api private
def applications
- @duplicates.empty? ?
- [@configuration] : @duplicates
+ if @duplicates.empty?
+ [@configuration]
+ else
+ @duplicates
+ end
+ end
+
+ # @since 0.3.0
+ # @api private
+ def delete(path)
+ FileUtils.rm_rf(path) if path.exist?
end
end
end
end