npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-organized

v0.1.4

Published

Allows describing grunt tasks in a more organized, readable style, grouped by target rather than task type.

Downloads

3

Readme

Grunt-organized enables you to write more organized Gruntfiles. It enhances the Grunt API to allow organizing your Gruntfile by target rather than by task. It also makes your Gruntfile more DRY by offering a clean, simple way to register a group of tasks under an alias.

##Example Gruntfile.js

Here is a sample Gruntfile.js using grunt-organized.

module.exports = function(grunt) {
    // Load grunt-organized and initialize our grunt config.
    grunt = require('grunt-organized')(grunt, {
        pkg: grunt.file.readJSON('package.json'
    });
    
    // Add several tasks used to build our project
    grunt.registerTask('build', 'Build site', {
        // minify JS code
        uglify: {
            files: [{
                expand: true,
                src: ['src/js/**/*.js'],
                dest: 'out/js'
            }]
        },
        // Copy static resources
        copy: {
            files: [{
                expand: true,
                cwd: 'src/resources',
                src: ['**/*'],
                dest: 'out/resources'
            }]
        }
    });
    
    // Add several tasks used to generate our API documentation from markdown files
    grunt.registerTask('docs', 'Generate API documentation', {
        // Copy images used in documentation
        copy: {
            files: [{
                expand: true,
                cwd: 'docs-src/img',
                src: ['**/*'],
                dest: 'docs/img'
            }]
        },
        // Render markdown
        markdown: {
            files: [{
                expand: true,
                cwd: 'docs-src',
                src: ['/**/*.md'],
                dest: 'docs'
            }]
        }
    });
};

The above Gruntfile is equivalent to:

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        uglify: {
            build: {
                // minify JS code
                files: [{
                    expand: true,
                    src: ['src/js/**/*.js'],
                    dest: 'out/js'
                }]
            }
        },
        copy: {
            build: {
                files: [{
                    expand: true,
                    cwd: 'src/resources',
                    src: ['**/*'],
                    dest: 'out/resources'
                }]
            },
            docs: {
                files: [{
                    expand: true,
                    cwd: 'docs-src/img',
                    src: ['**/*'],
                    dest: 'docs/img'
                }]
            }
        },
        markdown: {
            docs: {
                files: [{
                    expand: true,
                    cwd: 'docs-src',
                    src: ['/**/*.md'],
                    dest: 'docs'
                }]
            }
        }
    });
    
    grunt.registerTask('build', 'Build site', ['uglify:build', 'copy:build']);
    grunt.registerTask('docs', 'Generate API documentation', ['copy:docs', 'markdown:docs']);

Grunt-organized takes care of merging multiple targets into a single grunt-contrib-copy configuration and calls grunt.registerTask to create the alias tasks.

Grunt-organized also lets you mix custom task functions, target configurations, and task names in a single call to registerTask:

    /*
     * Register a task called 'cleanup' that will use grunt-contrib-clean, then
     * run the 'stop-server' task, and finally run a custom task.
     */
    grunt.registerTask('cleanup', [
        {
            clean: { src: ['temp/**/*'] }
        },
        'stop-server',
        function(grunt) {
            console.log('All done!');
        }
    ]);

##Usage

npm install --save-dev grunt-organized

In your Gruntfile, load and invoke the module, passing it your grunt object and optionally a grunt configuration object. This will return an object that mimics the grunt API such that it's a drop-in replacement for grunt. It will also call grunt.initConfig.

module.exports = function(grunt) {
    grunt = require('grunt-organized')(grunt, {
        pkg: grunt.file.readJSON('package.json')
    });
}

Alternatively, you can monkey-patch the API onto your grunt object by calling mixin.

module.exports = function(grunt) {
    require('grunt-organized').mixin(grunt, {
        pkg: grunt.file.readJSON('package.json')
    });
    grunt.registerTask(/* ... */);

Then configure plugins and register tasks using the enhanced APIs, original APIs, or any mix of the two.

##Grunt API Enhancements

###registerTask

In addition to Grunt's normal registerTask interface, grunt-organized also supports:

grunt.registerTask(taskName: string, description?: string, ...tasks: (function|string|object)[])
grunt.registerTask(taskName: string, description?: string, tasks: (function|string|object)[])

###addConfig

grunt.addConfig(configObject: object)

Adds more configuration into the existing grunt configuration, merging additional task targets into any existing configuration for that task.

Example:

grunt.addConfig({
    clean: {
        demo: { src: ['temp/demo'] }
    }
});
grunt.addConfig({
    clean: {
        docs: { src: ['temp/docs'] } // add new `docs` target to existing `clean` configuration
    },
    stylus: {
        // ... more config ...
    }
});

##TypeScript definitions

If you're using TypeScript, grunt-organized includes a type definition: grunt-organized.d.ts.

/// <reference path="node_modules/grunt-organized/grunt-organized.d.ts" />

##License

Licensed under the MIT License.