2016-09-19 44 views
0

我正在为Node应用程序创建构建脚本。gulp src glob:多个文件模式不匹配

我创建了一个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 
    } 

到目前为止,我已经写了这对咕嘟咕嘟:

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水珠工作正常,但其余的做没有找到任何东西...

我在想什么或做错了什么?

谢谢

回答

0

我已经被fs-extrawalk电话取代了水珠,但它并没有真正回答为什么水珠不起作用。

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(); 
    }); 
});