Skip to content

Commit

Permalink
meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 15, 2016
1 parent 82a1770 commit b9a0cb5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 38 deletions.
File renamed without changes.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"object-assign": "^4.0.0"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"xo": "*"
},
"peerDependencies": {
"grunt": ">=0.4"
"grunt": ">=0.4.0"
}
}
42 changes: 19 additions & 23 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
A good way to interact with other CLI tools. E.g. compiling Compass `compass compile` or get the current git branch `git branch`.

**Use [StackOverflow](http://stackoverflow.com/questions/tagged/gruntjs) for support questions.**
**Use [Stack Overflow](http://stackoverflow.com/questions/tagged/gruntjs) for support questions.**


## Install
Expand Down Expand Up @@ -70,9 +70,7 @@ You can also supply a function that returns the command:
grunt.initConfig({
shell: {
hello: {
command: function () {
return 'echo hello';
}
command: () => 'echo hello'
}
}
});
Expand All @@ -81,14 +79,12 @@ grunt.initConfig({
Which can also take arguments:

```js
module.exports = function(grunt) {
module.exports = grunt => {
grunt.loadNpmTasks('grunt-shell');
grunt.initConfig({
shell: {
greet: {
command: function (greeting) {
return 'echo ' + greeting;
}
command: greeting => 'echo ' + greeting
}
}
});
Expand Down Expand Up @@ -176,67 +172,67 @@ grunt.initConfig({
### command

*Required*<br>
Type: `string`, `function`
Type: `String` `Function`

The command you want to run or a function which returns it. Supports underscore templates.
Command to run or a function which returns the command. Supports underscore templates.

*command can be omitted by directly setting the target with the command.*
*Command can be omitted by directly setting the target with the command.*

## Options

### stdout

Type: `boolean`<br>
Type: `Boolean`<br>
Default: `true`

Show stdout in the Terminal.
Show stdout in the terminal.

### stderr

Type: `boolean`<br>
Type: `Boolean`<br>
Default: `true`

Show stderr in the Terminal.
Show stderr in the terminal.

### stdin

Type: `boolean`<br>
Type: `Boolean`<br>
Default: `true`

Forward the terminal's stdin to the command.

### failOnError

Type: `boolean`<br>
Type: `Boolean`<br>
Default: `true`

Fail task if it encounters an error. Does not apply if you specify a `callback`.
Fail task if it encounters an error. Doesn't apply if you specify a `callback`.

### stdinRawMode

Type: `boolean`<br>
Type: `Boolean`<br>
Default: `false`

This sets `stdin` to [act as a raw device](http://nodejs.org/api/tty.html#tty_rs_setrawmode_mode).
Set `stdin` to [act as a raw device](http://nodejs.org/api/tty.html#tty_rs_setrawmode_mode).

### callback(err, stdout, stderr, cb)

Type: `function`
Type: `Function`

Lets you override the default callback with your own.

**Make sure to call the `cb` method when you're done.**

### preferLocal

Type: `boolean`<br>
Type: `Boolean`<br>
Default: `false`

Execute local binaries by name like [npm run-script](http://blog.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/).

### execOptions

Type: `object`
Type: `Object`

Specify some options to be passed to the [.exec()](http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback) method:

Expand Down
24 changes: 12 additions & 12 deletions tasks/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var objectAssign = require('object-assign');
module.exports = function (grunt) {
grunt.registerMultiTask('shell', 'Run shell commands', function () {
var cb = this.async();
var options = this.options({
var opts = this.options({
stdout: true,
stderr: true,
stdin: true,
Expand All @@ -27,16 +27,16 @@ module.exports = function (grunt) {

cmd = grunt.template.process(typeof cmd === 'function' ? cmd.apply(grunt, arguments) : cmd);

if (options.preferLocal === true) {
options.execOptions.env = options.execOptions.env || objectAssign({}, process.env);
options.execOptions.env.PATH = npmRunPath({path: options.execOptions.env.PATH});
if (opts.preferLocal === true) {
opts.execOptions.env = opts.execOptions.env || objectAssign({}, process.env);
opts.execOptions.env.PATH = npmRunPath({path: opts.execOptions.env.PATH});
}

var cp = exec(cmd, options.execOptions, function (err, stdout, stderr) {
if (typeof options.callback === 'function') {
options.callback.call(this, err, stdout, stderr, cb);
var cp = exec(cmd, opts.execOptions, function (err, stdout, stderr) {
if (typeof opts.callback === 'function') {
opts.callback.call(this, err, stdout, stderr, cb);
} else {
if (err && options.failOnError) {
if (err && opts.failOnError) {
grunt.warn(err);
}
cb();
Expand All @@ -55,19 +55,19 @@ module.exports = function (grunt) {

grunt.verbose.writeln('Command:', chalk.yellow(cmd));

if (options.stdout || grunt.option('verbose')) {
if (opts.stdout || grunt.option('verbose')) {
captureOutput(cp.stdout, process.stdout);
}

if (options.stderr || grunt.option('verbose')) {
if (opts.stderr || grunt.option('verbose')) {
captureOutput(cp.stderr, process.stderr);
}

if (options.stdin) {
if (opts.stdin) {
process.stdin.resume();
process.stdin.setEncoding('utf8');

if (options.stdinRawMode && process.stdin.isTTY) {
if (opts.stdinRawMode && process.stdin.isTTY) {
process.stdin.setRawMode(true);
}

Expand Down

0 comments on commit b9a0cb5

Please sign in to comment.