Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run bash commands in gulp?

Tags:

bash

gulp

I want to add some bash commands at the end of gulp.watch function to accelerate my development speed. So, I am wondering if it is possible. Thanks!

like image 743
houhr Avatar asked Jan 15 '14 03:01

houhr


2 Answers

I would go with:

var spawn = require('child_process').spawn; var fancyLog = require('fancy-log'); var beeper = require('beeper');  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;             fancyLog(data);         });          child.stderr.setEncoding('utf8');         child.stderr.on('data', function (data) {             stderr += data;             fancyLog.error(data));             beeper();         });          child.on('close', function(code) {             fancyLog("Done with exit code", code);             fancyLog("You access complete stdout and stderr from here"); // stdout, stderr         });       }); }); 

Nothing really "gulp" in here - mainly using child processes http://nodejs.org/api/child_process.html and spoofing the result into fancy-log

like image 129
Mangled Deutz Avatar answered Oct 24 '22 17:10

Mangled Deutz


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

A handy command line interface for gulp

like image 35
Erik Avatar answered Oct 24 '22 18:10

Erik