gulp-tasks-monorepo
Write once, apply to all
Tool for running gulp tasks against multiple packages
Motivation
Basic idea of the package is reusing gulp tasks for multiple projects that have similar build pipelines. Package iterates over a given folder with packages and run gulp tasks against each package. In its turn, each gulp task receives a current package metadata that contains some information about the package which can be extended via package initializers (they are covered below).
Usage
Quick start
Imagine, that we have a following project structure
packages/ common/ src/ package.json api/ src/ package.json gulpfile.js package.json
Both packages are written in ES6 and needed to be transpiled into ES5. Here is our task in gulp file:
var rimraf = ;var path = ;var gulp = ;var babel = ;var gutil = ;var MonorepoTasks = ; var repo = ; repo; repo;
As we can see, pretty much the same as with regular vanilla gulp, but with one exception - every task receives a package metadata with its name and location.
Sequential execution flow
Since the package executes all tasks in parallel, there is a way how to force it to run them sequentially.
var repo = ; repo; repo; repo;
It needs to put those tasks that are needed to be executed sequentially in a nested array.
Metadata
Of course, in real world, our build tasks are more complicated and we need to give some more information to these tasks in order to let them know how to handle each package more precisely .
In order to do that, we can create package.js
in a root directory of each package that should export one single function which accepts a package metadata:
module { pkgoptions'build.scripts.minify' true;};
The package will load this module and run initializer before running any tasks. After that, any task can get the information:
var gif = ;var uglify = ; repo;
Async metadata initializer
Metadata initializer also can be async:
var fs = ;var path = ; module { fs;};
Bonus
As a bonus, we can drastically minimize amount of code and organize it better.
We can use gulp-tasks-registrator
for loading external gulp tasks:
var gulp = ;var RegisterTasks = ;var MonorepoTasks = ;var loadPlugins = ; var $ = ; ;
// tasks/clean.js var path = ; module { return { $; };};
// tasks/build.js var path = ; module { { return $gulp ; } taskdependencies = 'clean'; return task;};
API
Monorepo(options)
options.dir
Type: string
.
Full path to a directory that contains packages.
options.file
Type: string
.
File name for initialization module.
Optional.
Default package.js
.
options.package
Type: string
| array<string>
.
Array of string or comma-separated string that represent a package(s) to run tasks against.
Optional.
options.gulp
Type: object
.
Alternative gulp instance.
Optional.
options.quiet
Type: boolean
.
Turns off logging.
Optional.
Default false
.