Gulp src glob:多个文件模式不匹配

Gulp src glob : multiple files patterns not matching

我正在为 Node 应用程序创建构建脚本。

我已经创建了一个 Powershell (PSake) 脚本,但现在我需要将它移植到 Gulp 因为我需要 运行 它在 Mac.

基本上,我将源代码复制到某个地方并清理它们(删除所有不必要的文件,如自述文件和其他东西)以创建一个将安装在客户端 PC 上的包,所以我希望文件数量尽可能小.

在一个地方,我的 Powershell 看起来像这样:

Get-ChildItem "$srcout\node_modules\" -Recurse | ? {
    $_.FullName -match "\\.bin\" `
        -or $_.Name -match "[\w]+\.md$" `
        -or $_.Name -match "licen[c|s]e" `
        -or $_.Name -match "authors" `
        -or $_.Name -match "bower.json" `
        -or $_.Name -match "gruntfile\.js" `
        -or $_.Name -match "makefile" `
        -or $_.Name -match "cakefile"
    } | % {
        Remove-Item "$($_.FullName)" -Force -Recurse
    }

到目前为止,我已经为 Gulp 写了这篇文章:

var pump = require('pump');
var through = require('through2');

    pump([
        gulp.src([
            '**/node_modules/**/.bin/',
            '**/node_modules/**/*.md',
            '**/node_modules/**/licen+(s|c)e*',
            '**/node_modules/**/author*',
            '**/node_modules/**/bower.json',
            '**/node_modules/**/gruntfile.js',
            '**/node_modules/**/makefile',
            '**/node_modules/**/cakefile'
        ], { 
            cwd: srcout,
            nocase: true
        }),
        through.obj(function(f, e, cb) {

            if (fs.statSync(f.path).isFile()) {
                fs.unlinkSync(f.path);
            } else {
                rmdir.sync(f.path);
            }

            cb(null, f);
        })
    ],
    done);

/.bin/*.md glob 工作正常,但其余的没有找到任何东西...

我错过了什么或做错了什么?

谢谢

我已经用 fs-extra walk 调用替换了 glob,但它并没有真正回答为什么 glob 不起作用。

var fs = require('fs-extra');

gulp.task('cleanupapp', [ 'build' ], function(done) {
    fs.walk(path.join(srcout, 'node_modules'))
    .on('data', function (item) {

        // normalize folder paths (win/mac)
        var f = item.path.replace('/', '\');

        if (f.match(/\.bin\/i) ||
            f.match(/\.md$/i) ||
            f.match(/licen[c|s]e/i) ||
            f.match(/author[s]?/i) ||
            f.match(/bower\.json$/i) ||
            f.match(/gruntfile\.js$/i) ||
            f.match(/makefile$/i) ||
            f.match(/cakefile$/i)) {

            if (fs.accessSync(f, fs.W_OK)) {
                fs.removeSync(f);
            }
        }
    })
    .on('end', function () {
        done();
    });
});