gulp: Only get matched (glob) and not given filename in pipe

267 views Asked by At

I have a gulp task which can take parameters, specifically the parameter "--only {filename.ext}".

The problem is, if it's e.g. --only fOObaR.jade it also matches the file called foobar.jade, which is okay.

But then it passes the fOObaR through the pipe instead of the matched (and right) foobar, resulting in an HTML file also called fOObaR.html.

Is there any way I can get the filename of the match, instead of the filename which I pass through gulp.src()?

I already tried gulp-tap with no luck.

I'm thinking of something like:

  1. Get all files from the source directory beforehand
  2. Filter those out that don't match a certain criteria
  3. Start the task
  4. Start gulp-tap
  5. Go through all files we already got beforehand
  6. If the given file matches one of those, return file from the list to get the correct filename

Trying to get this to work now. If someone has useful tips or a better way to do this, let me know! =)

Here is my task, simplified (and hopefully helpful):

var gulp = require('gulp');
var jade = require('gulp-jade');
var args = require('yargs').argv;

gulp.task('html', function () {
  var source = [];
  var sourceGlob = '*.jade';
  var only = args.only || '';

  if (only.indexOf('.jade') > -1) {
    sourceGlob = only;
  }

  source.push(paths.src.views + '/**/' + sourceGlob);

  return gulp.src(source)
    .pipe(jade({ pretty: true }))
    .pipe(gulp.dest(paths.dest.views));
});
0

There are 0 answers