require 'active_support/all' require 'fileutils' require 'json' require 'yaml' require_relative 'load_sprockets' ######################################################################################################################## Plugin = Fanforce::Plugin Plugin.config.load_global_paths Plugin.config.load_env PluginWorker = Fanforce::PluginWorker ######################################################################################################################## namespace :assets do desc 'Precompile assets for production' task :precompile => :clean do config = Plugin.config sprockets = SprocketsCompiler.setup(config.base_dir) puts 'PRECOMPILING ASSETS... ' SprocketsCompiler.new(sprockets: sprockets, precompile: [/(\/|^)[^_\/]+[^\/]*\.(css|js|png|gif|jpeg|jpg|otf|eot|svg|ttf|woff)/]).compile puts 'DONE' print 'GENERATING ASSET MANIFESTS... ' asset_list = {} sprockets.each_logical_path do |logical_path| if File.basename(logical_path) !~ /^[_]/ and asset = sprockets.find_asset(logical_path) asset_list[logical_path] = "/assets/#{asset.digest_path}" end end IO.write File.join(config.base_dir, '/public/asset_manifest.json'), JSON.generate(asset_list) IO.write File.join(config.base_dir, '/public/asset_manifest.json'), "ASSETS=#{JSON.generate(asset_list)}" IO.write File.join(config.base_dir, '/public/asset_manifest.json'), asset_list.to_yaml puts 'DONE' end desc 'Clean assets folder' task :clean do print 'DESTROYING PUBLIC/ASSETS... ' FileUtils.rm_rf File.join(Plugin.config.base_dir, '/public/assets') puts 'DONE' end task :test do puts 'TEST WORKED!' end end