<commit_before>fs = require 'fs'
{exec} = require 'child_process'
require './string_extensions'
require '../src/string_extensions'
require '../src/array_extensions'

class BuildUtils
  slider_file: 'jquery.rambling.slider.coffee'

  log: (string) ->
    console.log string.as_console_message()

  error_handler: (err, stdout, stderr) ->
    console.log stdout if stdout
    console.log stderr if stderr
    throw err if err

  process: (content, callback) ->
    self = @
    fs.writeFile "lib/#{self.slider_file}", content.join("\n\n"), 'utf8', (err) ->
      self.error_handler err
      self.log "Building `src/#{self.slider_file}`"
      exec "coffee -c lib/#{self.slider_file}", (err, stdout, stderr) ->
        self.error_handler err, stdout, stderr
        fs.unlink "lib/#{self.slider_file}", (err) ->
          self.error_handler err
          self.log "Done. Output in `lib/#{self.slider_file.replace(/coffee/, 'js')}`"
          callback()

  compile: (callback) ->
    self = @
    @combine_source_files (content) ->
      self.process content, callback

  file_sorter: (first, second) ->
    return -1 if first is 'comments.coffee'
    return 1 if second is 'comments.coffee'
    return -1 if second is 'rambling.slider.transitions.coffee'
    return 1 if first is 'rambling.slider.transitions.coffee'
    return -1 if second is 'rambling.slider.coffee'
    return 1 if first is 'rambling.slider.coffee'
    return -1 if first < second
    return 1 if first > second
    0

  combine_source_files: (callback) ->
    self = @
    fs.readdir './src', (err, files) ->
      self.error_handler err
      content = []
      contentAdded = 0

      files = files.where (file) -> not file.startsWith '.'
      files = files.sort self.file_sorter

      self.log "Combining following files into `src/#{self.slider_file}`:\n  #{files.join('\n  ')}"
      for file, index in files then do (file, index) ->
        fs.readFile "./src/#{file}", 'utf8', (err, fileContent) ->
          self.error_handler err
          content[content.length] = fileContent
          contentAdded++

          if contentAdded is files.length
            callback content

global.BuildUtils = BuildUtils<commit_msg>Fixed the build files combining order.<commit_after>fs = require 'fs'
{exec} = require 'child_process'
require './string_extensions'
require '../src/string_extensions'
require '../src/array_extensions'

class BuildUtils
  slider_file: 'jquery.rambling.slider.coffee'

  log: (string) ->
    console.log string.as_console_message()

  error_handler: (err, stdout, stderr) ->
    console.log stdout if stdout
    console.log stderr if stderr
    throw err if err

  process: (content, callback) ->
    self = @
    fs.writeFile "lib/#{self.slider_file}", content.join("\n\n"), 'utf8', (err) ->
      self.error_handler err
      self.log "Building `src/#{self.slider_file}`"
      exec "coffee -c lib/#{self.slider_file}", (err, stdout, stderr) ->
        self.error_handler err, stdout, stderr
        fs.unlink "lib/#{self.slider_file}", (err) ->
          self.error_handler err
          self.log "Done. Output in `lib/#{self.slider_file.replace(/coffee/, 'js')}`"
          callback()

  compile: (callback) ->
    self = @
    @combine_source_files (content) ->
      self.process content, callback

  file_sorter: (first, second) ->
    return -1 if first is 'comments.coffee'
    return 1 if second is 'comments.coffee'
    return -1 if second is 'rambling.slider.transitions.coffee'
    return 1 if first is 'rambling.slider.transitions.coffee'
    return -1 if second is 'rambling.slider.coffee'
    return 1 if first is 'rambling.slider.coffee'
    return -1 if first < second
    return 1 if first > second
    0

  combine_source_files: (callback) ->
    self = @
    fs.readdir './src', (err, files) ->
      self.error_handler err
      content = []
      contentAdded = 0

      files = files.where (file) -> not file.startsWith '.'
      files = files.sort self.file_sorter

      self.log "Combining following files into `src/#{self.slider_file}`:\n  #{files.join('\n  ')}"
      for file, index in files then do (file, index) ->
        fs.readFile "./src/#{file}", 'utf8', (err, fileContent) ->
          self.error_handler err
          content[index] = fileContent
          contentAdded++

          callback(content) if contentAdded is files.length

global.BuildUtils = BuildUtils
{'fraction_non_alphanumeric': 0.13139349852239146, 'fraction_numerical': 0.00545578540577404, 'mean_word_length': 2.7639007698887936, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '887863', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1373, 'n_words': 373}