#StackBounty: #javascript #node.js #glob NodeJS&Glob: any number of filenames, filename extensions and files that must be excluded …

Bounty: 50

The following glob expression selects all .pug files except index.pug (filddle):

/src/!(index){.pug,.haml,index.haml}

Now assume that we has managed to stop haml support, therefore all that related with haml must be removed from above expression. The question is how to reduce above expression without radical changing of it’s structure? This condition is important for creation of simple and the same time flexible algorithm of glob expressions generation.

Wrong solution (no matches among .pug files):

/src/!(index){.pug}

Below solution is also improper, because possibly in the future we would to add new filename extension support (e. g. .slim). To implement it, we must to radically change the algorithm that generates below expression.

/src/!(index).pug

Below solution is also improper because we can not exclude arbitrary files from it. What if we want to exclude index.pug and about.slim, but not index.slim and about.pug?

/src/!(index).+(pug|slim)

By other words: all above solution are not scale-able on any count of:
* filename that must be selected
* filename extensions which files must be selected
* filename with certain extension that must be excluded.

Important: In this question, we does not consider files receiving by glob, globby, gulp.src() etc. We considering single string generation.

And also: if above problem is impossible to solve by one string, please write such as (with explanation/commentary).


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.