Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone explain what this means **/*.js when trying to fetch the src files in my js directory?

I'm trying to learn how to put a GulpJS file together and seeing the following source reference in some places */.js but unsure as to what exactly it means. Could someone explain what this is?

If my file structure is something like below, how would I access * each js file in each of the js libs and each js file in js src? * how can i access each image?

css/
    libs/
        lib1.scss
        lib2.scss
    src/
        partials/
            partial1.scss
            partial2.scss
            partial3.scss
js/
    libs/
        lib1/
            lib11.js
        lib2/
            lib21.js
        lib3/
            lib31.js
    src/
        src1.js
        src2.js
        src3.js

img/
    imgs1/
        img11.jpg
        img12.jpg
        img13.png
    imgs2/
        img21.gif
        img22.png
        img23.jpg
like image 784
styler Avatar asked Feb 17 '14 16:02

styler


2 Answers

It's helpful to have a basic understanding of pattern matching and the module that gulp is using to resolve those glob matches, ie https://github.com/isaacs/minimatch

Globstar **

The ** symbol you're asking about is known as the "globstar". In most unix pattern matching, the * can only represent one directory level:

"a/*/*.js"

a/b/app.js => MATCH
a/b/c/app.js => NO MATCH
a/app.js => NO MATCH

The globstar allows you to specifiy an unknown number of in-between directories, like so:

"a/**/*.js"

a/b/app.js => MATCH
a/b/c/app.js => MATCH
a/app.js => MATCH
a/b/c/d/e/f/g/h/i/j/app.js => MATCH
other/app.js => NO MATCH

Negation

You can negate them with a prepended !:

["a/**/*.js", "!a/vendor/**/*.js"]

a/b/c/app.js => MATCH
a/vendor/b/backbone.js => NO MATCH

Useful for excluding vendor files from linting, etc.

Multiple globs combined

You can also combine multiple globs in one array to include multiple patterns as one search.

["js/**/*.js", "img/**/*.png"]

js/a/b/app.js => MATCH
img/cat.png => MATCH

The glob you requested would be something like this:

["js/**/*.js", "img/**/*"]
like image 139
rhodesjason Avatar answered Nov 12 '22 13:11

rhodesjason


"**/*.js" means "all .js files in all directories under the current one, recursively".

Traditional "*/*.js" means "all .js files in all directories under the current one".

like image 26
MarcoS Avatar answered Nov 12 '22 13:11

MarcoS