vlasterx
vlasterx

Reputation: 3856

Gulp and git submodules

Is it possible to use gulp with git sub-modules that have their own gulp settings and npm modules?

This is the idea:

/ Project
|- Modules
|-- Grid
|--- some files and subfolders
|--- gulpfile.js
|-- Typography
|--- some files and subfolders
|--- gulpfile.js
|
| gulpfile.js

Modules are folder where I would like to keep unknown number of git sub-modules. Each of those git sub-modules would have their own gulpfile.js and NPM modules.

Question is - When I start gulp process from the root folder, is it possible for main gulpfile.js to start all other gulpfile.js files from included git sub-modules?

Upvotes: 0

Views: 633

Answers (1)

Sven Schoenung
Sven Schoenung

Reputation: 30564

There's gulp-hub which let's you run gulpfiles in subfolders. When you run gulp foo in your root folder it will run the foo task for each submodule.

Since you need to pass it an array with the location of each submodule's gulpfile it's easiest to use the glob package in order to automatically find what submodules there are and which of them have gulpfiles (instead of hardcoding all of that).

This is what your Project/gulpfile.js would look like:

var glob = require('glob');
var hub = require('gulp-hub');

hub(glob.sync('./Modules/*/[Gg]ulpfile.js'));

Now when you run gulp in your root folder it will run the default task for each submodule:

sven@hal9000:~/Project$ gulp 
[08:45:12] Loading Modules/Grid/gulpfile.js
[08:45:12] Loading Modules/Typography/Gulpfile.js
[08:45:12] Using gulpfile ~/Project/gulpfile.js
[08:45:12] Starting 'default'...
[08:45:12] Starting 'Modules/Grid/gulpfile.js-default'...
[08:45:12] Finished 'Modules/Grid/gulpfile.js-default' after 129 μs
[08:45:12] Starting 'Modules/Typography/Gulpfile.js-default'...
[08:45:12] Finished 'Modules/Typography/Gulpfile.js-default' after 102 μs
[08:45:12] Finished 'default' after 2.03 ms

Upvotes: 1

Related Questions