grunt-exec
Advanced tools
Comparing version 0.4.2 to 0.4.3
{ | ||
"name": "grunt-exec", | ||
"description": "Grunt task for executing shell commands.", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"homepage": "https://github.com/jharding/grunt-exec", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -25,5 +25,7 @@ [](http://travis-ci.org/jharding/grunt-exec) | ||
This plugin is a [multi task][types_of_tasks], meaning that grunt will automatically iterate over all exec targets if a target is not specified. | ||
This plugin is a [multi task][types_of_tasks], meaning that grunt will | ||
automatically iterate over all exec targets if a target is not specified. | ||
If the exit code generated by the specified shell command is greater than 0, grunt-exec will assume an error has occurred and will abort grunt immediately. | ||
If the exit code generated by the specified shell command is greater than 0, | ||
grunt-exec will assume an error has occurred and will abort grunt immediately. | ||
@@ -34,16 +36,25 @@ [types_of_tasks]: https://github.com/gruntjs/grunt/blob/master/docs/types_of_tasks.md#multi-tasks | ||
* __command__: The shell command to be executed. Must be a string or a function that returns a string. (alias: __cmd__) | ||
* __stdout__: If `true`, stdout will be printed. Defaults to `true`. | ||
* __stderr__: If `true`, stderr will be printed. Defaults to `true`. | ||
* __cwd__: Current working directory of the shell command. Defaults to the directory containing your Gruntfile. | ||
* __exitCode__: The expected exit code, task will fail if the actual exit code doesn't match. Defaults to `0`. | ||
* __callback__: The callback function passed `child_process.exec`. Defaults to a noop. | ||
* __command__ (alias: __cmd__): The shell command to be executed. Must be a | ||
string or a function that returns a string. | ||
* __stdout__: If `true`, stdout will be printed. Defaults to `true`. | ||
* __stderr__: If `true`, stderr will be printed. Defaults to `true`. | ||
* __cwd__: Current working directory of the shell command. Defaults to the | ||
directory containing your Gruntfile. | ||
* __exitCode__ (alias: __exitCodes__): The expected exit code(s), task will | ||
fail if the actual exit code doesn't match. Defaults to `0`. Can be an array | ||
for multiple allowed exit codes. | ||
* __callback__: The callback function passed `child_process.exec`. Defaults to | ||
a noop. | ||
### Command Functions | ||
If you plan on doing advanced stuff with grunt-exec, you'll most likely be using functions for the `command` property of your exec targets. This section details a couple of helpful tips about command functions that could help make your life easier. | ||
If you plan on doing advanced stuff with grunt-exec, you'll most likely be using | ||
functions for the `command` property of your exec targets. This section details | ||
a couple of helpful tips about command functions that could help make your life | ||
easier. | ||
#### Passing arguments from the command line | ||
Command functions can be called with arbitrary arguments. Let's say we have the following exec target that echoes a formatted name: | ||
Command functions can be called with arbitrary arguments. Let's say we have the | ||
following exec target that echoes a formatted name: | ||
@@ -65,7 +76,9 @@ ```javascript | ||
In order to get `SIMPSON, HOMER` echoed, you'd run `grunt exec:echo_name:homer:simpson` from the command line. | ||
In order to get `SIMPSON, HOMER` echoed, you'd run | ||
`grunt exec:echo_name:homer:simpson` from the command line. | ||
### Accessing `grunt` object | ||
All command functions are called in the context of the `grunt` object that they are being ran with. This means you can access the `grunt` object through `this`. | ||
All command functions are called in the context of the `grunt` object that they | ||
are being ran with. This means you can access the `grunt` object through `this`. | ||
@@ -122,3 +135,4 @@ ### Example | ||
For transparency and insight into the release cycle, releases will be numbered with the follow format: | ||
For transparency and insight into the release cycle, releases will be numbered | ||
with the follow format: | ||
@@ -125,0 +139,0 @@ `<major>.<minor>.<patch>` |
@@ -20,3 +20,3 @@ // grunt-exec | ||
, callback = _.isFunction(data.callback) ? data.callback : function() {} | ||
, exitCode = data.exitCode || 0 | ||
, exitCodes = data.exitCode || data.exitCodes || 0 | ||
, command | ||
@@ -27,2 +27,5 @@ , childProcess | ||
// https://github.com/jharding/grunt-exec/pull/30 | ||
exitCodes = _.isArray(exitCodes) ? exitCodes : [exitCodes]; | ||
// allow for command to be specified in either | ||
@@ -50,3 +53,3 @@ // 'command' or 'cmd' property | ||
verbose.subhead(command); | ||
verbose.writeln(f('Expecting exit code %d', exitCode)); | ||
verbose.writeln(f('Expecting exit code %s', exitCodes.join(' or '))); | ||
@@ -59,3 +62,3 @@ childProcess = cp.exec(command, execOptions, callback); | ||
childProcess.on('exit', function(code) { | ||
if (code !== exitCode) { | ||
if (exitCodes.indexOf(code) < 0) { | ||
log.error(f('Exited with code: %d.', code)); | ||
@@ -62,0 +65,0 @@ return done(false); |
@@ -23,7 +23,8 @@ module.exports = function(grunt) { | ||
return 'echo "you can use callback, and error, stdout, stderr can be used as arguments"'; | ||
}, | ||
callback: function(error, stdout, stderr){ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var outputPath = path.resolve(process.cwd(), 'test4'); | ||
} | ||
, callback: function(error, stdout, stderr){ | ||
var fs = require('fs') | ||
, path = require('path') | ||
, outputPath = path.resolve(process.cwd(), 'test4'); | ||
console.log('outputPath : ' + outputPath); | ||
@@ -33,2 +34,10 @@ fs.writeFileSync(outputPath, stdout, 'utf-8'); | ||
} | ||
, test5: { | ||
cmd: 'exit 8' | ||
, exitCodes: 8 | ||
} | ||
, test6: { | ||
cmd: 'exit 9' | ||
, exitCodes: [8, 9] | ||
} | ||
} | ||
@@ -35,0 +44,0 @@ }); |
@@ -7,3 +7,10 @@ var grunt = require('grunt') | ||
, opts = { gruntfile: path.join(testDir, 'Gruntfile.js') } | ||
, tasks = ['exec:test1', 'exec:test2', 'exec:test3:42:love', 'exec:test4']; | ||
, tasks = [ | ||
'exec:test1' | ||
, 'exec:test2' | ||
, 'exec:test3:42:love' | ||
, 'exec:test4' | ||
, 'exec:test5' | ||
, 'exec:test6' | ||
]; | ||
@@ -10,0 +17,0 @@ grunt.tasks(tasks, opts, function() { |
Sorry, the diff of this file is not supported yet
11804
199
150