cli.js 514 B

1234567891011121314151617181920212223
  1. #!/usr/bin/env node
  2. var fs = require('fs')
  3. var ndjson = require('./index.js')
  4. var minimist = require('minimist')
  5. var args = minimist(process.argv.slice(2))
  6. var inputStream
  7. var first = args._[0]
  8. if (!first) {
  9. console.error('Usage: ndjson [input] <options>')
  10. process.exit(1)
  11. }
  12. if (first === '-') inputStream = process.stdin
  13. else inputStream = fs.createReadStream(first)
  14. var parse = ndjson.parse(args)
  15. var serializer = ndjson.serialize(args)
  16. inputStream.pipe(parse).pipe(serializer).pipe(process.stdout)