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

v0.0.2

Published

functions to help manipulate grunt tasks

Downloads

2

Readme

grunt-multitasker

Helper functions for manipulating grunt tasks

Grunt tasks are very versatile, but there are a few things missing.

  • The ability to add a multitask with various aliases for targets
  • The ability to set a default target for a multitask

Getting started

This helper requires Grunt ~0.4.5 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.

To install the helper for use in your gruntfile, use this command:

npm install grunt-multitasker --save-dev

To instantiate the helper inside your gruntfile, simpy use:

var multitasker = require('grunt-multitasker')(grunt);

if you'd like the functions to be added to the grunt and grunt.task objects as well, pass true as an additional argument when instantiating the helper, eg

require('grunt-multitasker')(grunt, true);

The helper has several functions to aid in simplifying building tasks

##Note If you use the load-grunt-tasks module, take care to exclude grunt-multitasker from its globbing patterns. By default it will load tasks for any module matching grunt-*, which causes a warning in the grunt output. The registered tasks should still work however

Creating a simple multitask

A standard grunt task can be registered with an alias, which is simply an array of other tasks to execute, like so:

grunt.registerTask('myTask', ['otherTask1', 'otherTask2']);

Unfortunately, if you want to have several variations on this, you need to either register several tasks, or you need to create a task with a function that listens to a psuedotarget parameter. The first solution is fine (and in fact, ideal) when the chains of tasks aren't related. But when they're related or very similar, it makes sense to group them. Unfortunately writing them in a function is clunky, like so:

grunt.registerTask('myTask', function(target) {
  if (target === 'target1'){
    grunt.task.run(['otherTask1, otherTask2, otherTask3']);
  }
  else if (target === 'target2') {
    grunt.task.run(['otherTask1, otherTask3']);
  }
  else if (target === 'target3') {
    grunt.task.run(['myTask:target2', 'otherTask4']);
  }
  //etc...
});

The multitask makes it easy to group aliases together like targets in a real multitask, by generating the internal function for you. you can create a multitask easily like this:

multitasker.registerMultiAliasTask('myTask', {
  target1: ['otherTask1, otherTask2, otherTask3'],
  target2: ['otherTask1, otherTask3'],
  target3: ['myTask:target2', 'otherTask4']
});

You can also specify a default target in two ways. You can either give it it's own alias

default: ['otherTask1', 'otherTask2']

or you can give it the name of one of the other targets

default: 'target3'

Setting a default target for a multitask

Multitasks allow you to run a specific target configuration, but when you don't specify one, they run all of their target configurations, in the order they were declared. This is often useful, but sometimes certain targets can be dangerous to run by accident, so being able to specify a default target would be nice. The helper can do this for you by renaming the task, and reexposing it with a wrapper of the same name that defaults the target for you.

for example, if your copy task had 4 targets declared

grunt.initConfig({
  copy: {
    t1: {...},
    t2: {...},
    t3: {...},
    t4: {...}
  }
});

if you ran grunt copy, the effect would be the same as if you had ran grunt copy:t1; grunt copy:t2; grunt copy:t3; grunt copy:t4. If you want to have a specific set of targets (or a single target) run instead, you'd have to write another task that aliases the targets. The helper makes this simple

// default to just task t2
multitasker.setDefaultTargets('copy', 't2');

// default to tasks 1 and 3
multitasker.setDefaultTargets('copy', ['t1', 't3']);

When renaming the original task, the name will be appended with -base, eg copy-base. An optional third argument lets you specify what the task should be renamed to

multitasker.setDefaultTargets('copy', 't2', 'theTaskFormerlyKnownAsCopy');

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

(Nothing yet)