<commit_before>// https://github.com/DTrejo/run.js
// Used to run code in a directory and rerun it if any files are changed.
// Usage: ./cli.js servercode.js
// Where servercode.js is whatever js file you want node to run

// Excludes filetypes in the ignoreExtensions array
var util = require('util')
  , fs = require('fs')
  , path = require('path')
  , spawn = require('child_process').spawn
  , minimatch = require('minimatch')
  , child // child process which runs the user's code
  , ignoreExtensions = ['.dirtydb', '.db', '.styl', '.css']
  , ignoreFiles = [ 'node_modules' ]
  // switched out for coffee depending on extension.
  , node = 'node'
  , args = process.argv
  , signal = null

//
// Tell user the correct usage if they miss-type
//
if (args.length <= 2) {
  console.log('Found ' + (args.length - 2)
    , 'argument(s). Expected one or more.')
  console.log(
    'Usage: \n  runjs [SIGNAL] somecode.js [--args]\n'
    + 'Ex:  \n  runjs somecode.js --args'
    + '     \n  runjs SIGUSR2 somecode.js --args\n'
    )
  process.exit(1)
}

//
// If we define a signal, parse it out and then remove from the array
//
if (args[2].match(/^SIG/)) {
  signal = args.splice(2, 1)[0];
}

//
// use `coffee` if the file ends with .coffee
//
if (args[2].match(/\.coffee$/)) node = 'coffee'


//
// Exclude files based on .gitignore
//
if (fs.existsSync('.gitignore')) {
  ignoreFiles = ignoreFiles.concat(fs.readFileSync('.gitignore', 'utf8')
    .split('\n')
    .filter(function(s) {
      s = s.trim()
      return s.indexOf('#') !== 0 && s.length > 0
    })
  )
}

console.log('Watching', path.resolve('./'), 'and all sub-directories not'
  , 'excluded by your .gitignore. Will not monitor dotfiles.')

watchFiles(parseFolder('.'), restart) // watch all files, restart if problem
run()


process.stdin.setEncoding('utf8')

// executes the command given by the second argument
;function run() {
  // run the server
  var childArgs = args.slice(2) || []
  child = spawn(node, childArgs)

  // let the child's output escape.
  child.stdout.on('data', function(data) {
    util.print(data)
  })
  child.stderr.on('data', function(error) {
    util.print(error)
  })

  // let the user's typing get to the child
  process.stdin.pipe(child.stdin)

  console.log('\nStarting: ' + childArgs.join(' '))
}

;function restart() {
  // kill if running
  if (child) {
    if (signal) {
      child.kill(signal)
    } else {<commit_msg>Fixes "util.print: Use console.log instead" error<commit_after>// https://github.com/DTrejo/run.js
// Used to run code in a directory and rerun it if any files are changed.
// Usage: ./cli.js servercode.js
// Where servercode.js is whatever js file you want node to run

// Excludes filetypes in the ignoreExtensions array
var util = require('util')
  , fs = require('fs')
  , path = require('path')
  , spawn = require('child_process').spawn
  , minimatch = require('minimatch')
  , child // child process which runs the user's code
  , ignoreExtensions = ['.dirtydb', '.db', '.styl', '.css']
  , ignoreFiles = [ 'node_modules' ]
  // switched out for coffee depending on extension.
  , node = 'node'
  , args = process.argv
  , signal = null

//
// Tell user the correct usage if they miss-type
//
if (args.length <= 2) {
  console.log('Found ' + (args.length - 2)
    , 'argument(s). Expected one or more.')
  console.log(
    'Usage: \n  runjs [SIGNAL] somecode.js [--args]\n'
    + 'Ex:  \n  runjs somecode.js --args'
    + '     \n  runjs SIGUSR2 somecode.js --args\n'
    )
  process.exit(1)
}

//
// If we define a signal, parse it out and then remove from the array
//
if (args[2].match(/^SIG/)) {
  signal = args.splice(2, 1)[0];
}

//
// use `coffee` if the file ends with .coffee
//
if (args[2].match(/\.coffee$/)) node = 'coffee'


//
// Exclude files based on .gitignore
//
if (fs.existsSync('.gitignore')) {
  ignoreFiles = ignoreFiles.concat(fs.readFileSync('.gitignore', 'utf8')
    .split('\n')
    .filter(function(s) {
      s = s.trim()
      return s.indexOf('#') !== 0 && s.length > 0
    })
  )
}

console.log('Watching', path.resolve('./'), 'and all sub-directories not'
  , 'excluded by your .gitignore. Will not monitor dotfiles.')

watchFiles(parseFolder('.'), restart) // watch all files, restart if problem
run()


process.stdin.setEncoding('utf8')

// executes the command given by the second argument
;function run() {
  // run the server
  var childArgs = args.slice(2) || []
  child = spawn(node, childArgs)

  // let the child's output escape.
  child.stdout.on('data', function(data) {
    process.stdout.write(data)
  })
  child.stderr.on('data', function(error) {
    process.stdout.write(error)
  })

  // let the user's typing get to the child
  process.stdin.pipe(child.stdin)

  console.log('\nStarting: ' + childArgs.join(' '))
}

;function restart() {
  // kill if running
  if (child) {
    if (signal) {
      child.kill(signal)
    } else {
{'fraction_non_alphanumeric': 0.16693777958519723, 'fraction_numerical': 0.0056933712891419274, 'mean_word_length': 2.94150641025641, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '4270723', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1665, 'n_words': 483}