<commit_before>{spawn, exec}     = require 'child_process'
CoffeeScript      = require 'coffee-script'
fs                = require 'fs'
nib               = require 'nib'
path              = require 'path'
compilePistachios = require 'pistachio-compiler'
ProgressBar       = require 'progress'
SourceMap         = require 'source-map'
base64VLQ         = require 'source-map/lib/source-map/base64-vlq'
Stylus            = require 'stylus'
sprite            = require 'koding-sprites'
UglifyJS          = require 'uglify-js'
WebSocket         = require 'ws'
WebSocketServer   = WebSocket.Server
Promise           = require 'bluebird'
which             = Promise.promisify require 'which'

log =
  info  : console.log
  error : console.log
  debug : console.log
  warn  : console.log

formatByte = (bytes) ->
  minus = ''
  if bytes < 0
    minus  = '-'
    bytes *= -1
  thresh    = 1024
  units     = ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
  unitIndex = -1
  return "#{bytes} B"  if bytes < thresh
  loop
    bytes /= thresh
    ++unitIndex
    break unless bytes >= thresh

  return "#{minus}#{bytes.toFixed 2} #{units[unitIndex]}"

checkFileCase = (fileName) ->
  basename = path.basename fileName
  dirname  = path.normalize path.dirname fileName
  listing  = fs.readdirSync dirname

  if basename in listing
    if (dirname.split '/').length > 1
    then checkFileCase dirname
    else yes
  else no

module.exports = class Builder

  spriteHelper = null

  canBuildSprites: ->
    hasCanvas = !!try require 'canvas'
    (if hasCanvas then Promise.resolve() else which 'gm').catch (err) ->
      if /^not found:/.test err.message
        console.error "Unmet dependency!  You must install either graphicsmagick or cairo + node-canvas"
        console.error "You can install graphicsmagick using homebrew:"
        console.error "$ brew install graphicsmagick"
        process.exit(1)

  buildSprites: (options) ->

    @config ?= require('koding-config-manager').load("main.#{options.configFile}")

    @canBuildSprites().then ->
      sprite<commit_msg>builder: rethrow any other errors<commit_after>{spawn, exec}     = require 'child_process'
CoffeeScript      = require 'coffee-script'
fs                = require 'fs'
nib               = require 'nib'
path              = require 'path'
compilePistachios = require 'pistachio-compiler'
ProgressBar       = require 'progress'
SourceMap         = require 'source-map'
base64VLQ         = require 'source-map/lib/source-map/base64-vlq'
Stylus            = require 'stylus'
sprite            = require 'koding-sprites'
UglifyJS          = require 'uglify-js'
WebSocket         = require 'ws'
WebSocketServer   = WebSocket.Server
Promise           = require 'bluebird'
which             = Promise.promisify require 'which'

log =
  info  : console.log
  error : console.log
  debug : console.log
  warn  : console.log

formatByte = (bytes) ->
  minus = ''
  if bytes < 0
    minus  = '-'
    bytes *= -1
  thresh    = 1024
  units     = ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
  unitIndex = -1
  return "#{bytes} B"  if bytes < thresh
  loop
    bytes /= thresh
    ++unitIndex
    break unless bytes >= thresh

  return "#{minus}#{bytes.toFixed 2} #{units[unitIndex]}"

checkFileCase = (fileName) ->
  basename = path.basename fileName
  dirname  = path.normalize path.dirname fileName
  listing  = fs.readdirSync dirname

  if basename in listing
    if (dirname.split '/').length > 1
    then checkFileCase dirname
    else yes
  else no

module.exports = class Builder

  spriteHelper = null

  canBuildSprites: ->
    hasCanvas = !!try require 'canvas'
    (if hasCanvas then Promise.resolve() else which 'gm').catch (err) ->
      if /^not found:/.test err.message
        console.error "Unmet dependency!  You must install either graphicsmagick or cairo + node-canvas"
        console.error "You can install graphicsmagick using homebrew:"
        console.error "$ brew install graphicsmagick"
        process.exit(1)
      throw err

  buildSprites: (options) ->

    @config ?= require('koding-config-manager').load("main.#{options.configFile}")

    @canBuildSprites().then ->
      sprite
{'fraction_non_alphanumeric': 0.1158273381294964, 'fraction_numerical': 0.00671462829736211, 'mean_word_length': 2.6050129645635263, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '3656014', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1286, 'n_words': 357}