<commit_before># --------------------------------------------------------
# Build the JavaScript environment using Google Closure tools.
#
# Commands:
#   $ thor list
#
# --------------------------------------------------------

class Js < Thor
  JS_PATH = "public/javascripts"
  CORE_PATH = "#{JS_PATH}/open.core"
  CLOSURE_PATH = "#{JS_PATH}/closure-library/closure/bin"
  CLOSURE_TMPL_PATH = "#{JS_PATH}/closure-templates/"

  desc "build", "Calls all tasks to build the project in it's entirety"

  def build
    project = "core_dev"
    puts ""
    write_build_title "START", project
    success = true

    success = false if !templates
    success = false if !deps
    success = false if !lint
    success = false if !single

    write_build_title("FAILED", project) if !success
    write_build_title("SUCCESS", project) if success
    puts ""
    success
  end

  desc 'deps', "Calculate dependencies within all JavaScript files to generate deps.js"

  def deps
    puts "+ Calculating dependencies now..."
    success = true

    success = false if !calc_deps "open.core"

    puts ""
    success
  end

  desc "lint", "Runs the Google JS linter against all JavaScript files in the project"

  def lint
    puts "+ Running JS Linter now..."
    puts "--"
    lint_on "#{CORE_PATH}/core"
  end

  desc "single", "Copies all dependencies into a single JavaScript file"

  def single
    puts "+ Generating single application script now..."
    file = "#{JS_PATH}/application-single.js"
    success = system("
                     #{CLOSURE_PATH}/calcdeps.py \
                        -i #{JS_PATH}/application.js \
                        -p #{JS_PATH}/closure-library/ \
                        -p #{JS_PATH}/open.core/ \
                        -o script > #{file}
                     ")
    puts "+ Generated single application script file at: #{file}" if success
    puts "- FAILED to generate single application script file at: #{file}" if !success
    puts ""
    success
  end

  desc "templates", "Builds soy templates"

  def templates
    puts "+ Compiling soy templates"

    success = true
    success = false if ! compile_templates JS_PATH

    puts "+ Compiled soy templates" if success
    puts "- FAILED to compile soy templates" if !success
    puts ""
    success
  end

  private

  def walk_dir(dir, &blk)
    dir.entries.each do |entry|
      if !hidden?(entry)
        # Calculate paths.
        entry_path = "#{dir.path}/#{entry}"
        is_dir = FileTest.directory?(entry_path)

        # Execute the block if it's a file.
        yield File.new(entry_path) if !is_dir && block_given?

        # RECURSION: Walk children if it's a folder.
        walk_dir(Dir.new(entry_path), &blk) if is_dir
      end
    end
  end

  def hidden?(name)
    name.match(/^./).to_s == "."
  end<commit_msg>Added optional path parameter to thor js:templates task<commit_after># --------------------------------------------------------
# Build the JavaScript environment using Google Closure tools.
#
# Commands:
#   $ thor list
#
# --------------------------------------------------------

class Js < Thor
  JS_PATH = "public/javascripts"
  CORE_PATH = "#{JS_PATH}/open.core"
  CLOSURE_PATH = "#{JS_PATH}/closure-library/closure/bin"
  CLOSURE_TMPL_PATH = "#{JS_PATH}/closure-templates/"

  desc "build", "Calls all tasks to build the project in it's entirety"

  def build
    project = "core_dev"
    puts ""
    write_build_title "START", project
    success = true

    success = false if !templates
    success = false if !deps
    success = false if !lint
    success = false if !single

    write_build_title("FAILED", project) if !success
    write_build_title("SUCCESS", project) if success
    puts ""
    success
  end

  desc 'deps', "Calculate dependencies within all JavaScript files to generate deps.js"

  def deps
    puts "+ Calculating dependencies now..."
    success = true

    success = false if !calc_deps "open.core"

    puts ""
    success
  end

  desc "lint", "Runs the Google JS linter against all JavaScript files in the project"

  def lint
    puts "+ Running JS Linter now..."
    puts "--"
    lint_on "#{CORE_PATH}/core"
  end

  desc "single", "Copies all dependencies into a single JavaScript file"

  def single
    puts "+ Generating single application script now..."
    file = "#{JS_PATH}/application-single.js"
    success = system("
                     #{CLOSURE_PATH}/calcdeps.py \
                        -i #{JS_PATH}/application.js \
                        -p #{JS_PATH}/closure-library/ \
                        -p #{JS_PATH}/open.core/ \
                        -o script > #{file}
                     ")
    puts "+ Generated single application script file at: #{file}" if success
    puts "- FAILED to generate single application script file at: #{file}" if !success
    puts ""
    success
  end

  desc "templates", "Builds soy templates"

  def templates(path = JS_PATH)
    puts "+ Compiling soy templates"

    success = compile_templates(path)

    puts "+ Compiled soy templates" if success
    puts "- FAILED to compile soy templates" if !success
    puts ""
    success
  end

  private

  def walk_dir(dir, &blk)
    dir.entries.each do |entry|
      if !hidden?(entry)
        # Calculate paths.
        entry_path = "#{dir.path}/#{entry}"
        is_dir = FileTest.directory?(entry_path)

        # Execute the block if it's a file.
        yield File.new(entry_path) if !is_dir && block_given?

        # RECURSION: Walk children if it's a folder.
        walk_dir(Dir.new(entry_path), &blk) if is_dir
      end
    end
  end

  def hidden?(name)
    name.match(/^./).to_s == "."
  end
{'fraction_non_alphanumeric': 0.14079040225829217, 'fraction_numerical': 0.0, 'mean_word_length': 2.092744135297327, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6297656', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1622, 'n_words': 524}