grunt-run-grunt
Grunt task to run Gruntfiles in a child process. Gruntception!
Console output capture is not reliable on Windows as Node.js there doesn't always flush buffers before exiting. Until this is fixed Windows users should use the Vagrantfile instead (see below). ‼️
Getting Started
This plugin requires Grunt >=1.0.0
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-grunt --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt;
The "run_grunt" task
"Yo dawg! I herd you like grunt, so I put some grunt in your grunt so you can grunt while you grunt." 😆
Use the run_grunt
task to spawn new processes that run grunt-cli
and optionally do work on the result data. It will use the global $ grunt
command, just like when you'd run grunt manually.
Main use-case is testing your gruntfile or grunt-plugins, but it is also suited for creative use of gruntfiles and grunt-cli output.
For example use it to verify the final output of various reporters and formatters. Alternately parse the output of the "$grunt --help" command and work with the list of tasks and aliases (without instrumenting the gruntfile in any way).
If you need something similar to run grunt in a production build environment or don't really care about the content of the cli output then you are probably looking for grunt-hub instead. If you need to run tasks from one Gruntfile concurrently use grunt-concurrent or grunt-parallel.
In the future there will also be a way to use this as a standard Node.js module, so you can run grunt from inside standard scripts. Why? Who knows?
Usage
In your project's Gruntfile, add a section named run_grunt
to the data object passed into grunt.initConfig()
.
grunt
Options
grunt-cli options
help: booleanbase: 'string''no-color': booleandebug: booleanstack: booleanforce: booleantasks: booleannpm: 'string''no-write': booleanverbose: booleanversion: boolean
Custom options
// pass the tasks to run: either a string or array-of-stringstask: 'clean' 'jshint:strictTarget' 'mocha:subTarget' // process the result data object { // see below for result structure} // log child console outputlog: true // indent child console output with this stringindentLog: ' | ' // save raw output to filelogFile: null // modify env variablesenv: {} // apply an output parser (see below for values)parser: '' // how many parallel grunts to runconcurrent: <number> cpu-cores // expect at least this many filesminimumFiles: 1 // change the cwd of the gruntfilecwd: null //--- experimental options // generate cli commanddebugCli: false // save .bat and shellscriptswriteShell: null // don't failexpectFail: false // pass options that will be available in the executed gruntfile with grunt.option('myOption')// NOTE: will overwrite cli options with the same name!gruntOptions: {}
Process result object
// status, can overridefail: falseoutput: 'string' // parsed dataparsed: 'parseHelp' : {} // raw grunt.util.spawn callback argumentserrorrescode // used parameterssrc: 'path/to/Gruntfile.js'cwd: 'string'tasks: options: {} //cleaned srcgruntfile: 'Gruntfile' // timingstart: Dateend: 0duration: 0
Parsers
parseHelp
Parse grunt -h
output
- Use the
process
option to access the data. - Returns
result.parsed.parseHelp
object with task and alias names. - Requires
help
option (in a later version this will be forced)
Release History
See the CHANGELOG.
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.
Development
Requirements
There is a Vagrantfile and set of Chef cookbooks to use with Vagrant for easy testing on a Linux VM. It will install a node.js from nvm, install the dependencies and enable grunt.
$ bundle install
$ librarian-chef install
$ vagrant up
License
Copyright (c) 2017 Bart van der Schoor
Licensed under the MIT license.