cmd.js 616 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env node
  2. var insert = require('../');
  3. var through = require('through2');
  4. var concat = require('concat-stream');
  5. var JSONStream = require('JSONStream');
  6. var basedir = process.argv[2] || process.cwd();
  7. process.stdin
  8. .pipe(JSONStream.parse([ true ]))
  9. .pipe(through.obj(write))
  10. .pipe(JSONStream.stringify())
  11. .pipe(process.stdout)
  12. ;
  13. function write (row, enc, next) {
  14. var self = this;
  15. var s = insert(row.id, { basedir: basedir });
  16. s.pipe(concat(function (src) {
  17. row.source = src.toString('utf8');
  18. self.push(row);
  19. next();
  20. }));
  21. s.end(row.source);
  22. }