Skip to content

eluck/grunt-dirstruct-guardian

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grunt-dirstruct-guardian Build Status

Watches that certain filetypes lie in associated directories, e.g. .js-files in the 'js' dir.

Getting Started

This plugin requires Grunt ~0.4.2

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-dirstruct-guardian --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-dirstruct-guardian');

Or better use matchdep if you tired of including tons of "loadNpmTasks".

The "dirstruct_guardian" task

Overview

In your project's Gruntfile, add a section named dirstruct_guardian to the data object passed into grunt.initConfig().

grunt.initConfig({
    dirstruct_guardian: {
        options: {
            fail: true
        }
        task1: {
            files: [
                { allowed: ['.js', '.coffee'], src: ['a/path/regarding/root', 'another/path/regarding/root'], expand: true }
            ]
        },
        task2: {
            files: [
                { allowed: ['.css', '.less'], cwd: 'path/regarding/root', src: ['path/regarding/cwd', expand: true }
            ]
        }
    },
});

All rules are applied independently.

Options

options.fail

Type: Boolean Default value: false

If set to true, the grunt task will abort when it finds a file, which is not allowed for the directory. Otherwise it will just log a warning.

files.allowed

Type: Array of String Default value: []

List of allowed file extensions for the directories specified in files.src;

files.src, files.expand, files.cwd, etc.

These values help to define set of guarded directories. Find here extensive documentation on how to build extended file matchers that fit your needs.

Usage Examples

Example 1

Checking that:

  • 'routers' directory and its subdirectories only contain .js files
  • 'public/js' directory and its subdirectories only contain .js files
  • 'tests' directory and its subdirectories only contain .js and .json files
  • 'public/css' directory only contains .css files
  • 'pulbic/css/map' directory only contains .map files
grunt.initConfig({
    dirstruct_guardian: {
        options: {
            fail: true
        },
        js: {
            files: [
                { allowed: ['.js'], src: ['routers/**', 'public/js/**'], expand: true },
                { allowed: ['.js', '.json'], src: ['tests/**'], expand: true }
            ]
        },
        css: {
            files: [
                { allowed: ['.css'], src: ['public/css/*'], expand: true },
                { allowed: ['.map'], src: ['public/css/map/*'], expand: true }
            ]
        }
    }
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

  • 2014-01-08   v0.1.0   Initial release
  • 2014-01-09   v0.2.0   Colorize output, improve reporting and testing

License

MIT © eluck

About

Watches that certain filetypes lie in associated directories, e.g. .js-files in the 'js' dir.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors