cmd.js 752 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env node
  2. var mdeps = require('../');
  3. var subarg = require('subarg');
  4. var fs = require('fs');
  5. var path = require('path');
  6. var argv = subarg(process.argv.slice(2), {
  7. alias: { h: 'help', t: 'transform', g: 'globalTransform' }
  8. });
  9. if (argv.help) return usage(0);
  10. var JSONStream = require('JSONStream');
  11. var files = argv._.map(function (file) {
  12. if (file === '-') return process.stdin;
  13. return path.resolve(file);
  14. });
  15. var md = mdeps(argv);
  16. md.pipe(JSONStream.stringify()).pipe(process.stdout);
  17. files.forEach(function (file) { md.write(file) });
  18. md.end();
  19. function usage (code) {
  20. var r = fs.createReadStream(__dirname + '/usage.txt');
  21. r.pipe(process.stdout);
  22. if (code) r.on('end', function () { process.exit(code) });
  23. }