node package manager



Get task list of gulp file in node.js.


We all know that gulp --tasks or gulp -T can list all tasks of the gulpfile, but they consume too much time than I thought. Otherwise, I want to get the list in my node program, that means I have to wait, catch, process raw data from stdout. It's still another way to get the list in node, but … not elegant!

So I write a simple parser with esprima to achieve this goal, and found it is really faster than previous ways.


npm install --save gulp-tasklist

How to use

Here is the official demo code on Gulp website:

var gulp = require('gulp');
var pug = require('gulp-pug');
var less = require('gulp-less');
var minifyCSS = require('gulp-csso');
gulp.task('html', function(){
  return gulp.src('client/templates/*.pug')
gulp.task('css', function(){
  return gulp.src('client/templates/*.less')
gulp.task('default', [ 'html', 'css' ]);

Just require gulp-tasklist package and call getList() method:

const TaskList = require('gulp-tasklist');
const path = require('path');
let filePath = path.join(__dirname, 'gulpfile.js');
// Just pass the gulpfile path and get the list object 
let res = TaskList.getList(filePath);
if (res.err) throw res.err;
else console.log(;
// As result stdout prints: 
// { html: { deps: [] }, 
//   css: { deps: [] }, 
//   default: { deps: [ 'html', 'css' ] } }