tap.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Generated by CoffeeScript 1.12.5
  2. 'use strict';
  3. var DEBUG, baseStream, through;
  4. baseStream = require('stream');
  5. through = require('through2');
  6. DEBUG = process.env.NODE_ENV === 'development';
  7. /*
  8. * Taps into the pipeline and allows user to easily route data through
  9. * another stream or change content.
  10. */
  11. module.exports = function(lambda) {
  12. var modifyFile, utils;
  13. utils = function(tapStream, file) {
  14. return {
  15. /*
  16. * Routes through another stream. The filter must not be
  17. * created. This will create the filter as needed.
  18. *
  19. * @param filter {stream}
  20. * @param args {Array} Array containg arguments to apply to filter.
  21. *
  22. * @example
  23. * t.through coffee, [{bare: true}]
  24. */
  25. through: function(filter, args) {
  26. var stream;
  27. if (DEBUG) {
  28. if (!Array.isArray(args)) {
  29. throw new TypeError("Args must be an array to `apply` to the filter");
  30. }
  31. }
  32. stream = filter.apply(null, args);
  33. stream.on("error", function(err) {
  34. return tapStream.emit("error", err);
  35. });
  36. stream.write(file);
  37. return stream;
  38. }
  39. };
  40. };
  41. modifyFile = function(file, enc, cb) {
  42. var data, inst, next, obj;
  43. inst = {
  44. file: file
  45. };
  46. obj = lambda(inst.file, utils(this, inst.file), inst);
  47. next = (function(_this) {
  48. return function() {
  49. _this.push(file);
  50. return cb();
  51. };
  52. })(this);
  53. if (obj instanceof baseStream && !obj._readableState.ended) {
  54. obj.on('end', next);
  55. return obj.on('data', data = function() {
  56. obj.removeListener('end', next);
  57. obj.removeListener('data', data);
  58. return next();
  59. });
  60. } else {
  61. return next();
  62. }
  63. };
  64. return through.obj(modifyFile, function(cb) {
  65. return cb();
  66. });
  67. };
  68. //# sourceMappingURL=tap.js.map