const readline = require('readline')
const validateEvent = require('../lib/validateEvent')
const RED = '\033[0;31m'
const NC = '\033[0m'

const lines = readline.createInterface({ input: process.stdin })
let error = false
lines.on('line', line => {
  if(error) return
  let event
  try {
    event = JSON.parse(line)
    validateEvent(event)
    console.log(line)
  } catch(err) {
    if(event) {
      console.error(RED + '--- Failed to validate event ---' + NC)
      console.error(RED + JSON.stringify(event, null, 2) + NC)
      console.error(RED + '--- Validation error ---' + NC)
    }
    console.error(RED + err.message + NC)

    error = true
    lines.close()
  }
})
lines.on('close', () => process.exit(error ? 1 : 0))
#!/usr/bin/env node

const readline = require('readline')
const validateEvent = require('../lib/validateEvent')
const RED = '\033[0;31m'
const NC = '\033[0m'

const lines = readline.createInterface({ input: process.stdin })
let error = false
lines.on('line', line => {
  if(error) return
  let event
  try {
    event = JSON.parse(line)
    validateEvent(event)
    console.log(line)
  } catch(err) {
    if(event) {
      console.error(RED + '--- Failed to validate event ---' + NC)
      console.error(RED + JSON.stringify(event, null, 2) + NC)
      console.error(RED + '--- Validation error ---' + NC)
    }
    console.error(RED + err.message + NC)

    error = true
    lines.close()
  }
})
lines.on('close', () => process.exit(error ? 1 : 0))

Make binary command executable and add hashbang
event-protocol: Make binary command executable and add hashbang

I might have missed something, but I couldn't work out to run it (from
another directory) anymore since it moved into the bin directory in
3dbafa2e4a327a4251038a97063b7de5e0da3f88
