gruntjsglobgruntfilegrunt-plugins

Using glob patterns not for default Grunt keys


1. Summary

I can't set grunt-clean-console plugin, that it works for all my .html files.


2. Details

grunt-clean-console check browser console errors for .html files.

I want to check browser console errors for all .html files of my site. In official descripition I read, how plugin works for specific values of url key. I have many pages in my site; I don't want add each .html file separately. But I can't find, how I can use patterns.

I find, that I can use patterns for built-in Grunt cwd, src, dest keys. But how I can use glob (or another) patterns for custom keys as url of this plugin?


3. Data

3.1. Steps to reproduce

I run in console:

grunt clean-console --verbose

4. Not helped

4.1. Globbing

4.2. Building the object dinamically

4.3. Templates


Solution

  • Create a function before the grunt.initConfig part that utilizes grunt.file.expand. For instance:

    Gruntfile.js

    module.exports = function(grunt) {
    
      grunt.loadNpmTasks 'grunt-clean-console'
    
      // Add this function...
      function getFiles() { return grunt.file.expand('output/**/*.html'); }
    
      grunt.initConfig({
        'clean-console': {
          all: {
            options: {
              url: getFiles() // <-- invoke the function here.
            }
          }
        }
        // ...
      });
    
      // ...
    }
    

    Notes: