Node.js Glob/minimatch:如何吞下.src()所有内容,然后排除文件夹,但在其中保留一个文件
我有一个这样的项目:Node.js Glob/minimatch:如何吞下.src()所有内容,然后排除文件夹,但在其中保留一个文件,node.js,gulp,glob,minimatch,Node.js,Gulp,Glob,Minimatch,我有一个这样的项目: root |-incl1 |-incl2 |- ... |-excl1 |-excl2 |- .gitignore <-- keep this one |- (other files) <-- exclude them 这似乎有效: gulp.src([ baseDir + '/**', // Include all '!' + baseDir
root
|-incl1
|-incl2
|- ...
|-excl1
|-excl2
|- .gitignore <-- keep this one
|- (other files) <-- exclude them
这似乎有效:
gulp.src([
baseDir + '/**', // Include all
'!' + baseDir + '/excl1{,/**}', // Exclude excl1 dir
'!' + baseDir + '/excl2/**/!(.gitignore)', // Exclude excl2 dir, except .gitignore
], { dot: true });
从globmatch中排除单个文件很棘手,因为minimatch文档中没有类似的示例
“如果模式以
!
字符开头,则它将被否定” 不完美。现在excl2下的所有.gitignore
都被保留了。这对我来说不是什么大问题。谢谢,我会努力的。甚至不需要花括号。无论是谁发明了globstar风格的语法,都应该下地狱。认真地
gulp.src([
baseDir + '/**', // Include all
'!' + baseDir + '/excl1{,/**}', // Exclude excl1 dir
'!' + baseDir + '/excl2/**/!(.gitignore)', // Exclude excl2 dir, except .gitignore
], { dot: true });