From 08119096bc899f0c37781f5353d6075e483943ed Mon Sep 17 00:00:00 2001 From: Sun Zheng'an Date: Thu, 23 Feb 2017 00:28:48 +0800 Subject: [PATCH] Rearrange options --- README.md | 54 +++++++++++++++++++++---------------------- index.js | 6 ++--- test/index.js | 64 +++++++++++++++++++++++++-------------------------- 3 files changed, 61 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index 328964e..3f6c71e 100644 --- a/README.md +++ b/README.md @@ -73,64 +73,62 @@ type: `Array` or `String` A command can be a [template][] which can be interpolated by some [file][] info (e.g. `file.path`). -[template]: http://lodash.com/docs#template -[file]: https://github.com/wearefractal/vinyl +#### options.cwd -#### options.verbose +type: `String` -type: `Boolean` +default: [`process.cwd()`](http://nodejs.org/api/process.html#process_process_cwd) -default: `false` +Sets the current working directory for the command. This can be a [template][] which can be interpolated by some [file][] info (e.g. `file.path`). -Set to `true` to print the command(s) to stdout as they are executed +#### options.env -#### options.errorMessage +type: `Object` -type: `String` +By default, all the commands will be executed in an environment with all the variables in [`process.env`](http://nodejs.org/api/process.html#process_process_env) and `PATH` prepended by `./node_modules/.bin` (allowing you to run executables in your Node's dependencies). -default: ``Command `<%= command %>` failed with exit code <%= error.code %>`` +You can override any environment variables with this option. -You can add a custom error message for when the command fails. -This can be a [template][] which can be interpolated with the current `command`, some [file][] info (e.g. `file.path`) and some error info (e.g. `error.code`). +For example, setting it to `{PATH: process.env.PATH}` will reset the `PATH` if the default one brings your some troubles. -#### options.ignoreErrors +#### options.quiet type: `Boolean` default: `false` -By default, it will emit an `error` event when the command finishes unsuccessfully. +By default, it will print the command output. -#### options.quiet +#### options.verbose type: `Boolean` default: `false` -By default, it will print the command output. +Set to `true` to print the command(s) to stdout as they are executed -#### options.cwd +#### options.ignoreErrors -type: `String` +type: `Boolean` -default: [`process.cwd()`](http://nodejs.org/api/process.html#process_process_cwd) +default: `false` -Sets the current working directory for the command. This can be a [template][] which can be interpolated by some [file][] info (e.g. `file.path`). +By default, it will emit an `error` event when the command finishes unsuccessfully. -[template]: http://lodash.com/docs#template +#### options.errorMessage -#### options.templateData +type: `String` -type: `Object` +default: ``Command `<%= command %>` failed with exit code <%= error.code %>`` -The data that can be accessed in template. +You can add a custom error message for when the command fails. +This can be a [template][] which can be interpolated with the current `command`, some [file][] info (e.g. `file.path`) and some error info (e.g. `error.code`). -#### options.env +#### options.templateData type: `Object` -By default, all the commands will be executed in an environment with all the variables in [`process.env`](http://nodejs.org/api/process.html#process_process_env) and `PATH` prepended by `./node_modules/.bin` (allowing you to run executables in your Node's dependencies). - -You can override any environment variables with this option. +The data that can be accessed in [template][]. -For example, setting it to `{PATH: process.env.PATH}` will reset the `PATH` if the default one brings your some troubles. +[template]: http://lodash.com/docs#template +[file]: https://github.com/wearefractal/vinyl diff --git a/index.js b/index.js index e4892fc..3bb3718 100644 --- a/index.js +++ b/index.js @@ -21,11 +21,11 @@ function normalizeCommands (commands) { function normalizeOptions (options) { options = _.extend({ + cwd: process.cwd(), + quiet: false, verbose: false, ignoreErrors: false, - errorMessage: 'Command `<%= command %>` failed with exit code <%= error.code %>', - quiet: false, - cwd: process.cwd() + errorMessage: 'Command `<%= command %>` failed with exit code <%= error.code %>' }, options) var pathToBin = path.join(process.cwd(), 'node_modules', '.bin') diff --git a/test/index.js b/test/index.js index abc9b2c..d85be78 100644 --- a/test/index.js +++ b/test/index.js @@ -69,6 +69,38 @@ describe('gulp-shell(commands, options)', function () { }) describe('options', function () { + describe('cwd', function () { + it('sets the current working directory when `cwd` is a string', function (done) { + var stream = shell([ + 'test $PWD = ' + join(__dirname, '../..') + ], {cwd: '..'}) + + expectToBeOk(stream, done) + + stream.write(fakeFile) + }) + + it('uses the process current working directory when `cwd` is not passed', function (done) { + var stream = shell([ + 'test $PWD = ' + join(__dirname, '..') + ]) + + expectToBeOk(stream, done) + + stream.write(fakeFile) + }) + }) + + describe('quiet', function () { + it("won't output anything when `quiet` == true", function (done) { + var stream = shell(['echo cannot see me!'], {quiet: true}) + + expectToBeOk(stream, done) + + stream.write(fakeFile) + }) + }) + describe('ignoreErrors', function () { it('emits error by default', function (done) { var stream = shell(['false']) @@ -95,16 +127,6 @@ describe('gulp-shell(commands, options)', function () { }) }) - describe('quiet', function () { - it("won't output anything when `quiet` == true", function (done) { - var stream = shell(['echo cannot see me!'], {quiet: true}) - - expectToBeOk(stream, done) - - stream.write(fakeFile) - }) - }) - describe('errorMessage', function () { it('allows for custom messages', function (done) { var errorMessage = 'foo' @@ -131,27 +153,5 @@ describe('gulp-shell(commands, options)', function () { stream.write(fakeFile) }) }) - - describe('cwd', function () { - it('sets the current working directory when `cwd` is a string', function (done) { - var stream = shell([ - 'test $PWD = ' + join(__dirname, '../..') - ], {cwd: '..'}) - - expectToBeOk(stream, done) - - stream.write(fakeFile) - }) - - it('uses the process current working directory when `cwd` is not passed', function (done) { - var stream = shell([ - 'test $PWD = ' + join(__dirname, '..') - ]) - - expectToBeOk(stream, done) - - stream.write(fakeFile) - }) - }) }) })