How to console.log to stdout on gulp events?

0 votes

I want to log to stdout (the config environment) when a gulp task is running or has run.

Something like this:

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 am not sure what event I should be responding to or where to find a list of these. Any pointers?

Oct 11 in Node-js by kartik
• 35,820 points
113 views

1 answer to this question.

0 votes

Hello @kartik,

Use this:

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);
    });
}

Hope it helps!!

Thank you!!

answered Oct 11 by Niroj
• 78,120 points

Related Questions In Node-js

0 votes
1 answer

How to get the available tasks list in gulp?

Hello @kartik,  I got it use the gulp --tasks in ...READ MORE

answered Oct 13 in Node-js by Niroj
• 78,120 points
24 views
0 votes
1 answer

How to save a stream into multiple destinations with Gulp.js?

Hello @kartik, Currently you have to use two ...READ MORE

answered Oct 14 in Node-js by Niroj
• 78,120 points
40 views
0 votes
1 answer

How to run node.js app forever when console is closed?

Hello @kartik, You may also want to consider ...READ MORE

answered Oct 14 in Node-js by Niroj
• 78,120 points
86 views
0 votes
1 answer

How to get Node.JS Express to listen only on localhost?

Hello @kartik, This is a bug in hive-go that only ...READ MORE

answered Oct 16 in Node-js by Niroj
• 78,120 points
123 views
0 votes
1 answer

jQuery AJAX fires error callback on window unload - how do I filter out unload and only catch real errors?

Hello, In the error callback or $.ajax you have three ...READ MORE

answered Apr 27 in Java-Script by Niroj
• 78,120 points
448 views
0 votes
1 answer

How do I pass command line arguments to a Node.js program?

Hello @kartik, If your script is called myScript.js ...READ MORE

answered May 5 in Java-Script by Niroj
• 78,120 points
697 views
0 votes
1 answer

Error:Issue when trying to use IN() in wordpress database

Hello @kartik, Try this code : // Create an ...READ MORE

answered May 8 in PHP by Niroj
• 78,120 points
91 views
+2 votes
1 answer

How do I debug Node.js applications?

Hello @kartik, Use node-inspector  from any browser supporting WebSocket. Breakpoints, ...READ MORE

answered Jul 8 in Node-js by Niroj
• 78,120 points
87 views
0 votes
1 answer

How to get GET (query string) variables in Express.js on Node.js?

Hello @kartik, Since you've mentioned Express.js in your ...READ MORE

answered Jul 8 in Node-js by Niroj
• 78,120 points
416 views
0 votes
1 answer

How to run Gulp tasks sequentially one after the other?

Hello @kartik, By default, gulp runs tasks simultaneously, ...READ MORE

answered Jul 12 in Node-js by Niroj
• 78,120 points
65 views