base-generators
Advanced tools
Comparing version 0.1.16 to 0.1.17
222
index.js
@@ -14,2 +14,4 @@ /*! | ||
var debug = require('debug')('base:generators'); | ||
var FragmentCache = require('./lib/fragment'); | ||
var plugins = require('./lib/plugins'); | ||
var search = require('./lib/search'); | ||
@@ -20,2 +22,3 @@ var tasks = require('./lib/tasks'); | ||
var env = require('./lib/env'); | ||
var answers = {}; | ||
@@ -29,19 +32,9 @@ /** | ||
return function(app) { | ||
return function plugin(app) { | ||
if (this.isRegistered('base-generators')) return; | ||
this.isGenerator = true; | ||
this.define('firstGen', null); | ||
this.fragment = new FragmentCache(); | ||
this.generators = this.generators || {}; | ||
/** | ||
* Search caches | ||
*/ | ||
var memory = {}; | ||
memory.getGenerator = search(); | ||
memory.resolve = search(); | ||
memory.global = search(); | ||
memory.find = search(); | ||
/** | ||
* Add plugins necessary for running generators. | ||
@@ -51,14 +44,20 @@ * Plugins will only be registered once. | ||
this.define('initGenerators', function() { | ||
this.mixin('initGenerators', function() { | ||
this.options = utils.extend({}, this.options, config); | ||
if (!this.task) { | ||
this.use(utils.task(this.options)); | ||
} | ||
if (!this.fns) { | ||
this.use(utils.plugin(this.options)); | ||
} | ||
this.use(utils.cwd(this.options)); | ||
this.isGenerator = true; | ||
this.define('firstGen', null); | ||
if (!this.task) this.use(plugins.task(this.options)); | ||
this.use(plugins.resolver('apps')); | ||
this.use(plugins.plugin(this.options)); | ||
this.use(plugins.cwd(this.options)); | ||
this.use(tasks(this.options)); | ||
this.use(cache(this.options)); | ||
this.use(env(this.options)); | ||
this.apps.resolve('generate-*/{generator,index}.js'); | ||
this.apps.resolve('verb-*-generator/{generator,index}.js'); | ||
this.apps.resolve('./verbfile.js', {cwd: this.cwd}); | ||
}); | ||
@@ -86,19 +85,14 @@ | ||
this.define('resolve', function(name, options) { | ||
var opts = util.extend({ configfile: this.configfile }, options); | ||
if (memory.resolve.has(name)) { | ||
return memory.resolve.get(name); | ||
this.mixin('resolve', function(name, options) { | ||
var opts = util.extend({}, this.options, options); | ||
if (utils.isAbsolute(name)) { | ||
return this.resolveConfigpath(name, opts); | ||
} | ||
var fullname = this.toFullname(name); | ||
debug('resolving: "%s", at cwd: "%s"', name, opts.cwd); | ||
var filepath = util.tryResolve(fullname, opts) | ||
|| util.tryResolve(name, opts) | ||
|| util.tryResolve(path.join(name, this.configfile), opts) | ||
|| util.tryResolve(path.join(fullname, this.configfile), opts); | ||
if (filepath) { | ||
memory.resolve.set(name, filepath); | ||
return filepath; | ||
var generator = this.apps.get(name); | ||
if (generator) { | ||
return generator.path; | ||
} | ||
if (opts.cwd) { | ||
return this.resolveConfigpath(path.resolve(opts.cwd, name), opts); | ||
} | ||
}); | ||
@@ -116,3 +110,3 @@ | ||
this.define('registerConfig', function(name, configfile, options) { | ||
this.mixin('registerConfig', function(name, configfile, options) { | ||
var opts = util.extend({ cwd: this.cwd }, options); | ||
@@ -122,7 +116,4 @@ | ||
this.createEnv('default', configfile, opts); | ||
var fn = util.configfile(configfile, opts); | ||
var app = this.base.invoke(fn); | ||
this.register(name, app); | ||
return app; | ||
return this.register(name, fn); | ||
}); | ||
@@ -146,4 +137,10 @@ | ||
this.define('register', function(name, fn) { | ||
return this.generators.set(name, fn, this); | ||
this.mixin('register', function(name, fn) { | ||
var gen = this.generators.set(name, fn, this); | ||
var path = gen.env.path; | ||
if (path && this.apps.files.indexOf(path) === -1) { | ||
this.apps.files.push(path); | ||
} | ||
this.fragment.set('name', name, gen); | ||
return gen; | ||
}); | ||
@@ -171,3 +168,3 @@ | ||
this.define('generator', function(name, fn) { | ||
this.mixin('generator', function(name, fn) { | ||
if (arguments.length === 1 && typeof name === 'string') { | ||
@@ -204,3 +201,3 @@ var generator = this.getGenerator(name); | ||
this.define('hasGenerator', function(name) { | ||
this.mixin('hasGenerator', function(name) { | ||
var objectPath = util.toGeneratorPath(name); | ||
@@ -229,11 +226,5 @@ if (this.has(objectPath)) { | ||
this.define('getGenerator', function(name, aliasFn) { | ||
this.mixin('getGenerator', function(name, aliasFn) { | ||
debug('getting generator "%s"', name); | ||
var gen = this.generators[name]; | ||
if (gen) { | ||
memory.getGenerator.set(name, gen); | ||
return gen; | ||
} | ||
if (typeof aliasFn !== 'function') { | ||
@@ -243,10 +234,59 @@ aliasFn = this.toAlias.bind(this); | ||
if (memory.getGenerator.has(name)) { | ||
return memory.getGenerator.get(name); | ||
var app = this; | ||
function get(key) { | ||
return app.generators[key] || app.base.generators[key]; | ||
} | ||
var isSubgenerator = name.indexOf('.') !== -1; | ||
if (!isSubgenerator) { | ||
var fullname = this.toFullname(name); | ||
var alias = aliasFn(name); | ||
app = get(name) || get(alias) || get(fullname); | ||
if (typeof app === 'undefined') { | ||
app = this.apps.alias(name) | ||
|| this.apps.name(name) | ||
|| this.apps.alias(fullname) | ||
|| this.apps.name(fullname) | ||
|| this.apps.alias(alias) | ||
|| this.apps.name(alias) | ||
} | ||
} else { | ||
app = this.getSubGenerator(name, aliasFn); | ||
} | ||
if (app && app.path && !app.env) { | ||
this.register(name, app.path); | ||
app = this.generators[name]; | ||
this.invoke(app); | ||
} | ||
if (app && app.env) { | ||
this.fragment.set('name', name, app); | ||
return app; | ||
} | ||
}); | ||
/** | ||
* Get sub-generator `name`, using dot-notation for nested generators. | ||
* | ||
* ```js | ||
* app.getSubGenerator('foo.bar.baz')' | ||
* ```' | ||
* @name .getSubGenerator | ||
* @param {String} `name` The property-path of the generator to get | ||
* @param {Function} `aliasFn` | ||
* @api public | ||
*/ | ||
this.mixin('getSubGenerator', function(name, aliasFn) { | ||
if (!~name.indexOf('.')) { | ||
return this.getGenerator.apply(this, arguments); | ||
} | ||
var props = name.split('.'); | ||
var len = props.length; | ||
var idx = -1; | ||
var app = this; | ||
app = this; | ||
@@ -261,4 +301,4 @@ while (++idx < len) { | ||
if (app) { | ||
memory.getGenerator.set(name, app); | ||
if (app && app.env) { | ||
this.fragment.set('name', name, app); | ||
return app; | ||
@@ -280,16 +320,9 @@ } | ||
this.define('findGenerator', function(name, aliasFn) { | ||
this.mixin('findGenerator', function(name, aliasFn) { | ||
debug('finding generator "%s"', name); | ||
var gen = memory.find.get(name); | ||
if (util.isObject(gen) || typeof gen === 'function') { | ||
return gen; | ||
} | ||
aliasFn = aliasFn || this.toAlias.bind(this); | ||
// if sub-generator, look for it on the first resolved generator | ||
if (this.firstGen && this.firstGen.generators[name]) { | ||
var sub = this.firstGen.getGenerator(name, aliasFn); | ||
var sub = this.firstGen.getGenerator(name); | ||
if (sub) { | ||
memory.find.set(name, sub); | ||
return sub; | ||
@@ -313,3 +346,6 @@ } | ||
if (!generator && name.indexOf(this.prefix) === -1) { | ||
generator = this.findGenerator(this.toFullname(name), aliasFn); | ||
var fullname = this.toFullname(name); | ||
if (name !== fullname) { | ||
generator = this.findGenerator(fullname, aliasFn); | ||
} | ||
} | ||
@@ -320,3 +356,2 @@ | ||
if (!this.firstGen) this.firstGen = generator; | ||
memory.find.set(name, generator); | ||
return generator; | ||
@@ -336,20 +371,15 @@ } | ||
this.define('globalGenerator', function(name) { | ||
this.mixin('globalGenerator', function(name) { | ||
debug('getting global generator "%s"', name); | ||
if (memory.global.has(name)) { | ||
return memory.global.get(name); | ||
} | ||
var filepath = this.resolve(name, {cwd: util.gm}); | ||
if (memory.global.has(filepath)) { | ||
return memory.global.get(filepath); | ||
} | ||
if (utils.isGenerator(filepath, this.prefix)) { | ||
var generator = this.getGenerator(name); | ||
if (generator) { | ||
memory.global.set(name, generator); | ||
return generator; | ||
} | ||
} | ||
return util.tryResolve(name, { | ||
configfile: this.configfile | ||
}); | ||
}); | ||
@@ -370,3 +400,3 @@ | ||
this.define('invoke', function(app) { | ||
this.mixin('invoke', function(app) { | ||
if (Array.isArray(app)) { | ||
@@ -408,3 +438,3 @@ return app.forEach(this.invoke.bind(this)); | ||
this.define('extendWith', function(app) { | ||
this.mixin('extendWith', function(app) { | ||
this.invoke(app); | ||
@@ -447,3 +477,9 @@ return this; | ||
this.define('generate', function(name, tasks, cb) { | ||
this.mixin('generate', function(name, tasks, cb) { | ||
if (typeof name === 'function') { | ||
cb = name; | ||
name = 'default'; | ||
tasks = ['default']; | ||
} | ||
if (Array.isArray(name)) { | ||
@@ -523,3 +559,3 @@ return this.generateEach(name, tasks); | ||
this.define('generateEach', function(tasks, cb) { | ||
this.mixin('generateEach', function(tasks, cb) { | ||
if (Array.isArray(tasks) && tasks.length === 0) { | ||
@@ -548,3 +584,3 @@ tasks = ['default']; | ||
this.define('toAlias', function toAlias(name, options) { | ||
this.mixin('toAlias', function(name, options) { | ||
var opts = util.extend({}, config, this.options, options); | ||
@@ -569,3 +605,3 @@ if (!opts.prefix && !opts.modulename) { | ||
this.define('toFullname', function toFullname(alias, options) { | ||
this.mixin('toFullname', function(alias, options) { | ||
var opts = util.extend({prefix: this.prefix}, config, this.options, options); | ||
@@ -578,2 +614,22 @@ var fullname = util.toFullname(alias, opts); | ||
/** | ||
* Return the absolute filepath to a generator's main file. | ||
* | ||
* @name .resolveConfigpath | ||
* @param {String} `alias` | ||
* @param {Object} `options` | ||
* @return {String} Returns the full name. | ||
* @api public | ||
*/ | ||
this.mixin('resolveConfigpath', function(filepath, options) { | ||
var opts = util.extend({}, config, this.options, options); | ||
var file = this.apps.createEnv(filepath, opts); | ||
if (file) { | ||
this.fragment.set('name', file.name, file); | ||
debug('created configpath "%s" for generator "%s"', file.main, file.name); | ||
return file.main; | ||
} | ||
}); | ||
/** | ||
* Getter/setter for defining the `configname` name to use for lookups. | ||
@@ -580,0 +636,0 @@ * By default `configname` is set to `generator.js`. |
@@ -12,3 +12,3 @@ 'use strict'; | ||
return function(app) { | ||
if (this.isRegistered('generator-cache')) return; | ||
if (this.isRegistered('base-generators-cache')) return; | ||
@@ -93,2 +93,10 @@ var Generator = this.constructor; | ||
// if `pristine` is defined on base.options, parent options will | ||
// not be merged onto "child" generators, and parent plugins will | ||
// not be run on "child" generators | ||
if (pristine !== true) { | ||
generator.options = opts; | ||
app.run(generator); | ||
} | ||
// create getter for invoking the generator instance | ||
@@ -107,10 +115,2 @@ Object.defineProperty(this, name, { | ||
// if `pristine` is defined on base.options, parent options will | ||
// not be merged onto "child" generators, and parent plugins will | ||
// not be run on "child" generators | ||
if (pristine !== true) { | ||
generator.options = opts; | ||
app.run(generator); | ||
} | ||
parent.emit('generator.set', generator); | ||
@@ -180,2 +180,10 @@ parent.emit('generator', 'set', generator); | ||
if (error.name === 'TypeError') { | ||
return error; | ||
} | ||
if (error.name === 'SyntaxError') { | ||
return error; | ||
} | ||
if (error.name === 'ReferenceError') { | ||
@@ -182,0 +190,0 @@ return error; |
142
lib/env.js
'use strict'; | ||
var path = require('path'); | ||
var utils = require('generator-util'); | ||
var util = require('generator-util'); | ||
var debug = require('debug')('base:generators:env'); | ||
var cache = {}; | ||
var define = require('./define'); | ||
var utils = require('./utils'); | ||
@@ -13,3 +14,2 @@ module.exports = function(config) { | ||
if (this.isRegistered('base-generators-env')) return; | ||
this.env = this.env || {}; | ||
@@ -28,4 +28,4 @@ /** | ||
this.define('createEnv', function(name, options, fn) { | ||
if (!utils.isObject(options)) { | ||
this.mixin('createEnv', function(name, options, fn) { | ||
if (!util.isObject(options)) { | ||
fn = options; | ||
@@ -35,3 +35,4 @@ options = {}; | ||
var opts = utils.extend({}, config, this.options, options); | ||
var opts = util.extend({verbose: true}, config, this.options, options); | ||
// var env = new Env(this, name, opts, fn); | ||
this.env = this.env || {}; | ||
@@ -47,14 +48,27 @@ var env = this.env; | ||
var inspect = '<Generator ' + name; | ||
if (typeof fn === 'string') { | ||
envPath(this, name, env, opts, fn); | ||
inspect += ' [string] ' + env.path; | ||
} else if (typeof fn === 'function') { | ||
envFn(this, name, env, opts, fn); | ||
inspect += ' [function] ' + env.path; | ||
} else if (utils.isObject(fn) && fn.isGenerator) { | ||
} else if (util.isObject(fn) && fn.isGenerator) { | ||
envFn(this, name, env, opts, fn); | ||
inspect += ' [instance] ' + env.path; | ||
} | ||
if (env.path && util.isDirectory(env.path)) { | ||
env.path = path.resolve(env.path, env.configfile); | ||
} | ||
inspect += '>'; | ||
env.inspect = function() { | ||
return inspect; | ||
}; | ||
debug('created: %j', env); | ||
cache[name] = env; | ||
return env; | ||
@@ -64,15 +78,15 @@ }); | ||
function envPath(app, name, env, opts, fn) { | ||
env.path = fn; | ||
function envPath(app, name, env, opts, filepath) { | ||
env.path = env.path || filepath; | ||
if (!utils.isAbsolute(env.path)) { | ||
env.path = utils.tryResolve(fn, {configfile: app.configfile}); | ||
if (!util.isAbsolute(env.path)) { | ||
env.path = util.tryResolve(filepath, { configfile: app.configfile }); | ||
} | ||
if (typeof env.path === 'undefined' || !utils.exists(env.path)) { | ||
throw new Error('cannot find generator: ' + fn); | ||
if (typeof env.path === 'undefined' || !util.exists(env.path)) { | ||
throw new Error('cannot find generator: ' + filepath); | ||
} | ||
env.alias = utils.toAlias(name, opts); | ||
env.name = utils.toFullname(env.alias, opts); | ||
env.alias = app.toAlias(name, opts); | ||
env.name = app.toFullname(env.alias, opts); | ||
createPaths(app, name, env, opts); | ||
@@ -91,3 +105,3 @@ | ||
if (utils.isObject(fn)) { | ||
if (util.isObject(fn)) { | ||
paths[env.path] = fn; | ||
@@ -97,3 +111,3 @@ return fn; | ||
var fn = utils.tryRequire(env.path) || utils.tryRequire(env.cwd); | ||
var fn = util.tryRequire(env.path) || util.tryRequire(env.cwd); | ||
if (fn) { | ||
@@ -123,13 +137,83 @@ paths[env.path] = fn; | ||
function define(obj, prop, fn) { | ||
Object.defineProperty(obj, prop, { | ||
configurable: true, | ||
enumerable: true, | ||
set: function(val) { | ||
define(obj, prop, val); | ||
}, | ||
get: function() { | ||
return fn(); | ||
// function define(obj, prop, fn) { | ||
// Object.defineProperty(obj, prop, { | ||
// configurable: true, | ||
// enumerable: true, | ||
// set: function(val) { | ||
// define(obj, prop, val); | ||
// }, | ||
// get: function() { | ||
// return fn(); | ||
// } | ||
// }); | ||
// } | ||
function Env(app, fp, options, fn) { | ||
if (typeof options === 'function') { | ||
fn = options; | ||
options = {}; | ||
} | ||
var opts = utils.extend({}, app.options, options); | ||
var file = new utils.Vinyl({path: fp}); | ||
var cwd = path.dirname(file.path); | ||
// var fragment = app.generators.fragment; | ||
// file.pkgPath = path.resolve(cwd, 'package.json'); | ||
// var pkg; | ||
// define(file, 'pkg', function() { | ||
// return (pkg = require(file.pkgPath) || {}); | ||
// }); | ||
// define(file, 'name', function() { | ||
// // if the dirname is the current working directory, this is our default generator | ||
// var name = file.dirname !== process.cwd() | ||
// ? (pkg ? pkg.name : path.basename(file.dirname)) | ||
// : name = 'default'; | ||
// fragment.set('name', name, file); | ||
// return name; | ||
// }); | ||
// define(file, 'fn', function() { | ||
// if (typeof fn === 'function') { | ||
// return fn; | ||
// } | ||
// fn = fragment.get('fn', file.name); | ||
// if (typeof fn === 'function') { | ||
// return fn; | ||
// } | ||
// fn = require(file.path); | ||
// fragment.set('fn', fn); | ||
// return fn; | ||
// }); | ||
// define(file, 'alias', function() { | ||
// var alias = typeof opts.alias === 'function' | ||
// ? opts.alias.call(file, file.name) | ||
// : utils.aliasFn.call(file, file.name, file); | ||
// if (alias) { | ||
// fragment.set('alias', alias, file); | ||
// } | ||
// return alias; | ||
// }); | ||
var inspect = '<Generator ' + utils.formatAlias(file) + utils.formatPath(file) + '>'; | ||
if (opts.verbose) { | ||
inspect = {}; | ||
for (var key in file) { | ||
inspect[key] = file[key]; | ||
} | ||
}); | ||
} | ||
} | ||
file.inspect = function() { | ||
return inspect; | ||
}; | ||
return file; | ||
}; | ||
@@ -18,3 +18,3 @@ 'use strict'; | ||
this.define('resolveTasks', function(names, tasks) { | ||
this.mixin('resolveTasks', function(names, tasks) { | ||
var prop = this.stringifyTasks(names, tasks); | ||
@@ -24,3 +24,2 @@ var segs = prop.split(':'); | ||
debug('normalizing task args: "%s"', prop); | ||
var res = {}; | ||
@@ -89,3 +88,3 @@ res.generator = this; | ||
this.define('hasTask', function(name) { | ||
this.mixin('hasTask', function(name) { | ||
return this.has(['tasks', name]); | ||
@@ -103,3 +102,3 @@ }); | ||
this.define('stringifyTasks', function(names, tasks) { | ||
this.mixin('stringifyTasks', function(names, tasks) { | ||
debug('stringifying tasks "%j"', arguments); | ||
@@ -106,0 +105,0 @@ if (typeof tasks === 'function') { |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var fn = require; | ||
require = utils; | ||
require = utils; // eslint-disable-line | ||
@@ -14,11 +14,15 @@ /** | ||
require('base-cwd', 'cwd'); | ||
require('base-task', 'task'); | ||
require('base-plugins', 'plugin'); | ||
require('ansi-bold', 'bold'); | ||
require('ansi-yellow', 'yellow'); | ||
require('ansi-magenta', 'magenta'); | ||
require('arr-union', 'union'); | ||
require('array-unique', 'unique'); | ||
require('define-property', 'define'); | ||
require('extend-shallow', 'extend'); | ||
require('get-value', 'get'); | ||
require('is-absolute'); | ||
require('extend-shallow', 'extend'); | ||
require('array-unique', 'unique'); | ||
require = fn; | ||
require('mixin-deep', 'merge'); | ||
require('resolve'); | ||
require('vinyl', 'Vinyl'); | ||
require = fn; // eslint-disable-line | ||
@@ -42,3 +46,5 @@ utils.validate = function(file, opts) { | ||
var fn = (app.env && app.env.fn) || app; | ||
var isFunction = typeof app === 'function'; | ||
var fn = isFunction ? app : (app.env && app.env.fn); | ||
if (typeof fn !== 'function') { | ||
@@ -51,5 +57,5 @@ return app; | ||
debug('invoking "%s"', env.alias); | ||
debug('invoking "%s"', env && env.alias); | ||
fn.call(context, context, base, env); | ||
return app; | ||
return context; | ||
}; | ||
@@ -85,2 +91,25 @@ | ||
utils.formatAlias = function(file) { | ||
return utils.yellow(file.alias); | ||
} | ||
utils.formatPath = function(file) { | ||
var inspectType = file.inspectType || 'path'; | ||
var fp = file.path; | ||
if (!/\.\.\//.test(file.relative)) { | ||
fp = file.relative; | ||
} | ||
var name = path.dirname(fp); | ||
if (name === '.') { | ||
name = file.name; | ||
} | ||
var res = ' <' + utils.magenta(inspectType) + '>'; | ||
if (inspectType === 'function') { | ||
return res; | ||
} | ||
res += ' '; | ||
res += utils.yellow(utils.bold(name)); | ||
return res; | ||
}; | ||
/** | ||
@@ -87,0 +116,0 @@ * Expose `utils` |
{ | ||
"name": "base-generators", | ||
"description": "Adds project-generator support to your `base` application.", | ||
"version": "0.1.16", | ||
"version": "0.1.17", | ||
"homepage": "https://github.com/jonschlinkert/base-generators", | ||
@@ -24,6 +24,11 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"dependencies": { | ||
"ansi-bold": "^0.1.1", | ||
"ansi-magenta": "^0.1.1", | ||
"ansi-yellow": "^0.1.1", | ||
"arr-union": "^3.0.0", | ||
"array-unique": "^0.2.1", | ||
"async": "^1.5.2", | ||
"base-cwd": "^0.1.3", | ||
"base-plugins": "^0.4.1", | ||
"base-plugins": "^0.4.3", | ||
"base-resolver": "github:node-base/base-resolver#dev", | ||
"base-task": "^0.4.1", | ||
@@ -36,6 +41,10 @@ "debug": "^2.2.0", | ||
"is-absolute": "^0.2.3", | ||
"lazy-cache": "^1.0.3" | ||
"lazy-cache": "^1.0.3", | ||
"map-cache": "^0.2.0", | ||
"mixin-deep": "^1.1.3", | ||
"resolve": "^1.1.7", | ||
"vinyl": "^1.1.1" | ||
}, | ||
"devDependencies": { | ||
"base": "^0.7.2", | ||
"base": "^0.7.4", | ||
"base-option": "^0.6.1", | ||
@@ -42,0 +51,0 @@ "base-runtimes": "^0.1.4", |
@@ -18,5 +18,5 @@ # base-generators [](https://www.npmjs.com/package/base-generators) [](https://travis-ci.org/jonschlinkert/base-generators) | ||
- [Related projects](#related-projects) | ||
- [Generate docs](#generate-docs) | ||
- [Contributing](#contributing) | ||
- [Building docs](#building-docs) | ||
- [Running tests](#running-tests) | ||
- [Contributing](#contributing) | ||
- [Author](#author) | ||
@@ -32,3 +32,3 @@ - [License](#license) | ||
```sh | ||
$ npm i base-generators --save | ||
$ npm install base-generators --save | ||
``` | ||
@@ -250,3 +250,3 @@ | ||
### [.resolve](index.js#L82) | ||
### [.resolve](index.js#L81) | ||
@@ -283,3 +283,3 @@ Attempts to find a generator with the given `name` and `options`. | ||
### [.register](index.js#L139) | ||
### [.register](index.js#L130) | ||
@@ -303,3 +303,3 @@ Register generator `name` with the given `fn`. | ||
### [.generator](index.js#L163) | ||
### [.generator](index.js#L160) | ||
@@ -323,3 +323,3 @@ Register generator `name` with the given `fn`, or get generator `name` if only one argument is passed. This method calls the `.getGenerator` method but goes one step further: if `name` is not already registered, it will try to resolve and register the generator before returning it (or `undefined` if unsuccessful). | ||
### [.hasGenerator](index.js#L195) | ||
### [.hasGenerator](index.js#L192) | ||
@@ -348,3 +348,3 @@ Return true if the given `name` exists on the `generators` object. Dot-notation may be used to check for sub-generators. | ||
### [.getGenerator](index.js#L219) | ||
### [.getGenerator](index.js#L216) | ||
@@ -367,4 +367,17 @@ Get generator `name` from `app.generators`. Dot-notation may be used to get a sub-generator. | ||
### [.findGenerator](index.js#L267) | ||
### [.getSubGenerator](index.js#L271) | ||
Get sub-generator `name`, using dot-notation for nested generators. | ||
```js | ||
app.getSubGenerator('foo.bar.baz')' | ||
```' | ||
**Params** | ||
* `name` **{String}**: The property-path of the generator to get | ||
* `aliasFn` **{Function}** | ||
### [.findGenerator](index.js#L307) | ||
Find generator `name`, by first searching the cache, | ||
@@ -376,7 +389,7 @@ then searching the cache of the `base` generator, | ||
* `name` **{String}** | ||
* `aliasFn` **{Function}**: Optionally supply a rename function. | ||
* `name` **{String}** | ||
* `aliasFn` **{Function}**: Optionally supply a rename function. | ||
* `returns` **{Object|undefined}**: Returns the generator instance if found, or undefined. | ||
### [.globalGenerator](index.js#L320) | ||
### [.globalGenerator](index.js#L355) | ||
@@ -388,6 +401,6 @@ Search for globally installed generator `name`. If found, then generator | ||
* `name` **{String}** | ||
* `name` **{String}** | ||
* `returns` **{Object|undefined}** | ||
### [.invoke](index.js#L353) | ||
### [.invoke](index.js#L383) | ||
@@ -398,4 +411,4 @@ Invoke the given generator in the context of (`this`) the current instance. | ||
* `app` **{String|Object}**: Generator name or instance. | ||
* `returns` **{Object}**: Returns the instance for chaining. | ||
* `app` **{String|Object}**: Generator name or instance. | ||
* `returns` **{Object}**: Returns the instance for chaining. | ||
@@ -408,3 +421,3 @@ **Example** | ||
### [.extendWith](index.js#L390) | ||
### [.extendWith](index.js#L420) | ||
@@ -429,3 +442,3 @@ Alias for `.invoke`, Extend the current generator instance with the settings of other generators. | ||
### [.generate](index.js#L428) | ||
### [.generate](index.js#L458) | ||
@@ -468,3 +481,3 @@ Run a `generator` and `tasks`, calling the given `callback` function upon completion. | ||
### [.generateEach](index.js#L503) | ||
### [.generateEach](index.js#L539) | ||
@@ -488,3 +501,3 @@ Iterate over an array of generators and tasks, calling [generate](#generate) on each. | ||
### [.alias](index.js#L527) | ||
### [.alias](index.js#L563) | ||
@@ -499,3 +512,3 @@ Create a generator alias from the given `name`. | ||
### [.fullname](index.js#L547) | ||
### [.fullname](index.js#L583) | ||
@@ -510,8 +523,18 @@ Create a generator's full name from the given `alias`. | ||
### [.configname](index.js#L562) | ||
### [.resolveConfigpath](index.js#L600) | ||
Return the absolute filepath to a generator's main file. | ||
**Params** | ||
* `alias` **{String}** | ||
* `options` **{Object}** | ||
* `returns` **{String}**: Returns the full name. | ||
### [.configname](index.js#L618) | ||
Getter/setter for defining the `configname` name to use for lookups. | ||
By default `configname` is set to `generator.js`. | ||
### [.configfile](index.js#L584) | ||
### [.configfile](index.js#L640) | ||
@@ -521,3 +544,3 @@ Getter/setter for defining the `configfile` name to use for lookups. | ||
### [.configpath](index.js#L602) | ||
### [.configpath](index.js#L658) | ||
@@ -527,3 +550,3 @@ Getter/setter for defining the `configpath` name to use for lookups. | ||
### [.modulename](index.js#L620) | ||
### [.modulename](index.js#L676) | ||
@@ -533,3 +556,3 @@ Getter/setter for defining the `modulename` name to use for lookups. | ||
### [.base](index.js#L647) | ||
### [.base](index.js#L703) | ||
@@ -569,8 +592,12 @@ Getter/setter for the `base` (or shared) instance of `generate`. | ||
## Generate docs | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/base-generators/issues/new). | ||
## Building docs | ||
Generate readme and API documentation with [verb](https://github.com/verbose/verb): | ||
```sh | ||
$ npm i -d && npm run docs | ||
$ npm install verb && npm run docs | ||
``` | ||
@@ -589,9 +616,5 @@ | ||
```sh | ||
$ npm i -d && npm test | ||
$ npm install -d && npm test | ||
``` | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/base-generators/issues/new). | ||
## Author | ||
@@ -611,2 +634,2 @@ | ||
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on February 17, 2016._ | ||
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on February 23, 2016._ |
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
60210
12
1296
612
21
1
3
+ Addedansi-bold@^0.1.1
+ Addedansi-magenta@^0.1.1
+ Addedansi-yellow@^0.1.1
+ Addedarr-union@^3.0.0
+ Addedmap-cache@^0.2.0
+ Addedmixin-deep@^1.1.3
+ Addedresolve@^1.1.7
+ Addedvinyl@^1.1.1
+ Addedansi-bold@0.1.1(transitive)
+ Addedansi-magenta@0.1.1(transitive)
+ Addedansi-wrap@0.1.0(transitive)
+ Addedansi-yellow@0.1.1(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedclone@1.0.4(transitive)
+ Addedclone-stats@0.0.1(transitive)
+ Addedis-extendable@1.0.1(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedmap-cache@0.2.2(transitive)
+ Addedmixin-deep@1.3.2(transitive)
+ Addedreplace-ext@0.0.1(transitive)
+ Addedvinyl@1.2.0(transitive)
Updatedbase-plugins@^0.4.3