Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gulp main-bower-files regular expression filter not working

Why is the second array, bowerFiles, not filtered to just javascript files.

var gulp = require('gulp');
var mainBowerFiles = require('main-bower-files');

gulp.task('default', function () {

  var unfiltered = mainBowerFiles(); 
  console.log('unfiltered files:', unfiltered); // 11 FILES

  //var jsRegEx = /js$/i; // tried this way too...
  var jsRegEx = new RegExp('js$', 'i');
  var bowerFiles = mainBowerFiles(jsRegEx);
  console.log('bower files:', bowerFiles); // 11 FILES

});

I have tried to mimic what bower-main-files is doing here, and it works.

like image 972
user210757 Avatar asked Feb 26 '15 18:02

user210757


1 Answers

You don't need to create a RegExp to filter for files with main-bower-files.

Indeed, you can simply pass an array or a string of glob to check only for .js files:

gulp.task('default', function () {
  var bowerFiles = mainBowerFiles('**/*.js');
  console.log('bower files: ', bowerFiles);
});

If you really want to use the regex, you have to use the filter option, you can't directly pass it as an argument:

gulp.task('default', function () {
  var bowerFiles = mainBowerFiles({ filter: new RegExp('.*js$', 'i') });
  console.log('bower files: ', bowerFiles);
});
like image 90
Preview Avatar answered Oct 01 '22 23:10

Preview