Invite external commands into your grunt process with three tasks
This plugin requires Grunt
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
In your project's Gruntfile, add a section named
run to the data object passed into
Since this task doesn't operate on "files" it also doesn't use the standard src/files options. Instead, specify a
args: key to your test's config (see examples).
cmd: defaults to
If you would like to specify your command as a single string, usefull for specifying multiple commands in one task, use the
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.
# 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
Should we change the working directory for the command runs in?
true to ignore stdout from the process,
Infinity to ignore stderr as well (opts.failOnError will still work)
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
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.
Before running the command, look for these options using grunt.option(). The syntax supported for specifying command line args in grunt is
Want to just run some command line tool? With this config calling
grunt run:tool will run that tool.
Want to run a few commands. With this config calling
grunt run:commands will run them.
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.
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.
When you execute a command, sometimes you want to modify the script form the call to grunt.
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"
Please lint and test your code with the included jshint config, or just run