How to run bash commands in gulp?

I want to add some bash commands at the end of the gulp.watch function to speed up the development speed. So I wonder if this is possible. Thank!

+48
bash gulp
Jan 15 '14 at 3:52
source share
3 answers

Use https://www.npmjs.org/package/gulp-shell .

Convenient command line interface for gulp

+45
Apr 17 '14 at 7:09
source share

I would go with:

 var spawn = require('child_process').spawn; var gutil = require('gulp-util'); gulp.task('default', function(){ gulp.watch('*.js', function(e) { // Do run some gulp tasks here // ... // Finally execute your script below - here "ls -lA" var child = spawn("ls", ["-lA"], {cwd: process.cwd()}), stdout = '', stderr = ''; child.stdout.setEncoding('utf8'); child.stdout.on('data', function (data) { stdout += data; gutil.log(data); }); child.stderr.setEncoding('utf8'); child.stderr.on('data', function (data) { stderr += data; gutil.log(gutil.colors.red(data)); gutil.beep(); }); child.on('close', function(code) { gutil.log("Done with exit code", code); gutil.log("You access complete stdout and stderr from here"); // stdout, stderr }); }); }); 

Nothing really "gulp" here - basically using the child processes http://nodejs.org/api/child_process.html and faking the result in gulp -util log

+73
Jan 15 '14 at 9:25
source share

The simplest solution is as simple as:

 var child = require('child_process'); var gulp = require('gulp'); gulp.task('launch-ls',function(done) { child.spawn('ls', [ '-la'], { stdio: 'inherit' }); }); 

It does not use node and gulp streams, but it will do the job.

0
Jun 07 '17 at 9:23
source share



All Articles