1

I have a gulp.src on a task but I want to match all the files that contain a certain word as a prefix e.g.:

gulp.src('./mydir/project.build-blessed1.css')

But there can be N files with different numbers, blessed1, blessed2, blessed3

How can I make it match any file that starts with that and has the .css extension on the same line, without using a function?

DJ22T
  • 1,628
  • 3
  • 34
  • 66
  • You need a glob pattern *Glob* which can wildcard match your patterns (search for glob or gulp-glob – Denis Tsoi Mar 27 '17 at 13:50
  • 1
    Are we only matching files that match the pattern `./mydir/project.build-blessed#.css`? – Feathercrown Mar 27 '17 at 13:50
  • Try lastIndexOf, https://www.w3schools.com/jsref/jsref_lastindexof.asp – SPlatten Mar 27 '17 at 13:51
  • you can get the files in a specific folder (where you put your css files) using this: `fs.readdir('./', function(err, files) { files.forEach(function(file) { /* DO SOMETHING HERE */ } }` and inside that structure you can check each file name with a simple regex or `includes()` or `endswith()` statement – Dries Mar 27 '17 at 13:53
  • Use Glob syntax https://github.com/isaacs/node-glob './mydir/project.build-blessed[1-3].css' – Oleksandr Maliuta Mar 27 '17 at 13:55

2 Answers2

1

if you're not using an old implemetation of gulp you can use '*' as wild card even in the middle of a path so something like:

gulp.src('./mydir/project.build-blessed*.css')

should work

You can see the doc here https://github.com/gulpjs/gulp/blob/master/docs/API.md

rick
  • 1,869
  • 13
  • 22
  • 1
    That's right Sir, this was my first approach and it wasn't working until I've updated the gulp version. Thanks! – DJ22T Mar 27 '17 at 14:00
0

As Splatten suggested, you could use string.lastIndexOf method. In your case:

var string = 'i want to do something!'

if (string.lastIndexOf('something') !== -1) {
    //keyword was found, meaning it's in the string
} else {
    //keyword was not found 
}

lastIndexOf returns the index where he found the keyword.

alex
  • 479,566
  • 201
  • 878
  • 984
DrunkDevKek
  • 469
  • 4
  • 17