gulp.js
function runCompile(file, options) {
  if (!file) {
    throw new PluginError('can-compile', 'Missing file option for can-compile');
  }

  var templatePaths = [],
      latestFile;

  options = options || {};
  
  function bufferStream (file, enc, cb) {
    // ignore empty files
    if (file.isNull()) {
      cb();
      return;
    }

    // can't do streams yet
    if (file.isStream()) {
      this.emit('error', new PluginError('can-compile',  'Streaming not supported for can-compile'));
      cb();
      return;
    }

    // set latest file if not already set,
    // or if the current file was modified more recently.
    if (!latestFile || file.stat && file.stat.mtime > latestFile.stat.mtime) {
      latestFile = file;
    }

    templatePaths.push(file.path);
    cb();
  }

  function endStream(cb) {
    var self = this;

    // no files passed in, no file goes out
    if (!latestFile || !templatePaths.length) {
      cb();
      return;
    }

    compile(templatePaths, options, function (err, result) {
      if (err) {
        self.emit('error', new PluginError('can-compile',  err));
        return cb(err);
      }

      var joinedFile;

      // if file opt was a file path
      // clone everything from the latest file
      if (typeof file === 'string') {
        joinedFile = latestFile.clone({ contents: false });
        joinedFile.path = path.join(latestFile.base, file);
      } else {
        joinedFile = new File(file);
      }

      joinedFile.contents = new Buffer(result);

      self.push(joinedFile);

      cb();
    });
  }

  return through.obj(bufferStream, endStream);
}
function runCompile(file, options) {
  if (!file) {
    throw new PluginError('can-compile', 'Missing file option for can-compile');
  }

  var templatePaths = [],
      latestFile;

  options = options || {};
  
  function bufferStream (file, enc, cb) {
    // ignore empty files
    if (file.isNull()) {
      cb();
      return;
    }

    // can't do streams yet
    if (file.isStream()) {
      this.emit('error', new PluginError('can-compile',  'Streaming not supported for can-compile'));
      cb();
      return;
    }

    // set latest file if not already set,
    // or if the current file was modified more recently.
    if (!latestFile || file.stat && file.stat.mtime > latestFile.stat.mtime) {
      latestFile = file;
    }

    templatePaths.push(file.path);
    cb();
  }

  function endStream(cb) {
    var self = this;

    // no files passed in, no file goes out
    if (!latestFile || !templatePaths.length) {
      cb();
      return;
    }

    compile(templatePaths, options, function (err, result) {
      if (err) {
        self.emit('error', new PluginError('can-compile',  err));
        return cb(err);
      }

      var joinedFile;

      // if file opt was a file path
      // clone everything from the latest file
      if (typeof file === 'string') {
        joinedFile = latestFile.clone({ contents: false });
        joinedFile.path = path.join(latestFile.base, file);
      } else {
        joinedFile = new File(file);
      }

      joinedFile.contents = new Buffer(result);

      self.push(joinedFile);

      cb();
    });
  }

  return through.obj(bufferStream, endStream);
}
function runCompile ( file , options ) { if ( ! file ) { throw new PluginError ( 'can-compile' , 'Missing file option for can-compile' ) ; } var templatePaths = [ ] , latestFile ; options = options || { } ; function bufferStream ( file , enc , cb ) { // ignore empty files if ( file . isNull ( ) ) { cb ( ) ; return ; } // can't do streams yet if ( file . isStream ( ) ) { this . emit ( 'error' , new PluginError ( 'can-compile' , 'Streaming not supported for can-compile' ) ) ; cb ( ) ; return ; } // set latest file if not already set, // or if the current file was modified more recently. if ( ! latestFile || file . stat && file . stat . mtime > latestFile . stat . mtime ) { latestFile = file ; } templatePaths . push ( file . path ) ; cb ( ) ; } function endStream ( cb ) { var self = this ; // no files passed in, no file goes out if ( ! latestFile || ! templatePaths . length ) { cb ( ) ; return ; } compile ( templatePaths , options , function ( err , result ) { if ( err ) { self . emit ( 'error' , new PluginError ( 'can-compile' , err ) ) ; return cb ( err ) ; } var joinedFile ; // if file opt was a file path // clone everything from the latest file if ( typeof file === 'string' ) { joinedFile = latestFile . clone ( { contents : false } ) ; joinedFile . path = path . join ( latestFile . base , file ) ; } else { joinedFile = new File ( file ) ; } joinedFile . contents = new Buffer ( result ) ; self . push ( joinedFile ) ; cb ( ) ; } ) ; } return through . obj ( bufferStream , endStream ) ; }
file can be a vinyl file object or a string when a string it will construct a new one
file can be a vinyl file object or a string when a string it will construct a new one