index.js 820 B

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. var through = require('through2')
  3. var PluginError = require('plugin-error')
  4. var cloneStream = function() {
  5. return through.obj(function(file, enc, cb) {
  6. cb(null, file.clone());
  7. });
  8. };
  9. var cloneSink = function() {
  10. var tapStream = through.obj();
  11. var stream = through.obj(function(file, enc, cb) {
  12. if (file.isStream()) {
  13. this.emit('error', new PluginError('gulp-clone', 'Streaming not supported'));
  14. return cb();
  15. }
  16. if (file.isNull()) {
  17. return cb(null, file); // Do nothing if no contents
  18. }
  19. tapStream.write(file.clone());
  20. cb(null, file);
  21. });
  22. stream.tap = function() {
  23. return tapStream;
  24. };
  25. return stream;
  26. };
  27. module.exports = cloneStream;
  28. module.exports.sink = cloneSink;