cli.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env node
  2. var read = require('fs').createReadStream
  3. var write = require('fs').createWriteStream
  4. var umd = require('../')
  5. var args = process.argv.slice(2)
  6. var help = false
  7. var commonJS = false
  8. args = args.filter(function (arg) {
  9. if (arg === '-h' || arg === '--help') {
  10. help = true
  11. return false
  12. } else if (arg === '-c' || arg === '--commonJS') {
  13. commonJS = true
  14. return false
  15. }
  16. return true
  17. })
  18. if (help || !args[0]) {
  19. console.log('Usage: umd <name> <source> <destination> [options]')
  20. console.log('')
  21. console.log('Pipe Usage: umd <name> [options] < source > destination')
  22. console.log('')
  23. console.log('Options:')
  24. console.log('')
  25. console.log(' -h --help Display usage information')
  26. console.log(' -c --commonJS Use CommonJS module format')
  27. console.log('')
  28. if (!help) process.exit(1)
  29. } else {
  30. var source = args[1] ? read(args[1]) : process.stdin
  31. var dest = args[2] ? write(args[2]) : process.stdout
  32. var prelude = umd.prelude(args[0], {commonJS: commonJS})
  33. var postlude = umd.postlude(args[0], {commonJS: commonJS})
  34. dest.write(prelude)
  35. source.on('end', function () {
  36. dest.write(postlude + '\n')
  37. }).pipe(dest, {end: false})
  38. }