base-register
Add support for registering a glob of generators to your base app.
Last updated 4 years ago by jonschlinkert .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install base-register 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 0.1.1                                ...           latest (4 years ago)

2 Versions

  • 0.1.1                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 3
Dependencies (7)
Dev Dependencies (4)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |