我有一种情况,我正在尝试使用grunt来提取代码库,排除特定文件夹.
grunt在引擎盖下使用minimatch(类似于bsdglob)来匹配文件,但我似乎无法弄清楚如何进行文件夹的.gitignore样式排除.
我想要摄取这个:
ignoreme
并匹配这些:
/folder/path/here/to/something/ok.js
/another/folder/path.js
/test.js
Run Code Online (Sandbox Code Playgroud)
但不符合这些:
/folder/ignoreme/something.js
/folder/path/here/to/ignoreme/metoo/file.js
Run Code Online (Sandbox Code Playgroud)
这将匹配所有内容,包括ignoreme:
/**/*.js
Run Code Online (Sandbox Code Playgroud)
所以我想我可以这样做:
/**/!(ignoreme)/**/*.js
Run Code Online (Sandbox Code Playgroud)
但是匹配ignoreme文件夹中的文件.
我习惯了正则表达式,但似乎无法弄清楚如何重复模式或其他东西 - 我也试过像:
/(!(ignoreme)|*)*/*.js
Run Code Online (Sandbox Code Playgroud)
希望容器会重复,但这不起作用,它只是无法匹配所有东西.
有没有办法将正则表达式传递给grunt文件路径,或者让这个为我工作?
以下是我目前正在处理此问题的方法:
var pattern = /\/ignoreme\//
var files = grunt.file.expandFiles(arrayOfFilesPassedToMinimatch).filter(function(f){
return !pattern.test(f)
})
Run Code Online (Sandbox Code Playgroud)
如果在minimatch中可以删除文件夹,我仍然会感兴趣.
我已经安装了grunt任务grunt-contrib-copy.我把它嵌入我的Gruntfile.js并通过加载任务grunt.loadNpmTasks('grunt-contrib-copy');.
目前,我使用以下配置来创建包含我的js文件/文件夹子集的文件夹.
copy: {
options: {
processContent: [],
processContentExclude: ['build/**', 'bin/**', '.*', '*.orig', '*.bak', '.*/**', '*.log', 'dist/**', 'test/**', 'dev/**', 'pyserver/**', 'node_modules/**', 'doc/**']
},
du: {
files: [
{src: ['.conf1', '.conf2', './config.js'], dest: 'output/toolkit/', filter: 'isFile'},
{src: ['./css/**/*', './img/**/*', './js/**/*', './release/**/*', './lib/**/*', './locale/**/*'], dest: 'output/toolkit/'},
{expand: true, cwd: './', src: ['**'], dest: 'output/'}
]
}
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,但每次我运行grunt副本它退出时出现以下错误消息:
Copying Gruntfile.js -> output/Gruntfile.js
Warning: Error while processing "Gruntfile.js" file. Use --force to continue.
Run Code Online (Sandbox Code Playgroud)
我想排除Gruntfile.js和所有*.less …