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-usage

v1.1.1

Published

Usage description compositor for Grunt

Downloads

15

Readme

Grunt-usage

This plugin modifies the Grunt help output to be more user-friendly and relevant to your specific project.

By default, the "available tasks" section in the grunt --help output is not very helpful—for large projects, it often contains a lot of tasks that aren't meant to be used directly, but are part of a larger script.

This plugin uses argparse to display a usage overview that's relevant only to your tasks, and also allows you to hide the extraneous information that Grunt outputs while it's running a script.

Installation and setup

This assumes you're using npm to manage your project's dependencies. See the npm docs for a tutorial on how to initialize a new project if you haven't already.

First, save the plugin to your project:

npm install --save-dev grunt-usage

Then edit your Gruntfile.js and add the following:

grunt.initConfig({
  // ... other stuff here

  // Usage - displays usage information in a user-friendly manner
  'usage': {
    'options': {
      'title': 'My Awesome Website <https://site.com/>\n(C) 2015, MIT\n',
      // add all the tasks you want to display:
      'taskGroups': [
        {
          'header': 'My tasks',
          'tasks': ['dev-build', 'release', 'jshint', 'jscs']
        }
      ],
    }
  }
});

This will display the following output when running grunt usage:

My Awesome Website <https://site.com/>
(C) 2015, MIT

usage: grunt [dev] [release] [jshint] [jscs]

Your package.json description value goes here.

My tasks:
  dev       Runs a development server on localhost:8000.
  release   Compiles a release build of the website.
  jshint    Validate files with JSHint.
  jscs      JavaScript Code Style checker.

We recommend setting the default task to usage to get this output whenever you invoke just the grunt command:

grunt.registerTask('default', ['usage']);

You can still get the default Grunt help text by running grunt --help.

options

options.title

  • Type: Array|String

A title that's printed at the top of the usage output. You can pass either a string or an array (which will be joined with line breaks). This is a good place to add a copyright notice. You can add some colors with an undocumented feature.

options.taskGroups

  • Type: Array

An array containing the task groups you'd like to show in the usage output.

options.taskGroups.header
  • Type: String
  • Default: "Grunt tasks"

The section header displayed above the task group.

options.taskGroups.tasks
  • Type: Array

List of tasks to display in this task group. Note that you should use the task names, not the package names—e.g. 'jshint' instead of 'grunt-contrib-jshint'.

Note that you cannot have duplicate tasks in multiple groups.

options.hideTasks

  • Type: Boolean
  • Default: false

This causes the Grunt task header output to be hidden, i.e. the "Running 'task-name:target' (task-name) task" notifications. Note that this is a global setting that applies to all other tasks as well, as long as this plugin is initialized.

You can get the task header output back by passing the --show-tasks argument in the command line, even with this option set to true.

options.formatting

options.formatting.addPeriod
  • Type: Boolean
  • Default: true

Ensures that each description line ends with a period.

options.description

  • Type: String
  • Default: the description field from your project's package.json

By default, we show the description from the package.json file. Passing a description variable will override this.

options.taskDescriptionOverrides

  • Type: Object

Allows you to define alternate descriptions for your tasks. For example, if you don't like the jscs description (which is just "JavaScript Code Style checker"), you can override it here and type something more descriptive, such as "Checks code compliance with the style guide. See http://site.com/styleguide/."

These overrides apply to every task group.

Example with all options set

'usage': {
  'options': {
    'title': [
        'My Awesome Website <https://site.com/>',
        '(C) '+new Date().getFullYear()+', MIT license',
        ''
    ],
    'taskGroups': [
      {
        'header': 'Build tasks',
        'tasks': ['dev', 'release']
      },
      {
        'header': 'Code validation',
        'tasks': ['jshint', 'jscs']
      },
    ],
    'hideTasks': true, // hide task header output
    'formatting': {
      'addPeriod': true
    },
    'description': 'Task runner setup for My Awesome Website. If you\'re ' +
      'lost, go to <http://mysite.com/documentation/> for more information.',
    'taskDescriptionOverrides': {
      'jscs': 'Ensures code compliance with the Google JS Style Guide. ' +
        'Details can be found at <http://goo.gl/tJaiiP>.',
      'jshint': 'Runs the JSHint linter on the library code.'
    }
  }
}

This produces:

My Awesome Website <https://site.com/>
(C) 2015, MIT license

usage: grunt [dev] [release] [jshint] [jscs]

Task runner setup for My Awesome Website. If you're lost, go to
<http://mysite.com/documentation/> for more information.

Build tasks:
  dev       Runs a development server on localhost:8000.
  release   Compiles a release build of the website.

Code validation:
  jshint    Runs the JSHint linter on the library code.
  jscs      Ensures code compliance with the Google JS Style Guide. Details
            can be found at <http://goo.gl/tJaiiP>.

(Unfortunately, we can't hide the 'done, without errors' line at the end.)

Copyright

© 2015, Michiel Sikma. MIT license.

See the included license.md file.