gulp-shell
Advanced tools
Comparing version 0.1.0 to 0.2.0
33
index.js
var _ = require('lodash') | ||
var async = require('async') | ||
var cp = require('child_process') | ||
@@ -10,3 +9,3 @@ var gutil = require('gulp-util') | ||
function shell(commands, options) { | ||
function shell(command, options) { | ||
if (!options) options = {} | ||
@@ -22,29 +21,23 @@ var ignoreErrors = !!options.ignoreErrors | ||
return through.obj(function (file, _, done) { | ||
var self = this | ||
command = gutil.template(command, {file: file}) | ||
async.eachSeries(commands, function (command, done) { | ||
command = gutil.template(command, {file: file}) | ||
cp.exec(command, {env: env}, function (error, stdout, stderr) { | ||
if (!quiet) { | ||
if (stderr) gutil.log(stderr.trim()) | ||
if (stdout) gutil.log(stdout.trim()) | ||
} | ||
cp.exec(command, {env: env}, function (error, stdout, stderr) { | ||
if (!quiet) { | ||
if (stderr) gutil.log(stderr.trim()) | ||
if (stdout) gutil.log(stdout.trim()) | ||
} | ||
done(ignoreErrors ? null : error) | ||
}) | ||
}, function (error) { | ||
if (error) { | ||
self.emit('error', new gutil.PluginError(PLUGIN_NAME, error)) | ||
if (error && !ignoreErrors) { | ||
this.emit('error', new gutil.PluginError(PLUGIN_NAME, error)) | ||
} else { | ||
self.push(file) | ||
this.push(file) | ||
} | ||
done() | ||
}) | ||
}.bind(this)) | ||
}) | ||
} | ||
shell.task = function (commands, options) { | ||
shell.task = function (command, options) { | ||
return function () { | ||
var stream = shell(commands, options) | ||
var stream = shell(command, options) | ||
@@ -51,0 +44,0 @@ stream.write(new gutil.File()) |
{ | ||
"name": "gulp-shell", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A handy command line interface for gulp", | ||
@@ -8,2 +8,3 @@ "main": "index.js", | ||
"test": "mocha -R spec -r should && jshint index.js test/*.js", | ||
"watch": "mocha -R spec -r should -w", | ||
"coverage": "istanbul cover _mocha --report lcovonly -- -R spec", | ||
@@ -29,15 +30,14 @@ "coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage" | ||
"devDependencies": { | ||
"coveralls": "~2.8.0", | ||
"istanbul": "~0.2.4", | ||
"jshint": "~2.4.4", | ||
"mocha": "~1.17.1", | ||
"should": "~3.1.2", | ||
"jshint": "~2.4.4", | ||
"istanbul": "~0.2.4", | ||
"coveralls": "~2.8.0", | ||
"mocha-lcov-reporter": "0.0.1" | ||
"mocha-lcov-reporter": "0.0.1", | ||
"should": "~3.1.2" | ||
}, | ||
"dependencies": { | ||
"gulp-util": "~2.2.14", | ||
"through2": "~0.4.1", | ||
"lodash": "~2.4.1", | ||
"async": "~0.2.10" | ||
"through2": "~0.4.1" | ||
} | ||
} |
@@ -33,10 +33,7 @@ # gulp-shell | ||
return gulp.src('*.js') | ||
.pipe(shell([ | ||
'echo <%= file.path %>', | ||
'ls -l <%= file.path %>' | ||
])) | ||
.pipe(shell('echo <%= file.path %>')) | ||
}) | ||
``` | ||
If you just want to execute a bunch of commands only once, starting the stream with `gulp.src('')` should do the trick. | ||
If you just want to execute the command only once, starting the stream with `gulp.src('')` should do the trick. | ||
@@ -46,17 +43,23 @@ Or you can use this shorthand: | ||
```js | ||
gulp.task('shorthand', shell.task([ | ||
gulp.task('shorthand', shell.task('echo hello')) | ||
``` | ||
To run multiple commands, join them by `&&` or `;`: | ||
```js | ||
gulp.task('multiple', shell.task([ | ||
'echo hello', | ||
'echo world' | ||
])) | ||
].join(' && '))) | ||
``` | ||
Note: All the command will be executed in an environment where `PATH` prepended by `./node_modules/.bin`, allowing you to run executables in your dependencies. | ||
Note: The command will be executed in an environment where `PATH` prepended by `./node_modules/.bin`, allowing you to run executables in your Node's dependencies. | ||
## API | ||
### shell(commands, options) or shell.task(commands, options) | ||
### shell(command, options) or shell.task(command, options) | ||
#### template | ||
A command can be a [template][] in context of the current [file][]. | ||
A command can be a [template][] which can be interpolated by some [file][] info (e.g. `file.path`). | ||
@@ -69,2 +72,3 @@ [template]: http://lodash.com/docs#template | ||
type: `Boolean` | ||
default: `false` | ||
@@ -77,4 +81,5 @@ | ||
type: `Boolean` | ||
default: `false` | ||
By default, it will print the command output. |
@@ -7,3 +7,3 @@ var gutil = require('gulp-util') | ||
describe('gulp-shell(commands, options)', function () { | ||
describe('gulp-shell(command, options)', function () { | ||
var fakeFile = new gutil.File({ | ||
@@ -16,3 +16,3 @@ cwd: __dirname, | ||
it('should pass file through', function (done) { | ||
var stream = shell(['true']) | ||
var stream = shell('true') | ||
@@ -28,3 +28,3 @@ stream.on('data', function (file) { | ||
it('should execute command after interpolation', function (done) { | ||
var stream = shell(['echo <%= file.path %>']) | ||
var stream = shell('echo <%= file.path %>') | ||
@@ -42,3 +42,3 @@ var write = process.stdout.write | ||
it('should prepend `./node_modules/.bin` to `PATH`', function (done) { | ||
var stream = shell(['echo $PATH']) | ||
var stream = shell('echo $PATH') | ||
@@ -55,5 +55,5 @@ var write = process.stdout.write | ||
describe('.task(commands, options)', function () { | ||
describe('.task(command, options)', function () { | ||
it('should return a function which returns a stream', function (done) { | ||
var task = shell.task(['true']) | ||
var task = shell.task('true') | ||
should(task).be.type('function') | ||
@@ -71,3 +71,3 @@ | ||
it('should emit error by default', function (done) { | ||
var stream = shell(['false']) | ||
var stream = shell('false') | ||
@@ -82,3 +82,3 @@ stream.on('error', function () { | ||
it('should not emit error when `ignoreErrors` == true', function (done) { | ||
var stream = shell(['false'], {ignoreErrors: true}) | ||
var stream = shell('false', {ignoreErrors: true}) | ||
@@ -99,3 +99,3 @@ stream.on('error', function () { | ||
it('should not output anything when `quiet` == true', function (done) { | ||
var stream = shell(['echo cannot see me!'], {quiet: true}) | ||
var stream = shell('echo cannot see me!', {quiet: true}) | ||
@@ -102,0 +102,0 @@ var write = process.stdout.write |
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
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
3
82
8585
124
- Removedasync@~0.2.10
- Removedasync@0.2.10(transitive)