Skip to content

Latest commit

 

History

History
100 lines (67 loc) · 2.17 KB

.verb.md

File metadata and controls

100 lines (67 loc) · 2.17 KB

What is "Generate"?

{%= include("what-is-generate") %}

How does {%= name %} work?

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

1. middleware

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']}.

2. prompt

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

Tasks

{%= apidocs('index.js') %}

Visit Generate's task documentation{tasks.md}.