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

v0.8.1

Published

Invite external commands into your grunt process with three tasks `run`, `wait` and `stop`.

Downloads

124,447

Readme

grunt-run

Invite external commands into your grunt process with three tasks run, wait and stop.

Getting Started

This plugin requires Grunt ~0.4.1

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-run --save-dev

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

grunt.loadNpmTasks('grunt-run');

The "run" task

Overview

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

grunt.initConfig({
  run: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      cmd: 'executable',
      args: [
        'arg1',
        'arg2'
      ]
    }
  }
})

Src/files/etc

Since this task doesn't operate on "files" it also doesn't use the standard src/files options. Instead, specify a cmd: and args: key to your test's config (see examples). cmd: defaults to "node".

If you would like to specify your command as a single string, usefull for specifying multiple commands in one task, use the exec: key

Options

options.wait

Type: Boolean Default value: true

Should this task wait until the script exits before finishing? If you set this to false because you want to start a service of some sort before running another task, you can override this setting by passing the "keepalive" argument to the task call.

Example:

# start a testing instance of Elasticsearch and run some tests, `wait: false`
$ grunt run:es mocha:test

# override `wait` to keep Elasticsearch running
$ grunt run:es:keepalive

options.cwd

Type: String Default value: process.cwd()

Should we change the working directory for the command runs in?

options.quiet

Type: Boolean, Infinity Default value: false

Set to true to ignore stdout from the process, Infinity to ignore stderr as well (opts.failOnError will still work)

options.ready

Type: RegExp, Number, or false Default value: 1000

If we are not waiting for the process to complete, then how do we know the process is ready?

A RegExp will test the lines from stdout and stderr and complete the task once the test succeeds, a Number will just set a timeout, and anything else will complete the task on nextTick

options.failOnError

Type: Boolean Default value: false

If the process outputs anything on stderr then the process will be killed. If wait is true it will cause the task to fail as well.

options.passArgs

Type: Array Default value: []

Before running the command, look for these options using grunt.option(). The syntax supported for specifying command line args in grunt is --option1=myValue.

Usage Examples

Default

Want to just run some command line tool? With this config calling grunt run:tool will run that tool.

grunt.initConfig({
  run: {
    tool: {
      cmd: './some-bash-script',
    }
  }
});

grunt.loadNpmTasks('grunt-run');

Multiple scripts

Want to run a few commands. With this config calling grunt run:commands will run them.

grunt.initConfig({
  run: {
    commands: {
      exec: './some-bash-script && ./some-other-script',
    }
  }
});

grunt.loadNpmTasks('grunt-run');

waiting

In this example, we are starting a small server that will serve our mocha tests to a browser. We will then open that page in the browser and tell grunt to wait until the process is exited, which probably won't happen so the process will just run until the user ends the process manually.

grunt.initConfig({
  run: {
    integration_server: {
      options: {
        wait: false
      },
      // cmd: "node", // but that's the default
      args: [
        'test/integration_server.js'
      ]
    }
  },
  // https://github.com/jsoverson/grunt-open
  open: {
    integration_suite: {
      path: 'http://localhost:8888',
      app: 'Google Chrome'
    }

  }
});

grunt.loadNpmTasks('grunt-run');
grunt.loadNpmTasks('grunt-open');

grunt.registerTask('test', [
  'run:integration_server',
  'open:integration_tests',
  'wait:integration_server'
]);

stoping

We can do something similar using grunt-mocha to run the tests inside phantomjs, but instead of waiting for the process we will just stop it once mocha is done.

grunt.initConfig({
  run: {
    integration_server: {
      options: {
        wait: false
      },
      args: [
        'test/integration_server.js'
      ]
    }
  },
  // https://github.com/kmiyashiro/grunt-mocha
  mocha: {
    integration_suite: {
      urls: 'http://localhost:8888',
      app: 'Google Chrome'
    }
  }
});

grunt.loadNpmTasks('grunt-run');
grunt.loadNpmTasks('grunt-mocha');

grunt.registerTask('test', [
  'run:integration_server',
  'mocha:integration_suite',
  'stop:integration_server'
]);

passing args

When you execute a command, sometimes you want to modify the script form the call to grunt.

grunt.initConfig({
  run: {
    server: {
      args: ['./server.js'],
      options: {
        passArgs: [
          'port'
        ]
      }
    }
  }
})

Then you can specify a --port option when calling grunt and it will be sent to the other process.

$ grunt run:server --port=8888
# calls "node ./server.js --port=8888"

Contributing

Please lint and test your code with the included jshint config, or just run grunt.