EzDevInfo.com

minimatch

a glob matcher in javascript

jade-browser not finding any templates

app.use(jadeBrowser('/scripts/template.js', '/views/**.jade', { maxAge: 0}));

I can request template.js ok but I can't find a pattern that finds any templates.


Source: (StackOverflow)

Glob / minimatch: how to gulp.src() everything, then exclude folder but keep one file in it

I have a project like this:

root
  |-incl1
  |-incl2
  |- ...
  |-excl1
  |-excl2
     |- .gitignore  <-- keep this one
     |- (other files)  <-- exclude them

I need to write gulp.src() that will include all folders except excl1 and excl2 but keep the .gitignore file.

This is my code that doesn't work:

gulp.src([
  baseDir + '/**',
  '!' + baseDir + '/{excl1, excl1/**}'
  '!' + baseDir + '/excl2/{**, !.gitignore}'  // <-- doesn't work
], {dot: true})

Source: (StackOverflow)

Advertisements

How to specify file order with Grunt?

I've just started using Grunt, and I'm trying to get the concat task to concat my files in a specific order. Here's what I've got:

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        concat: {
            options: {
                separator: ';'
            },
            dist: {
                src: ['www/js/*.js','www/js/main.js','!**/*.{min,pack}.js','!<%= concat.dist.dest %>','!<%= uglify.dist %>'],
                dest: 'www/js/<%= pkg.name %>.js'
            }
        },

I was hoping that by putting www/js/main.js second, it would move the file down to the bottom of the list, but that doesn't appear to be the case.

How can I impose some order on the list of files it matches?


Source: (StackOverflow)

TFS drop, exclude obj folder using minimatch pattern

I'm setting up TFS 2015 on-prem and I'm having an issue on my last build step, Publish Build Artifacts. For some reason, the build agent appears to be archiving old binaries and I'm left with a huge filepath:

E:\TFSBuildAgent\_work\1a4e9e55\workspace\application\Development\project\WCF\WCF\obj\Debug\Package\Archive\Content\E_C\TFSBuildAgent\_work\1a4e9e55\workspace\application\Development\project\WCF\WCF\obj\Debug\Package\PackageTmp\bin

I'm copying the files using the example minimatch pattern to begin with:

**\bin

I'm only testing at the moment so this is not a permanent solution but how can I copy all binaries that are in a bin folder but not a descendant of obj?

From research I think that this should work, but it doesn't (It doesn't match anything):

**!(obj)**\bin

I'm using www.globtester.com to test. Any suggestions?

On a separate note, I'll look into the archiving issue later but if anyone has any pointers on it, feel free to comment. Thanks


Source: (StackOverflow)

What is the simplest way to prefix all strings in an array with a "!" (exclamation mark) in javascript?

I have two variables I use for when I want to either include or exclude system files (using minimatch glob syntax, where the ! stands for exclusion).

var systemFiles = ['node_modules/**/*', '.git/**/*'];
var ignoredSystemFiles = ['!node_modules/**/*', '!.git/**/*'];

But this feels a bit redundant. Is there a simple way to turn the systemFiles array into the ignoredSystemFiles array (i.e.: prefix all items in systemFiles with a !)?

I know !systemFiles does not work, but something as compact as this would be awesome, as it would allow me to eliminate the ignoredSystemFiles variable.


Source: (StackOverflow)

How to get first X files with node glob

Using node-glob, is it possible to specify a pattern that will return only the first X matching files, rather than all matches?

For example, if I wanted all JavaScript files, my pattern would be **/*.js. But what if I only wanted the first 5 JavaScript files?

I realize that there are other options, such as I could take the resulting fileset array and slice it. The underlying case here makes that difficult, so I am trying to accomplish this directly from the glob pattern.


Source: (StackOverflow)

Glob which match 'ca' but not 'c'

I'm trying to create glob which match those strings: a, b, ca but doesn't match ca

I finished with glob like this {a,b,!c} but it doesn't work. Can somebody provide an advice?


Source: (StackOverflow)

Grunt usemin task not updating nested relative paths correctly

I have a Yeoman project scaffolded with 'webapp-generator' which contains a static website with nested HTML files, resembling this structure:

-root/
  index.html
    -directory/
       file1.html
    -directory2/
       file2.html
    -js/
       (revved .js files)
    -css
       (revved .css files)

I'm using usemin and filerev tasks to update the filerevved file paths on the .html documents. It updates all file names correctly on js/css/images and it works correctly on the root index.html. However, on the nested HTML files, it doesn't replace the reference to the correct nested path.

For example.

js/scripts.js gets renamed to js/827385.scripts.js

In index.html

<scripts src="js/scripts.js"></scripts>

resolves to: <scripts src="js/827385.scripts.js"></scripts>

But in directory/file1.html (or any other nested html file)

<scripts src="../js/scripts.js"></scripts>

gets also converted to: <scripts src="js/827385.scripts.js"></scripts>

Ignoring the ../ relative path

--

Is there any way to tweak the Grunt tasks to be aware of the relative depth of the file within the directories to keep the relative indicator ../ in the renamed path?.

Below is the code snippet for the relevant Grunt tasks.

Any help is appreciated, thanks in advance for any guidance or pointing me into the right direction. P.S: I have already followed some of the possible answers in this StackOverflow question: How should I configure grunt-usemin to work with relative path to no avail.

     // Renames files for browser caching purposes
    rev: {
        dist: {
          files: {
            src: [
              '<%= config.dist %>/scripts/{,**/}*.js',
              '<%= config.dist %>/styles/{,**/}*.css',
              '<%= config.dist %>/images/{,**/}*.*',
              '<%= config.dist %>/styles/fonts/{,**/}*.*',
              '<%= config.dist %>/*.{ico,png}'
            ]
          }
        }
      },

      // Reads HTML for usemin blocks to enable smart builds that automatically
      // concat, minify and revision files. Creates configurations in memory so
      // additional tasks can operate on them
      // <%= config.dist %>
      useminPrepare: {
        options: {
          dest: 'out',
          // root: '<%= config.app %>'
        },
        html: '<%= config.app %>/index.html'
          // root: '<%= config.app %>'
      },

      // Performs rewrites based on rev and the useminPrepare configuration
      usemin: {
        options: {
          assetsDirs: [
            '<%= config.dist %>',
            '<%= config.dist %>/images',
            '<%= config.dist %>/styles'
          ]
        },
        html: ['<%= config.dist %>/**/*.html'],
        css: ['<%= config.dist %>/styles/**/*.css']
      },


Source: (StackOverflow)

Including/excluding globs for gulp.src

I'm trying to setup a glob array for my javascript concat build task in gulp. The directory structure looks as follows:

├── about
│   └── about.js
├── assets
├── contact
├── core
│   ├── navbar
│   │   ├── navbar.js
│   │   └── navbar.test.js
│   ├── routing.js
│   ├── routing.test.js
│   ├── utils.js
│   └── utils.test.js
├── generated
│   ├── footer.js
│   ├── header.js
│   └── templates.js
├── home
├── app.js
└── config.js

The order of the files is important:

  1. generated/header.js
  2. app.js
  3. any of the *.js files, except those here below
  4. generated/templates.js
  5. generated/footer.js

I've wildly tried all kinds of wildcards combination, but the globbing isn't strong with me.

var inputFiles = [
  'generated/header.js',
  'app.js',
  '!(generated)**/*.js',    // <=---- ???
  'generated/templates.js',
  'generated/footer.js',
  '!**/*.test.js'
];

So how do I include all *.js files except those from a subdirectory?

Thanks.


Source: (StackOverflow)

Is there a simple way of inverting more than one minimatch expression?

I have the following two minimatch expressions being used within Grunt tasks:

files: ['background/**/*', 'common/**/*', 'contentScript/youTubePlayer/**/*', 'foreground/**/*', 'test/**/*', '!**/main.js']

files: ['**/*', '!**/background/**', '!**/common/**', '!contentScript/youTubePlayer/**/*', '!**/foreground/**', '!**/test/**',  '**/main.js', '!**/less/**']

The second expression inversely mirrors the first expression such that all files which are included in the first expression are excluded in the second and, similarly, all files which are excluded from the first are included in the second.

I'd like to keep these two expressions in-sync. I know how to do this with plain JS... such as:

var inverseFiles = files.map(function(file){
    return file.charAt(0) === '!' ? file.slice(1) : ('!' + file) 
});

I'm wondering if there's anything simpler with Grunt, or if this would be an appropriate way to ensure these two expressions mirror each other?


Source: (StackOverflow)

Node-Minimatch/Regex: Match subdirectories within a specified subdirectory

I would like to match all subfolders within a given subfolder.

Let's say I have the following directories:

test/rock/martin
test/rock/steven
test/rock/steven/coolmusik
test/rock/steven/coolmusik/newmusic

test/pop/martin
test/pop/steven
test/pop/steven/mysubdir
test/pop/steven/anothersubdir

Now I'd like to match everything in 'rock' and 'pop', with a restriction of a given name. In this case it's 'steven'.

The following minimatch glob-rule works fine so far:

minimatch('./test', ['!*(rock|pop|steven)'], {matchBase: true}))

Translation of the rule above:

Hide everything that is not in rock and pop and steven.


But here's the problem: As one can imagine minimatch doesn't include the subdirectories in this particular case.

I want it to be like...

minimatch('./test', ['!*(rock|pop|steven|PLUS_SUBDIRS_OF_STEVEN)'], {matchBase: true}))

...but sadly it didn't work with my rule:

minimatch('./test', ['!*(rock|pop|steven/**)'], {matchBase: true}))

My question is: How can I hide all things except for rock+pop+steven+steven's subdirectories ?


A better overview of the directory-structure:

test
|-rock
|--martin
|--steven
|---coolmusik
|----newmusic
|-pop
|--martin
|--steven
|---mysubdir
|---anothersubdir

Also: If there's no way minimatch can handle this, how would a regular Regex for the rules above look like?


Source: (StackOverflow)

Get all files except minified files in gulp.src

I try to select all files EXCEPT minified files.

I have this file structure :

lib/
    angular/
        angular.js
        angular.min.js
    lodash/
        lodash.js
        lodash.min.js

I try this :

var pattern = ["./lib/**/*!(.min).*"];
gulp.src(pattern).pipe(using({}));

But this doesn't works : i get all files, even if they are minified.

(With gulp-using i get :

[gulp] Using file ./lib/angular/angular.js
[gulp] Using file ./lib/angular/angular.min.js
[gulp] Using file ./lib/lodash/lodash.js
[gulp] Using file ./lib/lodash/lodash.min.js

)

Any idea ?

Thanks you in advance for your help


Source: (StackOverflow)

Glob / minimatch: How to get sub folders?

I would like to copy the complete folder structure (without first level files) of a bower component into my web project.

The structure of the source projects looks like this:

bower_components/roboto-fontface-bower/css/
bower_components/roboto-fontface-bower/fonts/
bower_components/roboto-fontface-bower/.bower.json
bower_components/roboto-fontface-bower/bower.json
bower_components/roboto-fontface-bower/LICSENSE
bower_components/roboto-fontface-bower/package.json
bower_components/roboto-fontface-bower/README.md

I would like to get the folder css (with included files) and fonts (with includes files).

My current minimatch pattern is:

"bower_components/roboto-fontface-bower/**"

With my current pattern, the files .bower.json, bower.json, etc. are also copied which is what I don't want. How can I only get the two folders (css & fonts)?

I tried "bower_components/roboto-fontface-bower/{css/,fonts/}" but this copies nothing.


Source: (StackOverflow)

Exclude a nested directory from being copied over when using a src glob

I can't exclude a directory structure from being copied over when using a glob in gulp src method. My task:

gulp.task( 'compile', function () {
    return gulp.src( 'src/modules/*/wrappers/**' )
        .pipe( gulp.dest( 'build/' ) );
} );

I am expecting to copy only files, not whole dir structure.

My dir structure:

+ src/
  + modules/
      + module_1/
          + wrappers/
              file_1
              file_2
      + module_2/
          + wrappers/
              file_3
              file_4
+ build/

Dir structure after running gulp task:

+ src/
  + modules/
      + module_1/
          + wrappers/
              file_1
              file_2
      + module_2/
          + wrappers/
              file_3
              file_4
+ build/
  + modules/
      + module_1/
          + wrappers/
              file_1
              file_2
      + module_2/
          + wrappers/
              file_3
              file_4

Expected dir structure after running gulp task:

+ src/
  + modules/
      + module_1/
          + wrappers/
              file_1
              file_2
      + module_2/
          + wrappers/
              file_3
              file_4
+ build/
      file_1
      file_2
      file_3
      file_4

It's worth noting that using e.g. glob 'src/modules/module_1/wrappers/**' gives desired result.

Used modules:

  • gulp 3.8.10

Am I doing something wrong or is that bug in js glob implementation?


Source: (StackOverflow)

how can I define a pattern for minimatch that finds files and excludes some directories in on command

I'm try to define a pattern for a minimatch line in a karma.conf.js coverage statement i.e. 'src/*.js': ['coverage']

but I have for example something like the folllowing directories and files, there are a lot more these are just a representative example:

/client/app.js
/client/assets/images/background.png
/client/bower_components/jquery/dist/jquery.js
/client/src/app.js
/client/src/app.spec.js
/client/src/components/buttons/amet.js
/client/src/components/codemirror/subdir/tincidunt.js
/client/src/components/codemirror/test/tincidunt.spec.js
/client/src/components/codemirror/tincidunt.js
/client/src/components/ipsum.js
/client/src/components/preview/lorem.js
/client/src/components/widget/lorem.js
/client/src/otherdir/sub/lotcd.js,
/server/consectetur.js
/server/otherdirs/consectetur.js
/server/otherdx/urna.js
/test/atest.spec.js

I'd like to include the *.js files within client dir that are not *.spec.js and exclude all js files in directories that have bower_components or codemirror in the pathname.

So the pattern matches come out to be these:

/client/app.js
/client/src/app.js
/client/src/components/buttons/amet.js
/client/src/components/ipsum.js
/client/src/components/preview/lorem.js 
/client/src/components/widget/lorem.js 
/client/src/otherdir/sub/lotcd.js

Trying several attempts using a minmatch test tool here http://www.globtester.com/ and a runnable http://runnable.com/VGG6AieB5u0-jHhx/minimatchtest-js-for-node-js without much success. Any explanation on how to address this is appreciated.


Source: (StackOverflow)