{%= include("what-is-generate") %}
This generator can be installed as a dependency and registered with the .use
method in your own generator.
Install
{%= include("install-npm") %}
Example usage
In your own generator{generators.md}:
module.exports = function(app) {
app.use(require('{%= name %}'));
};
Once registered, {%= name %} does two things:
- middleware: Adds a middleware for getting dependencies to install
- prompt: Adds a task for prompting the user to install the detected dependencies
Adds a .postWrite
middleware{middleware.md}, which runs after a file is written to the file system to see if an install
object was defined in yaml front-matter{front-matter.md}).
Example
This example shows a basic gulpfile.js
template with front-matter that defines gulp
as a dev dependency.
---
install:
devDependencies: ['gulp']
---
var gulp = require('gulp');
gulp.task('default', function(cb) {
// do task stuff
cb();
});
If the install
object exists, the middleware will extract the dependencies
and devDependencies
, filtering out any deps that are already installed and listed in package.json
.
This also works:
---
install: ['gulp']
---
var gulp = require('gulp');
gulp.task('default', function(cb) {
// do task stuff
cb();
});
Which is normalize to {devDependencies: ['gulp']}
.
The second thing this generator adds is an optional task for prompting the user.
Example usage
Run after other tasks are finished:
app.use(require('{%= name %}'));
app.task('generate-stuff', function(cb) {
cb();
});
app.generate(['generate-stuff', 'install'], function(err) {
if (err) return console.log(err);
});
This task is optional, since the user can also install this generator globally and run is directly.
Example
If your generate is named foo
, the user can do this:
gen foo install
{%= apidocs('index.js') %}
Visit Generate's task documentation{tasks.md}.