grunt-shell
Advanced tools
Comparing version 1.2.1 to 1.3.0
{ | ||
"name": "grunt-shell", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Run shell commands", | ||
@@ -33,12 +33,14 @@ "license": "MIT", | ||
"dependencies": { | ||
"chalk": "^1.0.0" | ||
"chalk": "^1.0.0", | ||
"npm-run-path": "^1.0.0", | ||
"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" | ||
} | ||
} |
@@ -7,3 +7,3 @@ # grunt-shell [![Build Status](https://travis-ci.org/sindresorhus/grunt-shell.svg?branch=master)](https://travis-ci.org/sindresorhus/grunt-shell) | ||
**Use [StackOverflow](http://stackoverflow.com/questions/tagged/gruntjs) for support questions.** | ||
**Use [Stack Overflow](http://stackoverflow.com/questions/tagged/gruntjs) for support questions.** | ||
@@ -74,5 +74,3 @@ | ||
hello: { | ||
command: function () { | ||
return 'echo hello'; | ||
} | ||
command: () => 'echo hello' | ||
} | ||
@@ -86,3 +84,3 @@ } | ||
```js | ||
module.exports = function(grunt) { | ||
module.exports = grunt => { | ||
grunt.loadNpmTasks('grunt-shell'); | ||
@@ -92,5 +90,3 @@ grunt.initConfig({ | ||
greet: { | ||
command: function (greeting) { | ||
return 'echo ' + greeting; | ||
} | ||
command: greeting => 'echo ' + greeting | ||
} | ||
@@ -183,7 +179,7 @@ } | ||
*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.* | ||
@@ -194,17 +190,17 @@ ## Options | ||
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` | ||
@@ -216,17 +212,17 @@ | ||
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` | ||
@@ -237,5 +233,12 @@ Lets you override the default callback with your own. | ||
### preferLocal | ||
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` | ||
@@ -242,0 +245,0 @@ 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: |
'use strict'; | ||
var exec = require('child_process').exec; | ||
var chalk = require('chalk'); | ||
var npmRunPath = require('npm-run-path'); | ||
var objectAssign = require('object-assign'); | ||
@@ -8,3 +10,3 @@ module.exports = function (grunt) { | ||
var cb = this.async(); | ||
var options = this.options({ | ||
var opts = this.options({ | ||
stdout: true, | ||
@@ -14,3 +16,7 @@ stderr: true, | ||
failOnError: true, | ||
stdinRawMode: false | ||
stdinRawMode: false, | ||
preferLocal: false, | ||
execOptions: { | ||
env: null | ||
} | ||
}); | ||
@@ -26,7 +32,12 @@ | ||
var cp = exec(cmd, options.execOptions, function (err, stdout, stderr) { | ||
if (typeof options.callback === 'function') { | ||
options.callback.call(this, err, stdout, stderr, cb); | ||
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, 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); | ||
@@ -50,15 +61,15 @@ } | ||
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); | ||
@@ -65,0 +76,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8159
64
251
4
2
+ Addednpm-run-path@^1.0.0
+ Addedobject-assign@^4.0.0
+ Addednpm-run-path@1.0.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedpath-key@1.0.0(transitive)