gulp-shell
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -8,5 +8,5 @@ var gulp = require('gulp') | ||
gulp.task('test', shell.task('mocha -R spec')) | ||
gulp.task('test', shell.task('mocha -c')) | ||
gulp.task('coverage', ['test'], shell.task('istanbul cover _mocha -- -R spec')) | ||
gulp.task('coverage', ['test'], shell.task('istanbul cover _mocha -- -c')) | ||
@@ -13,0 +13,0 @@ gulp.task('coveralls', ['coverage'], shell.task('cat coverage/lcov.info | coveralls')) |
107
index.js
@@ -10,3 +10,3 @@ var _ = require('lodash') | ||
function shell(commands, options) { | ||
function normalizeCommands(commands) { | ||
if (typeof commands === 'string') { | ||
@@ -20,3 +20,8 @@ commands = [commands] | ||
return commands | ||
} | ||
function normalizeOptions(options) { | ||
options = _.extend({ | ||
verbose: false, | ||
ignoreErrors: false, | ||
@@ -35,48 +40,63 @@ errorMessage: 'Command `<%= command %>` failed with exit code <%= error.code %>', | ||
var stream = through.obj(function (file, unused, done) { | ||
var self = this | ||
return options | ||
} | ||
async.eachSeries(commands, function (command, done) { | ||
var context = _.extend({file: file}, options.templateData) | ||
command = gutil.template(command, context) | ||
function runCommands(commands, options, file, done) { | ||
async.eachSeries(commands, function (command, done) { | ||
var context = _.extend({file: file}, options.templateData) | ||
command = gutil.template(command, context) | ||
var child = exec(command, { | ||
env: options.env, | ||
cwd: options.cwd, | ||
maxBuffer: options.maxBuffer, | ||
timeout: options.timeout | ||
}, function (error, stdout, stderr) { | ||
if (options.interactive) { | ||
process.stdin.unpipe(child.stdin) | ||
process.stdin.resume() | ||
process.stdin.pause() | ||
} | ||
if (options.verbose) { | ||
gutil.log(gutil.colors.cyan(command)) | ||
} | ||
if (error && !options.ignoreErrors) { | ||
error.stdout = stdout | ||
error.stderr = stderr | ||
var child = exec(command, { | ||
env: options.env, | ||
cwd: options.cwd, | ||
maxBuffer: options.maxBuffer, | ||
timeout: options.timeout | ||
}, function (error, stdout, stderr) { | ||
if (options.interactive) { | ||
process.stdin.unpipe(child.stdin) | ||
process.stdin.resume() | ||
process.stdin.pause() | ||
} | ||
var errorContext = _.extend({ | ||
command: command, | ||
file: file, | ||
error: error | ||
}, options.templateData) | ||
if (error && !options.ignoreErrors) { | ||
error.stdout = stdout | ||
error.stderr = stderr | ||
error.message = gutil.template(options.errorMessage, errorContext) | ||
} | ||
var errorContext = _.extend({ | ||
command: command, | ||
file: file, | ||
error: error | ||
}, options.templateData) | ||
done(options.ignoreErrors ? null : error) | ||
}) | ||
if (options.interactive) { | ||
process.stdin.resume() | ||
process.stdin.setEncoding('utf8') | ||
process.stdin.pipe(child.stdin) | ||
error.message = gutil.template(options.errorMessage, errorContext) | ||
} | ||
if (!options.quiet) { | ||
child.stdout.pipe(process.stdout) | ||
child.stderr.pipe(process.stderr) | ||
} | ||
}, function (error) { | ||
done(options.ignoreErrors ? null : error) | ||
}) | ||
if (options.interactive) { | ||
process.stdin.resume() | ||
process.stdin.setEncoding('utf8') | ||
process.stdin.pipe(child.stdin) | ||
} | ||
if (!options.quiet) { | ||
child.stdout.pipe(process.stdout) | ||
child.stderr.pipe(process.stderr) | ||
} | ||
}, done) | ||
} | ||
function shell(commands, options) { | ||
commands = normalizeCommands(commands) | ||
options = normalizeOptions(options) | ||
var stream = through.obj(function (file, unused, done) { | ||
var self = this | ||
runCommands(commands, options, file, function (error) { | ||
if (error) { | ||
@@ -100,9 +120,4 @@ self.emit('error', new gutil.PluginError({ | ||
shell.task = function (commands, options) { | ||
return function () { | ||
var stream = shell(commands, options) | ||
stream.write(new gutil.File()) | ||
stream.end() | ||
return stream | ||
return function (done) { | ||
runCommands(normalizeCommands(commands), normalizeOptions(options), null, done) | ||
} | ||
@@ -109,0 +124,0 @@ } |
{ | ||
"name": "gulp-shell", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "A handy command line interface for gulp", | ||
@@ -27,13 +27,13 @@ "main": "index.js", | ||
"devDependencies": { | ||
"chai": "~3.3.0", | ||
"coveralls": "~2.11.2", | ||
"eslint": "~1.6.0", | ||
"chai": "~3.4.0", | ||
"coveralls": "~2.11.4", | ||
"eslint": "~1.7.3", | ||
"gulp": "~3.9.0", | ||
"istanbul": "~0.3.14", | ||
"istanbul": "~0.4.0", | ||
"mocha": "~2.3.3", | ||
"mocha-lcov-reporter": "1.0.0" | ||
"mocha-lcov-reporter": "~1.0.0" | ||
}, | ||
"dependencies": { | ||
"async": "~1.4.2", | ||
"gulp-util": "~3.0.5", | ||
"async": "~1.5.0", | ||
"gulp-util": "~3.0.7", | ||
"lodash": "~3.10.1", | ||
@@ -40,0 +40,0 @@ "through2": "~2.0.0" |
@@ -48,3 +48,3 @@ # gulp-shell | ||
If you just want to execute a series of commands only once, starting the stream with `gulp.src('')` should do the trick. | ||
If you just want to execute a series of commands only once, ~~starting the stream with `gulp.src('')`~~ should do the trick. However, [this is an anti-pattern](https://github.com/sun-zheng-an/gulp-shell/issues/55), and **it won't work in `gulp 4.0`** . | ||
@@ -77,2 +77,10 @@ Or you can use this shorthand: | ||
#### options.verbose | ||
type: `Boolean` | ||
default: `false` | ||
Set to `true` to print the command(s) to stdout as they are executed | ||
#### options.errorMessage | ||
@@ -79,0 +87,0 @@ |
@@ -61,10 +61,9 @@ /*eslint-env mocha */ | ||
describe('.task(commands, options)', function () { | ||
it('returns a function which returns a stream', function (done) { | ||
var task = shell.task(['true']) | ||
it('returns a function which returns a callback', function (done) { | ||
var task = shell.task(['echo hello world']) | ||
expect(task).to.be.a('function') | ||
expectToOutput('hello world', done) | ||
var stream = task() | ||
stream.on('data', function () { | ||
done() | ||
}) | ||
task() | ||
}) | ||
@@ -71,0 +70,0 @@ }) |
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
14789
237
158
+ Addedasync@1.5.2(transitive)
- Removedasync@1.4.2(transitive)
Updatedasync@~1.5.0
Updatedgulp-util@~3.0.7