From 3b379e718abaa7757b449dde295b094205385aae Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 25 Sep 2016 14:22:35 +0700 Subject: [PATCH] [BREAKING] ES2015ify and require Node.js 4 --- .gitattributes | 1 + gruntfile.js | 10 +++++----- package.json | 8 +++++--- readme.md | 30 +++++++++++++++--------------- tasks/shell.js | 22 +++++++++++----------- 5 files changed, 37 insertions(+), 34 deletions(-) diff --git a/.gitattributes b/.gitattributes index 176a458..391f0a4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ * text=auto +*.js text eol=lf diff --git a/gruntfile.js b/gruntfile.js index 26dad0b..805d5cc 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -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(); } @@ -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: { diff --git a/package.json b/package.json index 32a00cc..85a7f83 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "sindresorhus.com" }, "engines": { - "node": ">=0.10.0" + "node": ">=4" }, "scripts": { "test": "xo && grunt" @@ -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", @@ -41,5 +40,8 @@ }, "peerDependencies": { "grunt": ">=0.4.0" + }, + "xo": { + "esnext": true } } diff --git a/readme.md b/readme.md index 7565b03..7999ea6 100644 --- a/readme.md +++ b/readme.md @@ -183,7 +183,7 @@ grunt.initConfig({ ### command *Required*
-Type: `String` `Function` +Type: `string` `Function` Command to run or a function which returns the command. Supports underscore templates. @@ -193,35 +193,35 @@ Command to run or a function which returns the command. Supports underscore temp ### stdout -Type: `Boolean`
+Type: `boolean`
Default: `true` Show stdout in the terminal. ### stderr -Type: `Boolean`
+Type: `boolean`
Default: `true` Show stderr in the terminal. ### stdin -Type: `Boolean`
+Type: `boolean`
Default: `true` Forward the terminal's stdin to the command. ### failOnError -Type: `Boolean`
+Type: `boolean`
Default: `true` Fail task if it encounters an error. Doesn't apply if you specify a `callback`. ### stdinRawMode -Type: `Boolean`
+Type: `boolean`
Default: `false` Set `stdin` to [act as a raw device](http://nodejs.org/api/tty.html#tty_rs_setrawmode_mode). @@ -236,24 +236,24 @@ Lets you override the default callback with your own. ### preferLocal -Type: `Boolean`
+Type: `boolean`
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 diff --git a/tasks/shell.js b/tasks/shell.js index cc2c222..35a8425 100644 --- a/tasks/shell.js +++ b/tasks/shell.js @@ -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, @@ -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'); @@ -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 { @@ -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 {