require 'fileutils' require 'json' require 'yaml' require_relative 'load_sprockets' ######################################################################################################################## App = Fanforce::App App.config.load_env AppWorker = Fanforce::AppWorker ######################################################################################################################## namespace :assets do desc 'Precompile assets for production' task :precompile => :clean do config = App.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(App.config.base_dir, '/public/assets') puts 'DONE' end task :test do puts 'TEST WORKED!' end end