JSPM

  • Created
  • Published
  • Downloads 22037
  • Score
    100M100P100Q125602F
  • License MIT

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

Package Exports

  • generate

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (generate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

generate NPM version NPM downloads Build Status

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

You might also be interested in base.

TOC

(TOC generated by verb using markdown-toc)

Install

Install globally with npm

$ npm install -g generate

What is generate?

Generate is a new, open source developer framework for rapidly initializing and scaffolding out new code projects. Generate's offers a powerful and expressive API that makes it easy and enjoyable to author generators, and an intuitive CLI that helps you stay productive.

Example

This example shows two generators working together seamlessly.

Example of how to generate a gulpfile.js

Want to know more?

You can use generate from the command line, or as a node.js library as a part of your own application.

Continue on, and start generating!

CLI

Installing the CLI

To run generate from the command line, you'll need to install it globally first. You can do that now with the following command:

$ npm i -g generate

This adds the gen command to your system path, allowing it to be run from any directory.

You should now be able to use the gen command to execute code in a local generator.js file, or to execute globally installed generators by their aliases.

Quickstart

The following intro only skims the surface of what generate has to offer. For a more in-depth introduction, we highly recommend visiting the getting started guide.

Create a generator

Add a generator.js to the current working directory with the following code:

module.exports = function(app) {
  console.log('success!');
};

Run a generator

Enter the following command:

gen

If successful, you should see success! in the terminal.

Create a task

Now, add a task to your generator.

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

Now, in the command line, run:

$ gen
# then try
$ gen default

When a local generator.js exists, the gen command is aliased to automatically run the default task if one exists. But you can also run the task with gen default.

Run a task

Let's try adding more tasks to your generator:

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

  app.task('bar', function(cb) {
    console.log('bar > success!');
    cb();
  });
};

Now, in the command line, run:

$ gen
# then try
$ gen foo
# then try
$ gen foo bar

Run task dependencies

Now update your code to the following:

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

  app.task('bar', function(cb) {
    console.log('bar > success!');
    cb();
  });
};

And run:

$ gen

You're now a master at running tasks with generate! You can do anything with generate tasks that you can do with gulp tasks (we use and support gulp libraries after all!).

Next steps

But generate does much more than this. For a more in-depth introduction, we highly recommend visiting the getting started guide.

More info

Feature highlights

Generate offers an elegant and robust suite of methods, carefully organized to help you accomplish common activities in less time, including:

  • unparalleled flow control: through the use of generators, sub-generators and tasks
  • templates, scaffolds and boilerplates: generate a single file, initialize an entire project, or provide ad-hoc "components" throughout the duration of a project using any combination of templates, scaffolds and boilerplates.
  • any engine: use any template engine to render templates, including handlebars, lodash, swig and pug
  • prompts: asks you for data when it can't find what it needs, and it's easy to customize prompts for any data you want.
  • data: gathers data from the user's environment to populate "hints" in user prompts and render templates
  • streams: interact with the file system, with full support for gulp and assemble plugins
  • smart plugins: Generate is built on base, so any "smart" plugin can be used
  • stores: persist configuration settings, global defaults, project-specific defaults, answers to prompts, and so on.

Visit the getting started guide to learn more.

FAQ

What's an alias, and what do they do?

Generate tries to find globally installed generators using an "alias" first, falling back on the generator's full name if not found by its alias.

A generator's alias is created by stripping the substring generate- from the full name of generator. Thus, when publishing a generator the naming convention generate-foo should be used (where foo is the alias, and generate-foo is the full name).

Note that no dots may be used in published generator names. Aside from that, any characters considered valid by npm are fine.

Generate shares a common architecture and plugin ecosystem with the following libraries:

  • 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
  • update: Easily keep anything in your project up-to-date by installing the updaters you want to use… more | homepage
  • verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage

Contributing

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

Building docs

Generate readme and API documentation with verb:

$ npm install verb && npm run docs

Or, if verb is installed globally:

$ verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

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


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