Sha256: 705020020f93ce1cad3d49431dd18efef26d6e9dbf17d6e4f7b6c40963a87be7

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'json'
require 'pp'

namespace :bower do

  desc "install files from bower"
  task :install do
    #install to corresponding directories
    perform_command do
      sh 'bower install'
    end
  end

  desc "update bower packages"
  task :update do
    #install to corresponding directories
    perform_command false do
      sh 'bower update'
    end
  end
end

#run the passed bower block in appropriate folders
def perform_command remove_components = true
  #load in bower json file
  txt  = File.read("#{Rails.root}/bower.json")
  json = JSON.parse(txt)

  ["lib", "vendor"].each do |dir|

    data = json[dir]

    #go in to dir to act
    Dir.chdir("#{Rails.root}/#{dir}/assets/javascripts") do

      #remove old components
      FileUtils.rm_rf("components") if remove_components

      #create component json
      File.open("component.json","w") do |f|
        f.write(data.to_json)
      end

      #run command
      yield

      #remove component file
      FileUtils.rm("component.json")

    end if data

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bower-rails-0.1.3 lib/tasks/bower.rake