Console.log in stdout on gulp events

I want to enter stdout (configuration environment) when the gulp task is running or running.

Something like that:

gulp.task('scripts', function () { var enviroment = argv.env || 'development'; var config = gulp.src('config/' + enviroment + '.json') .pipe(ngConstant({name: 'app.config'})); var scripts = gulp.src('js/*'); return es.merge(config, scripts) .pipe(concat('app.js')) .pipe(gulp.dest('app/dist')) .on('success', function() { console.log('Configured environment: ' + environment); }); }); 

I'm not sure which event I should respond to or where to find a list of them. Any pointers? Thank you very much.

+59
javascript gulp
Jan 15 '15 at 23:50
source share
2 answers

Gulp gulp-util provides logging and was created by the Gulp team.

 var gutil = require('gulp-util'); gutil.log('Hello world!'); 



To add a log, Gulp API documentation let us know .src returns:

Returns a stream of vinyl files that can be connected to plugins.

Node.js Stream documentation contains a list of events. Let's compare an example here:

 gulp.task('default', function() { return gulp.src('main.scss') .pipe(sass({ style: 'expanded' })) .on('end', function(){ gutil.log('Almost there...'); }) .pipe(minifycss()) .on('end', function(){ gutil.log('Done!'); }); }); 

Note. The end event can be triggered before the plugin completes (and sends all its own output), because the event is fired when "all data has been flushed to the base system."

+121
Jan 16
source share

To build on Jacob Budin's answer, I recently tried this and found it useful.

 var gulp = require("gulp"); var util = require("gulp-util"); var changed = require("gulp-changed"); gulp.task("copyIfChanged", function() { var nSrc=0, nDes=0, dest="build/js"; gulp.src("app/**/*.js") .on("data", function() { nSrc+=1;}) .pipe(changed(dest)) //filter out src files not newer than dest .pipe(gulp.dest(dest)) .on("data", function() { nDes+=1;}) .on("finish", function() { util.log("Results for app/**/*.js"); util.log("# src files: ", nSrc); util.log("# dest files:", nDes); }); } 
+9
Oct 08 '15 at 20:01
source share



All Articles