Reputation: 50
There is a parent folder (gulp module) which has some child folders (gulp modules too). I want to run the default gulp task of each child through the gulpfile of the parent.
My approach was to iterate through the folders by using gulp-folders
and run a gulp
through gulp-shell
by setting the current work directory to the corresponding child.
var tOptions = {};
[...]
gulp.task('setup-modules', folders('./', function(folder){
tOptions.cwd = folder;
gulp.start('setup-module');
return gulp.src('', {read: false});
}));
gulp.task('setup-module', shell.task([
'gulp'
], tOptions));
It seems that just one instance of the task setup-module
gets started. What do I need to change to get several instances (for each child folder) of the task running?
Upvotes: 1
Views: 527
Reputation: 19428
Instead of using gulp-shell
you can use gulp-chug
and pass a glob to gulp.src()
to access your child gulpfiles eliminating the need to iterate over each subdirectory. You can even specify which tasks you would like to run if you want to run any task(s) other than default
.
Additionally, gulp-chug
will do everything so there's no need to depend on more than just that one package accomplish what you're looking to do.
One of the examples from the gulp-chug
docs goes over almost the exact scenario you're discussing.
// This example was taken from the gulp-chug docs
var gulp = require( 'gulp' );
var chug = require( 'gulp-chug' );
gulp.task( 'default', function () {
// Find and run all gulpfiles under all subdirectories
gulp.src( './**/gulpfile.js' )
.pipe( chug() )
} );
Upvotes: 2