title: Using a function conditionally with gulp-if
body: <p>I'm trying to conditionally change the paths to JS files when in production. I'm using <code>gulp-inject-string</code> along with <code>gulp-if</code> to call a function that inserts my remote path + the parent folder name of a series of html files:</p>
  
  <pre><code>```
  ...(require a bunch of stuff here)...
  var inject = require('gulp-inject-string');
  
  function getFolders(dir) {
      return fs.readdirSync(dir)
          .filter(function(file) {
              return fs.statSync(path.join(dir, file)).isDirectory();
          });
  }
  
  function injectAfterEach(src) {
      var folders = getFolders(config.root.dest);
  
      var tasks = folders.map(function(folder) {
          if (folder !== 'base') {
              var fullPath = path.join(config.remotePath, folder, '/');
              console.log('folder: ' + fullPath);
              return gulp.src(src)
                  .pipe(inject.afterEach('&lt;script src="', fullPath))
                  .pipe(gulp.dest(config.tasks.html.dest))
          }
      });
      return tasks;
  }
  
  gulp.task('html', function() {
  
      return gulp.src(config.tasks.html.src)
          .pipe(gulpif(process.env.NODE_ENV == 'production', injectAfterEach(config.tasks.html.src) ))
          .pipe(gulpif(process.env.NODE_ENV == 'production', removeCode({ production: true })))
          .pipe(gulpif(process.env.NODE_ENV == 'production', htmlmin(config.tasks.html.htmlmin)))
          .pipe(gulp.dest(config.tasks.html.dest))
          .pipe(browserSync.stream());
  });
  ```
  </code></pre>
  
  <p>I keep getting a "dest.on is not a function" error, which I guess is because my <code>injectAfterEach</code> isn't returning a stream.Transform object? Can someone clarify the best way to run that function conditionally? My gulp is a little shaky, but I tried to reference the <a href="https://gulpjs.org/recipes/running-task-steps-per-folder" rel="nofollow noreferrer">api docs</a> for this particular use case. </p>