Skip to content

Commit

Permalink
Rearrange options
Browse files Browse the repository at this point in the history
  • Loading branch information
sun-zheng-an committed Feb 22, 2017
1 parent dcb16ea commit 0811909
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 63 deletions.
54 changes: 26 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
64 changes: 32 additions & 32 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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'
Expand All @@ -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)
})
})
})
})

0 comments on commit 0811909

Please sign in to comment.