Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get task name inside task in gulp

Tags:

I'm using gulp-plumber + gulp-notify and want to put task name in gulp-notify as a title. following is the code i wrote, thanks in advance.

gulp.task('SOMETASK', function() {     return gulp.src(sourcePaths)         .pipe(plumber({errorHandler: notify.onError({             message: "<%= error.message %>",             title: "I WANT TO PUT TASK NAME HERE"         })}))         // omitted below  }); 
like image 454
toshitaphy Avatar asked Nov 27 '14 01:11

toshitaphy


People also ask

What is Gulp SRC?

src() # The gulp. src() function takes a glob (i.e. a string matching one or more files) or an array of globs and returns a stream that can be piped to plugins. Gulp uses node-glob to get the files from the glob or globs you specify.

How does gulp work?

Gulp purely uses the JavaScript code and helps to run front-end tasks and large-scale web applications. It builds system automated tasks like CSS and HTML minification, concatenating library files, and compiling the SASS files.


2 Answers

gulp.Gulp.prototype.__runTask = gulp.Gulp.prototype._runTask; gulp.Gulp.prototype._runTask = function(task) {   this.currentTask = task;   this.__runTask(task); }  gulp.task("someTask", function(){   console.log( this.currentTask.name ); } 
like image 134
Denis S Kryukov Avatar answered Oct 21 '22 17:10

Denis S Kryukov


gulp.task('SOMETASK',function() {     console.log('Task name:', this.seq.slice(-1)[0]) // Task name: SOMETASK }) 
like image 44
Alex0007 Avatar answered Oct 21 '22 17:10

Alex0007