lib/tasks/bower.rake in bower-rails-0.2.1 vs lib/tasks/bower.rake in bower-rails-0.3.1

- old
+ new

@@ -1,8 +1,7 @@ require 'json' require 'pp' - namespace :bower do desc "install files from bower" task :install do #install to corresponding directories @@ -16,12 +15,46 @@ #install to corresponding directories perform_command false do sh 'bower update' end end + + namespace :dsl do + desc "install files from bower" + task :install do + #install to corresponding directories + dsl_perform_command do + sh 'bower install' + end + end + + desc "update bower packages" + task :update do + #install to corresponding directories + dsl_perform_command false do + sh 'bower update' + end + end + end end +def dsl_perform_command remove_components = true + BowerRails::Dsl.config = {:root_path => Rails.root} + dsl = BowerRails::Dsl.evalute(Rails.root.join("Jsfile")) + + if remove_components + dsl.write_bower_json + puts "bower.js files generated" + end + + dsl.directories.each do |dir| + Dir.chdir(dir) do + yield + 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) @@ -29,27 +62,27 @@ ["lib", "vendor"].each do |dir| data = json[dir] #check folder existence and create? - dir = "#{Rails.root}/#{dir}/assets/javascripts" + dir = "#{Rails.root}/#{dir}/assets" FileUtils.mkdir_p dir unless File.directory? dir #go in to dir to act Dir.chdir(dir) do #remove old components FileUtils.rm_rf("components") if remove_components - #create component json - File.open("component.json","w") do |f| + #create bower json + File.open("bower.json","w") do |f| f.write(data.to_json) end #run command yield - #remove component file - FileUtils.rm("component.json") + #remove bower file + FileUtils.rm("bower.json") end if data end end