<commit_before>require 'json'
require 'pp'

namespace :bower do
  
  desc "install files from bower"
  task :install do    
    #install to corresponding directories
    perform_command { %x[bower install] }     
  end

  desc "update bower packages"
  task :update do    
    #install to corresponding directories
    perform_command { %x[bower update] }     
  end
end

#run the passed bower block in appropriate folders
def perform_command 
  #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")
      
      #create component json
      File.open("component.json","w") do |f|
        f.write(data.to_json)
      end

      #install
      if block_given
        yield
      end

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

    end if data

  end
end<commit_msg>optionally remove components<commit_after>require 'json'
require 'pp'

namespace :bower do
  
  desc "install files from bower"
  task :install do    
    #install to corresponding directories
    perform_command { %x[bower install] }     
  end

  desc "update bower packages"
  task :update do    
    #install to corresponding directories
    perform_command false { %x[bower update] }     
  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

      #install
      if block_given
        yield
      end

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

    end if data

  end
end
{'fraction_non_alphanumeric': 0.09587772116720704, 'fraction_numerical': 0.0, 'mean_word_length': 2.558484349258649, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7017425', 'n_tokens_mistral': 680, 'n_tokens_neox': 655, 'n_words': 202}