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.

Invoking the Gulp tool programmatically

See original GitHub issue

I am trying to invoke Gulp within another Node.js script. Is there any non-hackish way to do this? e.g. by not manually requiring bin/gulp.js or setting up a new Liftoff({ ... }), or running the command in the shell as is done at the moment in this plugin I’m currently working on?

To be more general I’m asking if there’s an official way to run Gulp as a part of another tool, without the extra overhead of spawning a new child process. A meta-API, if you like.

I think this is somewhat related to issue #755, except that no gulpfile has been loaded yet.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:4
  • Comments:34 (10 by maintainers)

github_iconTop GitHub Comments

18reactions
yocontracommented, Jun 12, 2019

nah heres how you really do it

var gulp = require('gulp');
require('./gulpfile');

if (gulp.tasks.test) { 
    console.log('gulpfile contains task!');
    gulp.start('test');
}

a gulpfile is just a node script, so you can require it in like any other.

As they said though, .start will be gone in 4.0 and replaced with series and parallel

8reactions
stringparsercommented, Nov 14, 2014

Ok, vanilla gulp

var gulp = require('gulp');
process.nextTick(function(){
 var tasks = gulp.tasks;
 if( gulp.myTask ){ gulp.start('myTask'); }
});

in gulp@4.0 gulp.start will be removed in favor of gulp.series and gulp.parallel, which are really cool by the way. So beware of changing that in the future.

Using the plugin I wrote

var runtime = require('gulp-runtime');
process.nextTick(function(){ 
 runtime.input.write('myTask\n');
})

which is the same as you wrote in the shell the task and pressed enter. The repl is something more of a feature. It can work without stdin and stdout, but I have yet to document it better.

Anyhow the first option will serve you good if your aim is simpler.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run Gulp 4 task programmatically - node.js - Stack Overflow
Yes you can retrieve a task by calling gulp.task , but rather than calling it directly you can wrap it in a call...
Read more >
Run Gulp 4 tasks programmatically from NodeJS
I want to use the power of the Gulp functions like the series(), parallel(), src(), dest(), pipe(), the globbing, an the plugin model...
Read more >
Using Gulp — ASP.NET documentation
Gulp is a JavaScript-based streaming build toolkit that can be used for bundling and minification. Visual Studio automatically installs Gulp along with a...
Read more >
An Introduction to Gulp.js - SitePoint
This article, sponsored by New Relic, provides an introduction to the automated task runner, Gulp.js, and shows how it can be used to ......
Read more >
Learn How to Use Gulp - WebFX
In this tutorial, learn Gulp's most efficient tools on our site today! ... We can use this name in other Gulp tasks, or...
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