Gulp.src 用方括号匹配文件夹

Gulp.src match folder with square brackets

我已经使用 gulp.

自动化了项目中的所有任务

但是我有一个名称中带有方括号的特定名称文件夹(是的,它的名称中必须有方括号是有意的),这似乎不适用于 gulp。 我需要定位该文件夹并缩小其中的 javascript。我尝试使用正则表达式匹配模式,但只要我读到 gulp is using blob 或者我不理解 blob 或者我做错了

假设我有一个用脚本命名的文件夹:[testFolder] > script1.js, script2.js 这就是我用代码定位它的方式。

function minifyJs() {
  return gulp.src('resources/[testFolder]/**/*.js') // not working
  return gulp.src('resources/\[.*testFolder\]/**/*.js) // not working either desipte I've tested 
       it on various things
    .pipe(minify({ noSource: true }))
    .pipe(gulp.dest('resources/[testFolder]')) // this is working pretty much fine
}

我做错了什么?

使用 \ 转义 []

function minifyJs() {
  return gulp.src('resources/\[testFolder\]/**/*.js') // not working
    .pipe(minify({ noSource: true }))
    .pipe(gulp.dest('resources/[testFolder]')) // this is working pretty much fine
}

有关详细信息,请阅读 globs/segments-and-separators and How do I match a square bracket literal using RegEx

好吧,经过几天的努力,它似乎适用于 macOS / linux 和 Windows(在 windows 10 上测试) 感谢@Saeed 在下面的回答中提供的帮助。

// MAC / LINUX OS
function minifyJs() {
return gulp.src('resources/\[testFolder\]/**/*.js') // note the \[name\] escape here
 .pipe(minify({ noSource: true }))
 .pipe(gulp.dest('resources/[testFolder]')) // this is working for both
}

// WINDOWS
function minifyJs() {
return gulp.src('resources/[[]testFolder]/**/*.js') // note [[]name] escape here
  .pipe(minify({ noSource: true }))
  .pipe(gulp.dest('resources/[testFolder]')) // this is working for both
}

这是给windows