I wrote the snippet below as part of grunt-aws-s3
task.
var weekCache = 'css|js';
var yearCache = 'jpg|jpeg|png|gif|ico|eot|otf|ttf|woff|woff2';
var prodFiles = [
{expand: true, cwd: 'public', src: ['**/*.!('+weekCache+'|'+yearCache+')'], dest: '/'},
{expand: true, cwd: 'public', src: ['**/*.@('+weekCache+')'], dest: '/', stream: true, params: {CacheControl: 'max-age=604800, public'}}, // enable stream to allow large files
{expand: true, cwd: 'public', src: ['**/*.@('+yearCache+')'], dest: '/', stream: true, params: {CacheControl: 'max-age=31536000, public'}},
];
The idea is to have three different matches inside prodFiles
variable:
- Match all files except the ones matched by
yearCache
andweekCache
- Match all files with extensions carried in
weekCache
- Match all files with extensions carried in
yearCache
It works more or less, I have 63 files inside public
directory and its subdirectories. However those rules match 72 files, it is clear some files are matched twice at least.
What is wrong with my globbing?
EDIT:
Testing with node-glob-all
shown that error is in the first pattern:
$ glob-all '**/*.!(css|js)'
assets/css/style-nuvue6sithwirecbhvw3dkaobiojqvtadsnhguwi7k04xklybw5djl1smadp.min.css
assets/images/favicon.ico
assets/js/jquery.fancybox.js
assets/js/jquery.fancybox-thumbs.js
I was expecting this pattern to return everything but exclude *.js
and *.css
. Testing against the other two rules returned correct files.
$ glob-all '**/*.@(css|js)'
assets/css/style-nuvue6sithwirecbhvw3dkaobiojqvtadsnhguwi7k04xklybw5djl1smadp.min.css
assets/js/jquery.fancybox.js
assets/js/jquery.fancybox-thumbs.js
So, the question is how to correctly negate the pattern '**/*.!(css|js)'
?