Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

node.js - Glob / minimatch: how to gulp.src() everything, then exclude folder but keep one file in it

I have a project like this:

root
  |-incl1
  |-incl2
  |- ...
  |-excl1
  |-excl2
     |- .gitignore  <-- keep this one
     |- (other files)  <-- exclude them

I need to write gulp.src() that will include all folders except excl1 and excl2 but keep the .gitignore file.

This is my code that doesn't work:

gulp.src([
  baseDir + '/**',
  '!' + baseDir + '/{excl1, excl1/**}'
  '!' + baseDir + '/excl2/{**, !.gitignore}'  // <-- doesn't work
], {dot: true})
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This seems to work:

gulp.src([
    baseDir + '/**',                              // Include all
    '!' + baseDir + '/excl1{,/**}',               // Exclude excl1 dir
    '!' + baseDir + '/excl2/**/!(.gitignore)',    // Exclude excl2 dir, except .gitignore
], { dot: true });

Excluding single file from glob match was tricky because there's no similar examples in minimatch docs.

https://github.com/isaacs/minimatch

"If the pattern starts with a ! character, then it is negated".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...