require 'json' require 'pp' namespace :bower do desc "Install components from bower" task :install do perform do |bower| sh "#{bower} install" end end namespace :install do desc "Install components with -F option" task :force do perform do |bower| sh "#{bower} install -F" end end end desc "Update bower components" task :update do perform do |bower| sh "#{bower} update" end end desc "List bower components" task :list do perform false do |bower| sh "#{bower} list" end end namespace :update do desc "Update existing components and uninstalls extraneous components" task :prune do perform do |bower| sh "#{bower} update && #{bower} prune" end end end desc "Resolve assets paths in bower components" task :resolve do perform false do resolve_asset_paths end end end # Install bower assets before precompile # Rake::Task['assets:precompile'].enhance ['bower:install', 'bower:resolve'] def perform remove_components = true, &block entries = Dir.entries(get_bower_root_path) npm_path = File.join(get_bower_root_path, 'node_modules', '.bin') bower = find_command('bower', [npm_path]) if bower.nil? $stderr.puts < #{image_path}" "url(<%= asset_path '#{image_path}' %>)" end # Replace CSS with ERB CSS file with resolved asset paths FileUtils.rm(filename) File.write(filename + '.erb', new_contents) end end end # http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby def find_command(cmd, paths = []) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] paths += ENV['PATH'].split(File::PATH_SEPARATOR) paths.each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable? exe end end nil end