title: Gulp control output based on data from an earlier pipe
body: <p>I have been trying to find a way with gulp to only write out certain files based on yaml data I am collecting in the pipe.   I have been able to see the file's data, but not able to get the output I expect.</p>
  
  <p>In this task, I am collecting a glob of markdown files, and passing them into a pipe that reads the yaml using gulp-data, and then adds some other data to it.  I then pipe it through Swig.</p>
  
  <p>I'm trying to add some sort of conditional element before I pipe into gulp.dest.  I found this <a href="https://stackoverflow.com/questions/29788001/passing-gulp-front-matter-value-to-gulp-wrap">example</a> which got me to where I am currently.</p>
  
  <p>The closest I've gotten is below:</p>
  
  <pre><code>  .pipe(tap(function(file) {
      if (new Date(file.data.date) &gt;= new Date(buildRange)) {
        console.log(file.path);
        gulp.src(file.path)
          .pipe(gulp.dest(config.paths.dest + '/underreview/'));
      }
    }))
  </code></pre>
  
  <p>What I've gotten from the console.log command is correct (it shows 2 of 50 files).   But nothing gets written to the destination.  If I move the gulp.dest outside of this pipe, all files get written.</p>
  
  <p>I've tried using gulp-if or gulp-ignore, but have been unable to get the file.data.date into either of those modules.</p>
  
  <hr>
  
  <p>Edited:   Here's the complete task</p>
  
  <pre><code>module.exports = function(gulp, config, env) {
  
  
  var gulpSwig = require('gulp-swig'),
      swig = require('swig'),
      data = require('gulp-data'),
      matter = require('gray-matter'),
      runSequence = require('run-sequence'),
      // BrowserSync
      reload = config.browserSync.reload,
      _ = require('lodash'),
      Path = require('path'),
      requireDir = require('require-dir'),
      marked = require('marked'),
      readingTime = require('reading-time'),
      postsData = [],
      postsTags = [],
      pdate = null,
      buildRange = new Date(new Date().setDate(new Date().getDate()-14));
      sitebuilddate = null,
      through = require('through2'),
      gutil = require('gulp-util'),
      rename = require('gulp-rename'),
      File = require('vinyl'),
      $if = require('gulp-if'),
      ignore = require('gulp-ignore'),
      tap = require('gulp-tap');
  
    var opts = {
      defaults: {
        cache: false
      },
      setup: function(Swig) {
        Swig.setDefaults({
          loader: Swig.loaders.fs(config.paths.source + '/templates')});
      }
    };
  
    // Full of the compiled HTML file
    function targetPathFull(path, data) {
      return Path.join(Path.dirname(path), targetPath(data));
    }
  
  gulp.task('templates2:under', function() {
      return gulp.src(config.paths.source + '/content/**/*.md')
        .pipe(data(function(file) {
          postData = [];
          var matterObject = matter(String(file.contents)), // extract front matter data
            type = matterObject.data.type, // page type
            body = matterObject.content,
            postData = matterObject.data,
            moreData = requireDir(config.paths.data),
            data = {},
            bodySwig;
  
          bodySwig = swig.compile(body, opts);
          // Use swig to render partials first
          body = bodySwig(data);
          // Process markdown
          if (Path.extname(file.path) === '.md') {
            body = marked(body);
          }
          // Inherit the correct template based on type
          if (type) {
            var compiled = _.template(
              "{% extends 'pages/${type}.html' %}{% block body %}${body}{% endblock %}"
              // Always use longform until a different template for different types is needed
              //"{% extends 'pages/longform.html' %}{% block body %}${body}{% endblock %}"
            );
            body = compiled({
              "type": type,
              "body": body
            });
          }
  
          file.path = targetPathFull(file.path, postData);
          moreData.path = targetPath(postData);
          _.merge(data, postData, moreData);
  
          data.url = data.site.domain + "/" + data.slug;
          // Copy the processed body text back into the file object so Gulp can keep piping
          file.contents = new Buffer(body);
  
          return data;
        }))
        .pipe(gulpSwig(opts))
        .pipe(tap(function(file) {
          if (new Date(file.data.date) &gt;= new Date(buildRange)) {
            console.log(file.path);
            gulp.src(file.path)
              .pipe(gulp.dest(config.paths.dest + '/underreview/'));
          }
        }))
        .pipe(gulp.dest(config.paths.dest + '/underreview/'));  
    });
  }
  </code></pre>