require 'fanforce' require 'fileutils' require 'json' require 'yaml' require_relative 'app_factory/sprockets/hacks' require_relative 'app_factory/sprockets/compiler' def load_env_from_file(file) File.open(file, 'rb') do |file| contents = file.read lines = contents.gsub('export ', '').split(/\n\r?/).reject{|line| line.blank?} lines.each do |line| keyValue = line.split("=", 2) next unless keyValue.count == 2 ENV[keyValue.first] = keyValue.last.gsub("'",'').gsub('"','') end end end if (!ENV['RACK_ENV'] or ENV['RACK_ENV'] == 'development') load_env_from_file("#{FanforceApp.config.root_dir}/.powenv") if File.exists?("#{FanforceApp.config.root_dir}/.powenv") load_env_from_file("#{FanforceApp.config.root_dir}/.appenv") if File.exists?("#{FanforceApp.config.root_dir}/.appenv") end FanforceApp.config.load_redis namespace :assets do root_dir = FanforceApp.config.root_dir factory_root_dir = FanforceApp.config.factory_root_dir desc 'Precompile assets for production' task :precompile => :clean do sprockets = SprocketsCompiler.setup(root_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(root_dir, '/public/asset_manifest.json'), JSON.generate(asset_list) IO.write File.join(root_dir, '/public/asset_manifest.json'), "ASSETS=#{JSON.generate(asset_list)}" IO.write File.join(root_dir, '/public/asset_manifest.json'), asset_list.to_yaml puts 'DONE' print 'ENSURING FAVICON EXISTS... ' if !File.exists?(root_dir+'/public/favicon.ico') puts '' FileUtils.cp("#{factory_root_dir}/public/favicon.ico", "#{root_dir}/public/favicon.ico") puts "#{root_dir}/public/favicon.ico" end puts 'DONE' end desc 'Clean assets folder' task :clean do print 'DESTROYING PUBLIC/ASSETS... ' FileUtils.rm_rf File.join(root_dir, '/public/assets') puts 'DONE' end task :test do puts 'TEST WORKED!' end end