<commit_before>import assert from 'assert'
import IPCEE from 'ipcee'

let ipc = IPCEE(process)
let debug = require('debug')('explorer:job')
let p = require('path')

let plugins = {}
let args = [].slice.call(process.argv, 2)

for(let i in args) {
  let title = p.basename(args[i], '.js')
  debug('Require %s', title)
  plugins[title] = require(args[i])(ipc)
}

ipc.on('command', function(args, data) {

  args = args.split('.')

  let command = args.shift()
  let option = args.shift()

  assert(command, 'Must have a "command" argument')
  assert(option, 'Must have an "option" argument')

  debug('Got command %s.%s with data %o', command, option, data)

  let job = plugins[command]

  if(!job) {
    return ipc.send('error', 'Command ' + command + ' is not available')
  }

  if(option !== undefined && option in job && typeof job[option] == 'function') {
    return job[option](data)
  } 

  return ipc.send('error', 'Option ' + option + ' is not a valid option')
})

ipc.on('info', function(plugin = null) {

  if(plugin && !(plugin in plugins))
    return ipc.send('error', 'Plugin ' + plugin + ' is not available')

  let check = Object.keys(plugins)
  let data = {}

  if(plugin)
    check = [plugins]

  for(let i in check) {
    debug('Info on %s', check[i])
    data[check[i]] = plugins[check[i]].info() 
  }

  return ipc.send('info', data)
})

ipc.on('uncaughtException', function(err) {
  //Temptation would be to send the full Error object
  //but JSON.stringify(new Error('test')) will return '{}'
  ipc.send('error', err.toString(), err.stack)

  console.error(err.stack)

  process.nextTick(function() {
    process.exit(1) 
  })<commit_msg>fix(job): Arguments as data<commit_after>import assert from 'assert'
import IPCEE from 'ipcee'

let ipc = IPCEE(process)
let debug = require('debug')('explorer:job')
let p = require('path')

let plugins = {}
let args = [].slice.call(process.argv, 2)

for(let i in args) {
  let title = p.basename(args[i], '.js')
  debug('Require %s', title)
  plugins[title] = require(args[i])(ipc)
}

ipc.on('command', function(args, ...data) {

  args = args.split('.')

  let command = args.shift()
  let option = args.shift()

  assert(command, 'Must have a "command" argument')
  assert(option, 'Must have an "option" argument')

  debug('Got command %s.%s with data %o', command, option, data)

  let job = plugins[command]

  if(!job) {
    return ipc.send('error', 'Command ' + command + ' is not available')
  }

  if(option !== undefined && option in job && typeof job[option] == 'function') {
    return job[option].apply(job, data)
  } 

  return ipc.send('error', 'Option ' + option + ' is not a valid option')
})

ipc.on('info', function(plugin = null) {

  if(plugin && !(plugin in plugins))
    return ipc.send('error', 'Plugin ' + plugin + ' is not available')

  let check = Object.keys(plugins)
  let data = {}

  if(plugin)
    check = [plugins]

  for(let i in check) {
    data[check[i]] = plugins[check[i]].info() 
  }

  return ipc.send('info', data)
})

ipc.on('uncaughtException', function(err) {
  //Temptation would be to send the full Error object
  //but JSON.stringify(new Error('test')) will return '{}'
  ipc.send('error', err.toString(), err.stack)

  console.error(err.stack)

  process.nextTick(function() {
    process.exit(1) 
  })
{'fraction_non_alphanumeric': 0.1751207729468599, 'fraction_numerical': 0.0012077294685990338, 'mean_word_length': 3.8084179970972425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2918062', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1127, 'n_words': 310}