node package manager

generate

Fast, composable, highly extendable project generator with a user-friendly and expressive API.

generate

Fast, composable, highly extendable project generator with a user-friendly and expressive API.

You might also be interested in verb.

(TOC generated by verb using markdown-toc)

Install globally with npm

$ npm install -g generate

Generate automates the creation of new GitHub projecs

Scaffolding

Generate or add files to existing projecs,

TODO:

  • cli: run by command line
  • install globally
  • look at bootstrap's docs

Generate is fast, highly pluggable, has a user-friendly CLI and a powerful and expressive API.

templates, or to add "scaffolding" by automating creation of new projects a scaffolding tool used to automate project creation. It will build an entire directory structure based on current environment and answers to some questions. The exact files and contents created depend on the template chosen along with the answers to the questions asked.

  • [x] Built on assemble-core, so all methods from base, assemble, and templates are exposed on generate's API.
  • [x] Supports gulp and assemble plugins
  • [x] Runs local or globally-installed generators
  • [x] Runs sub-generators using simple dot-notation. Supports any level of nesting!
  • [x] Runs gulp-style "tasks" and uses some of the same underlying libraries as gulp
  • [x] Generators can extend and use other generators
  • [x] Generators, sub-generators and tasks can be run by command line, API, or both.
  • [x] Runs tasks from any generator or sub-generator, programmatically or via CLI
  • [x] Easy to add functionality and features to generate using via plugins
  • [x] Supports any node.js template engine, including consolidate
  • [x] First class support for template collections, including pagination, sorting, groups, and more.
  • [x] Supports middleware that can be run on specific files or template collections, at specific points during the build cycle, such as onLoad, preRender, postRender, etc.

Generate is also well-tested, with close to 1200 unit tests.

If you're familiar with node.js and ready to get started,

When used by command line, generate must first be [installed globally][], and then run with gen command.

When used by command line, generate must first be [installed globally][], and then run with gen command.

var Generate = require('generate');
var generator = new Generate();
 
generator.register('one', function(app) {
  app.task('default', function(cb) {
    // do stuff 
    cb();
  });
});
 
generator.register('two', function(app) {
  app.task('default', function(cb) {
    // do stuff 
    cb();
  });
 
  app.task('foo', function(cb) {
    // do stuff 
    cb();
  });
 
  app.task('bar', function(cb) {
    // do stuff 
    cb();
  });
 
  // register another generator as a sub-generator 
  app.register('one');
 
  // register a custom sub-generator 
  app.register('qux', function(qux) {
    app.task('default', function(cb) {
      // do stuff 
      cb();
    });
  });
});
 
// run the `default` task on generator `one` 
generator.generate('one', function(err) {
  if (err) throw err;
});
 
// run the `bar` task on generator `two` 
generator.generate('two', 'bar', function(err) {
  if (err) throw err;
});
 
// run the `one` sub-generator in generator "two" 
// (sub-generators can be infinitely nested!) 
generator.generate('two.one', function(err) {
  if (err) throw err;
});

1. generator.js

Create a generator.js file, and add the following code:

module.exports = function(app) {
  app.task('default', function(cb) {
    console.log('task > default');
    cb();
  });
 
  app.task('foo', function(cb) {
    console.log('task > foo');
    cb();
  });
};

2. Run gen

In the command line run:

  • gen to execute the default task
  • gen foo to execute the foo task

Generate

Create an instance of Generate with the given options

Params

  • options {Object}: Settings to initialize with.

Example

var Generate = require('generate');
var generate = new Generate();

help

Display --help.

Example

$ gen defaults:help

dest

Prompt the user for the dest directory to use for generated files. This is called by the new task.

Example

$ gen defaults:dest

new

Add a generator.js file to argv.dest or user cwd.

Example

$ gen defaults.new

new

Add a generator.js file to argv.dest or user cwd.

Example

$ gen defaults:new

new

Render a --src file to --dest directory. The user's working directory is used if a --dest is not defined.

Example

$ gen defaults:new

.ask

Async helper that prompts the user and populates a template with the answer.

Params

  • app {Object}
  • returns {Function}: Returns the helper function

Example

<%= ask('author.name') %>

You might also be interested in these projects:

update: Easily keep anything in your project up-to-date by installing the updaters you want to use… more | homepage

  • assemble: Assemble is a powerful, extendable and easy to use static site generator for node.js. Used… more | homepage
  • base: base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… more | homepage
  • verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Generate readme and API documentation with verb:

$ npm install verb && npm run docs

Or, if verb is installed globally:

$ verb

Install dev dependencies:

$ npm install -d && npm test

Jon Schlinkert

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb, v0.9.0, on May 09, 2016.