0.1.1 • Published 8 years ago

base-register v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

base-register NPM version NPM downloads Build Status

Add support for registering a glob of generators to your base app.

Install

Install with npm:

$ npm install --save base-register

Usage

var generators = require('base-generators');
var register = require('base-register');
var Base = require('base');
var base = new Base();

base.use(generators());
base.use(register());

API

Params

  • patterns {Array|String}: End glob patterns with a slash to register a generator in a directory.
  • options {Object}
  • returns {Object}: Returns the instance for chaining

Example

app.register('generators/*');

Example

Let's say you have a generator with three sub-generators in directories:

my-generator
  L generators/sub-generator-a
  L generators/sub-generator-b
  L generators/sub-generator-c

Before

Typically, with base-generators you would register the sub-generators in your generator like this:

module.exports = function(app) {
  app.register('a', require('./generators/sub-generator-a'));
  app.register('b', require('./generators/sub-generator-b'));
  app.register('c', require('./generators/sub-generator-c'));
};

After

With this plugin, you can do this:

module.exports = function(app) {
  app.register('generators/*/');
};

Options

Pass options as the second argument. Anything that is supported by matched may be used.

Example

module.exports = function(app) {
  app.register('*/', {matchBase: '*.js', cwd: 'generators'});
};

Rename function

Pass a custom rename function as the last argument.

Params

The function exposes the following parameters:

  • filepath The fully resolved, absolute path to the generator
  • basename The basename of the absolute directory path. So the basename of foo/bar/baz/index.js would be baz

Example

Given the same generators from the first examples:

app.register('generators/*/index.js', function(name, filepath) {
  return 'foo-' + name;
});

// registers `foo-a`, `foo-b`, and `foo-c`

Related projects

You might also be interested in these projects:

  • base: base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… more | homepage
  • base-generators: Adds project-generator support to your base application. | homepage
  • generate: The Santa Claus machine for GitHub projects. Scaffolds out new projects, or creates any kind… more | homepage

Contributing

This document was generated by verb-readme-generator (a verb generator), please don't edit directly. Any changes to the readme must be made in .verb.md. See Building Docs.

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue. Or visit the verb-readme-generator project to submit bug reports or pull requests for the readme layout template.

Building docs

Generate readme and API documentation with verb:

$ npm install -g verb verb-readme-generator && 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 June 15, 2016.