Skip to content

Commit

Permalink
[BREAKING] ES2015ify and require Node.js 4
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 25, 2016
1 parent 88e6f6e commit 3b379e7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto
*.js text eol=lf
10 changes: 5 additions & 5 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
module.exports = function (grunt) {
module.exports = grunt => {
function log(err, stdout, stderr, cb) {
console.log('Directory listing:\n' + stdout);
console.log(`Directory listing:\n${stdout}`);
cb();
}

Expand All @@ -17,13 +17,13 @@ module.exports = function (grunt) {
}
},
fnCmd: {
command: function (version) {
command(version) {
// `this` is scoped to the grunt instance
if (version) {
return 'echo grunt-shell version: ' + version;
return `echo grunt-shell version: ${version}`;
}

return 'echo grunt version: ' + this.version;
return `echo grunt version: ${this.version}`;
}
},
callback: {
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "xo && grunt"
Expand All @@ -31,8 +31,7 @@
],
"dependencies": {
"chalk": "^1.0.0",
"npm-run-path": "^2.0.0",
"object-assign": "^4.0.0"
"npm-run-path": "^2.0.0"
},
"devDependencies": {
"grunt": "^1.0.1",
Expand All @@ -41,5 +40,8 @@
},
"peerDependencies": {
"grunt": ">=0.4.0"
},
"xo": {
"esnext": true
}
}
30 changes: 15 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ grunt.initConfig({
### command

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

Command to run or a function which returns the command. Supports underscore templates.

Expand All @@ -193,35 +193,35 @@ Command to run or a function which returns the command. Supports underscore temp

### stdout

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

Show stdout in the terminal.

### stderr

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

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. Doesn't apply if you specify a `callback`.

### stdinRawMode

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

Set `stdin` to [act as a raw device](http://nodejs.org/api/tty.html#tty_rs_setrawmode_mode).
Expand All @@ -236,24 +236,24 @@ Lets you override the default callback with your own.

### 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/).
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`

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:
Specify some options to be passed to the [.exec()](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback) method:

- `cwd` String *Current working directory of the child process*
- `cwd` string *Current working directory of the child process*
- `env` Object *Environment key-value pairs*
- `setsid` Boolean
- `encoding` String *(Default: 'utf8')*
- `timeout` Number *(Default: 0)*
- `maxBuffer` Number *(Default: 200\*1024)*
- `killSignal` String *(Default: 'SIGTERM')*
- `setsid` boolean
- `encoding` string *(Default: `'utf8'`)*
- `timeout` number *(Default: `0`)*
- `maxBuffer` number *(Default: `200 * 1024`)*
- `killSignal` string *(Default: `'SIGTERM'`)*


## License
Expand Down
22 changes: 11 additions & 11 deletions tasks/shell.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
var exec = require('child_process').exec;
var chalk = require('chalk');
var npmRunPath = require('npm-run-path');
const exec = require('child_process').exec;
const chalk = require('chalk');
const npmRunPath = require('npm-run-path');

module.exports = function (grunt) {
module.exports = grunt => {
grunt.registerMultiTask('shell', 'Run shell commands', function () {
var cb = this.async();
var opts = this.options({
const cb = this.async();
const opts = this.options({
stdout: true,
stderr: true,
stdin: true,
Expand All @@ -18,7 +18,7 @@ module.exports = function (grunt) {
}
});

var cmd = typeof this.data === 'string' ? this.data : this.data.command;
let cmd = typeof this.data === 'string' ? this.data : this.data.command;

if (cmd === undefined) {
throw new Error('`command` required');
Expand All @@ -30,7 +30,7 @@ module.exports = function (grunt) {
opts.execOptions.env = npmRunPath.env({env: opts.execOptions.env || process.env});
}

var cp = exec(cmd, opts.execOptions, function (err, stdout, stderr) {
const cp = exec(cmd, opts.execOptions, (err, stdout, stderr) => {
if (typeof opts.callback === 'function') {
opts.callback.call(this, err, stdout, stderr, cb);
} else {
Expand All @@ -39,11 +39,11 @@ module.exports = function (grunt) {
}
cb();
}
}.bind(this));
});

var captureOutput = function (child, output) {
const captureOutput = (child, output) => {
if (grunt.option('color') === false) {
child.on('data', function (data) {
child.on('data', data => {
output.write(chalk.stripColor(data));
});
} else {
Expand Down

0 comments on commit 3b379e7

Please sign in to comment.