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

v2.0.0

Published

Run tasks multiple times programmatically with dynamic options

Downloads

376

Readme

grunt-galvanize

Run other grunt tasks multiple times with different options.

Install

$ npm install --save-dev grunt-galvanize

Why?

Using grunt with static configurations has its limits. Perhaps your build process needs to read in a list of files from disk, then perform tasks on those files. This is made difficult by the fact that grunt.task.run simply queues a new task to be run. Thus the state of grunt.config may change between the time that the task was queued and when it is run. Galvanize allows you to define critical components of grunt.options and grunt.config, and ensure that those components are in the desired state when a sub-task is run. In practice, this enables calling grunt.task.run within a loop.

Usage

Create galvanizeConfig:

The galvanizeConfig is an array of objects with a configs and an options property. The configs and options will be used to set grunt config and grunt options before running each iteration of a task.

   grunt.option('galvanizeConfig', [
       { configs: {color: 'red'}, options: {size: small} },
       { configs: {color: 'green'}, options: {size: small}
   ]);

Run galvanize:

Run the galvanize task, specifying the task that you would like galvanize to iterate.

grunt.task.run(['galvanize:myTask']);

The above config will result in running myTask once with grunt.config.color = 'red', and once with grunt.config.color = 'green'.

Get fancy

For nested configs and options, use an array to specify the key and value:

    grunt.option('galvanizeConfig', [
        {
            configs: [
                { key: ['browserify', 'files'], value: '/mnt/foo/bar/**.js' },
                { key: ['browserify', 'dedup'], value: false }
            ]
        },
        {
            configs: [
                { key: ['browserify', 'files'], value: '/mnt/foo/baz/**.js' },
                { key: ['browserify', 'dedup'], value: true }
            ]
        }
    ]);

    grunt.task.run(['galvanize:browserify']);

The above config will run browserify once with grunt.config.browserify.files set to /mnt/foo/bar/**.js, and once with grunt.config.browserify.files set to /mnt/foo/baz/**.js.

The galvanizeConfig can be easily created programmatically within your build process.

In the wild:

Here's a snippet from our code base that takes advantage of Galvanize

/**
 * Run udb on each changelog in the master runlist
 * @param {string} db is the alias for the DB against which changelogs should be run.
 *   defaults to the db defined for the current branch in config.dbBranchMap.
 */
grunt.registerTask('execRunlist', '', function(db) {
    var runlistPath = config.get('masterRunlist');
    var runlist = grunt.file.readJSON(runlistPath);

    // verify that runlist is an array
    if (!_.isArray(runlist)) {
        throw new Error(
            'runlist is not an array: it is a ' + typeof runlist
        );
    }

    // map runlists to options object
    var galvanizeConfig = runlist.map(function(path) {
        return {options: {path: path}};
    });

    grunt.option('galvanizeConfig', galvanizeConfig);
    grunt.task.run([
        'galvanize:udb', //run udb for each path in galvanizeConfig
        'galvanize:dequeueFromRunlist' //remove each path in galvanizeConfig from runlist
    ]);
});

Contributing

Please submit any changes to this repo (including additions and subtractions from the lint config files) as pull requests.