question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get a list of gulp tasks from another module

See original GitHub issue

Hi @contra

Is there a way to retrieve the list of gulp tasks from an external module ?

for eg:

//foo.js
var gulp = require('gulp');

module.exports = function(){  
 var gulpTasks = Object.keys(gulp.tasks);
 console.log(gulpTasks);
 // some other stuff
}

//bar.js
require('foo')();

$ > node bar.js
//expect a list of gulp tasks, but getting an empty list

I am getting it to work when I add foo.js as a plugin inside my gulpfile and create a new task.

//gulpfile.js
var foo = require('foo');
gulp.task('fooTask',foo);

$> gulp fooTask
//outputs a list of tasks in gulpfile

The only thing I need gulp for inside foo.js is to get a list of gulp tasks all other stuff inside foo.js is no way related to gulp. Just not sure if foo.js needs to be a gulp plugin only for this purpose.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
niki4810commented, May 1, 2014

@contra Nevermind, I figured it out:

// inside gulpfile.js add
module.exports = function(){
  return gulp;
}

//inside your module 
tasks = Object.keys(require('./gulpfile')().tasks);

had to use tasks = Object.keys(require('./gulpfile')().tasks) instead of this tasks = Object.keys(require('./gulpfile'))

Thanks again for your tip 👍

0reactions
niki4810commented, May 5, 2014

@contra with your help on this issue, I was able to finish a little pet project of mine : https://github.com/niki4810/gulp-devtools , wanted to share it with you. Thanks again for you help 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to import all tasks from another gulp file.js - Stack Overflow
It is possible to have one main gulpfile.js from which to call tasks from other gulp files.js using the require-dir module.
Read more >
Exporting tasks from gulpfile.js - Vjeko.com
This is a very simple way of exporting tasks. You call gulp.task, pass a reference to a function, and there you go. When...
Read more >
Building multi module projects with Gulp - Sparkbit
Build definition of each module is now short and clean, you can see what tasks are run be just listing gulp-tasks directory.
Read more >
Creating Tasks | gulp.js
Each gulp task is an asynchronous JavaScript function - a function that accepts an error-first callback or returns a stream, promise, event emitter, ......
Read more >
How to Consume and Run Gulp Tasks in Other Files from a ...
The Gulp Part · Create a convenient and descriptive list of the sub folders this "hub" will be targeting. · A config object...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found