1

I want to exclude files that have either ".fixtures.js", ".mocks.js", or ".tests.js" with gulp. For example I have:

client/js/app.js  
client/js/modules/services/myservice.js
client/js/modules/services/tests/myservice.tests.js
client/js/modules/directives/mydirective.js
client/js/modules/services/tests/mydirective.tests.js
client/js/modules/tests/global.mocks.js
client/js/modules/tests/global.fixtures.js

How can I exclude these all without manually doing:

gulp.src([
   'client/js/**/*.js',
   '!client/js/**/*.tests.js',
   '!client/js/**/*.fixtures.js',
   '!client/js/**/*.mocks.js',
])
.pipe(doSomething())
cusejuice
  • 10,285
  • 26
  • 90
  • 145
  • Could you please explain what's wrong with your solution? Since I use the same pattern for excluding files. – Shilly Sep 28 '17 at 13:16
  • Is there something i can do like "!client/js/*.(tests||mocks||fixtures).js – cusejuice Sep 28 '17 at 13:17
  • Have you tried '!client/js/**/*.(tests|mocks|fixtures).js' as seen in the glob docs? https://github.com/isaacs/node-glob – Shilly Sep 28 '17 at 13:21
  • When I do '!client/js/**/*.tests.js' it works, but if I do "!client/js/**/*.(tests|mocks|fixtures).js" it doesnt work. It keeps including those files – cusejuice Sep 28 '17 at 13:29
  • Maybe it has to be `"!client/js/**/(*.tests.js|*.mocks.js|*.fixtures.js)"` so you don't nest the globs. If we have to unnest the client/js/** as well, you're basically back to the original. – Shilly Sep 28 '17 at 13:48
  • I seem to recall 'client/js/**/*.!(tests|mocks|fixtures).js' or you may need curly braces 'client/js/*.!{test|mocks|fixtures}.js' but I can't find any examples just now. – Mark Sep 28 '17 at 16:59
  • Essentially a duplicate of https://stackoverflow.com/questions/23557305/glob-matching-exclude-all-js-files. gulp.src([ 'client/js/**/!(*.tests|*.fixtures|*.mocks)*.js' ]) look like what you want. Let me know if that fixes it. – Mark Sep 28 '17 at 21:02

1 Answers1

3

Essentially a duplicate of exclude a set of files.

gulp.src([ 'client/js/**/!(*.tests|*.fixtures|*.mocks)*.js' ])

look like what you want.

Mark
  • 143,421
  • 24
  • 428
  • 436