base-register

Add support for registering a glob of generators to your base app.
Install
Install with npm:
$ npm install base-register --save
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;
});
Related projects
You might also be interested in these projects:
- base-generators: Adds project-generator support to your
base application. | homepage
- base: base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… more | homepage
- generate: Fast, composable, highly extendable project generator with a user-friendly and expressive API. | 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 05, 2016.