<commit_before>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
  
  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 get_bower_root_path
  if defined?(Rails)
    return Rails.root  
  else
    return Dir.pwd
  end
end

def dsl_perform_command remove_components = true
  bower_root = get_bower_root_path
  BowerRails::Dsl.config = {:root_path => bower_root}
  dsl = BowerRails::Dsl.evalute(File.join(bower_root, "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
  bower_root = get_bower_root_path
  #load in bower json file
  txt  = File.read(File.join(bower_root, "bower.json"))
  json = JSON.parse(txt)

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

    data = json[dir]

    #check folder existence and create?
    dir = File.join(bower_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 bower json
      File.open("bower.json","w") do |f|<commit_msg>Use the proper variable name when joining directories<commit_after>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
  
  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 get_bower_root_path
  if defined?(Rails)
    return Rails.root  
  else
    return Dir.pwd
  end
end

def dsl_perform_command remove_components = true
  bower_root = get_bower_root_path
  BowerRails::Dsl.config = {:root_path => bower_root}
  dsl = BowerRails::Dsl.evalute(File.join(bower_root, "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
  bower_root = get_bower_root_path
  #load in bower json file
  txt  = File.read(File.join(bower_root, "bower.json"))
  json = JSON.parse(txt)

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

    data = json[dir]

    #check folder existence and create?
    dir = File.join(bower_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 bower json
      File.open("bower.json","w") do |f|
{'fraction_non_alphanumeric': 0.07261410788381743, 'fraction_numerical': 0.0, 'mean_word_length': 2.943762781186094, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7446121', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1237, 'n_words': 390}