base-generators
Advanced tools
Comparing version 0.1.17 to 0.1.18
54
index.js
@@ -130,4 +130,4 @@ /*! | ||
this.mixin('register', function(name, fn) { | ||
var gen = this.generators.set(name, fn, this); | ||
this.mixin('register', function(name, fn, options) { | ||
var gen = this.generators.set(name, fn, this, options); | ||
var path = gen.env.path; | ||
@@ -161,3 +161,3 @@ if (path && this.apps.files.indexOf(path) === -1) { | ||
this.mixin('generator', function(name, fn) { | ||
this.mixin('generator', function(name, fn, options) { | ||
if (arguments.length === 1 && typeof name === 'string') { | ||
@@ -167,3 +167,3 @@ var generator = this.getGenerator(name); | ||
} | ||
this.register(name, fn); | ||
this.register(name, fn, options); | ||
return this.getGenerator(name); | ||
@@ -219,8 +219,7 @@ }); | ||
this.mixin('getGenerator', function(name, aliasFn) { | ||
this.mixin('getGenerator', function(name, options) { | ||
debug('getting generator "%s"', name); | ||
if (typeof aliasFn !== 'function') { | ||
aliasFn = this.toAlias.bind(this); | ||
} | ||
options = options || {}; | ||
var aliasFn = (options.toAlias || this.toAlias).bind(this); | ||
@@ -230,3 +229,3 @@ var app = this; | ||
function get(key) { | ||
return app.generators[key] || app.base.generators[key]; | ||
return app.generators.get(key) || app.base.generators.get(key); | ||
} | ||
@@ -243,4 +242,6 @@ | ||
|| this.apps.name(name) | ||
|| this.apps.alias(fullname) | ||
|| this.apps.name(fullname) | ||
|| this.apps.alias(alias) | ||
@@ -277,3 +278,3 @@ || this.apps.name(alias) | ||
this.mixin('getSubGenerator', function(name, aliasFn) { | ||
this.mixin('getSubGenerator', function(name, options) { | ||
if (!~name.indexOf('.')) { | ||
@@ -290,3 +291,3 @@ return this.getGenerator.apply(this, arguments); | ||
var key = props[idx]; | ||
app = app.findGenerator(key, aliasFn); | ||
app = app.findGenerator(key, options); | ||
if (!app) { | ||
@@ -310,3 +311,3 @@ break; | ||
* @param {String} `name` | ||
* @param {Function} `aliasFn` Optionally supply a rename function. | ||
* @param {Function} `options` Optionally supply a rename function on `options.toAlias` | ||
* @return {Object|undefined} Returns the generator instance if found, or undefined. | ||
@@ -316,3 +317,3 @@ * @api public | ||
this.mixin('findGenerator', function(name, aliasFn) { | ||
this.mixin('findGenerator', function(name, options) { | ||
debug('finding generator "%s"', name); | ||
@@ -322,3 +323,3 @@ | ||
if (this.firstGen && this.firstGen.generators[name]) { | ||
var sub = this.firstGen.getGenerator(name); | ||
var sub = this.firstGen.getGenerator(name, options); | ||
if (sub) { | ||
@@ -331,4 +332,4 @@ return sub; | ||
// search for the generator on the base instance's cache | ||
var generator = this.generators.get(name, aliasFn) | ||
|| this.base.generators.get(name, aliasFn); | ||
var generator = this.generators.get(name, options) | ||
|| this.base.generators.get(name, options); | ||
@@ -346,3 +347,3 @@ // try searching in local and global node_modules | ||
if (name !== fullname) { | ||
generator = this.findGenerator(fullname, aliasFn); | ||
generator = this.findGenerator(fullname, options); | ||
} | ||
@@ -372,3 +373,3 @@ } | ||
var filepath = this.resolve(name, {cwd: util.gm}); | ||
if (utils.isGenerator(filepath, this.prefix)) { | ||
if (this.isGeneratorPath(filepath, this.prefix)) { | ||
var generator = this.getGenerator(name); | ||
@@ -567,3 +568,16 @@ if (generator) { | ||
/** | ||
* Returns true if the given | ||
*/ | ||
this.mixin('isGeneratorPath', function(filepath) { | ||
if (typeof filepath !== 'string') { | ||
return false; | ||
} | ||
var basename = path.basename(path.dirname(filepath)); | ||
return basename.indexOf(this.prefix) !== -1; | ||
}); | ||
/** | ||
* Create a generator alias from the given `name`. | ||
@@ -580,5 +594,3 @@ * | ||
var opts = util.extend({}, config, this.options, options); | ||
if (!opts.prefix && !opts.modulename) { | ||
opts.prefix = this.prefix; | ||
} | ||
opts.prefix = opts.prefix || opts.modulename || this.prefix; | ||
var alias = util.toAlias(name, opts); | ||
@@ -585,0 +597,0 @@ debug('created alias "%s" for string "%s"', alias, name); |
@@ -43,3 +43,3 @@ 'use strict'; | ||
Cache.prototype.set = function(name, fn, parent) { | ||
Cache.prototype.set = function(name, fn, parent, options) { | ||
debug('setting generator "%s"', name); | ||
@@ -71,3 +71,3 @@ delete invoked[alias]; | ||
// merge options | ||
var opts = utils.extend({}, config, app.base.options, generator.options); | ||
var opts = utils.extend({}, config, app.base.options, options, generator.options); | ||
if (opts.pristine === true) { | ||
@@ -93,2 +93,3 @@ pristine = true; | ||
generator.namespace = toNamespace(parent, alias); | ||
generator.name = generator.env.name; | ||
@@ -109,3 +110,3 @@ // if `pristine` is defined on base.options, parent options will | ||
if (invoked[name]) return invoked[name]; | ||
var gen = utils.invoke(generator); | ||
var gen = utils.invoke(generator, opts.runInContext); | ||
if (gen) { | ||
@@ -112,0 +113,0 @@ return (invoked[name] = gen); |
@@ -33,4 +33,3 @@ 'use strict'; | ||
var opts = util.extend({verbose: true}, config, this.options, options); | ||
// var env = new Env(this, name, opts, fn); | ||
var opts = utils.merge({verbose: true}, config, this.options, options); | ||
this.env = this.env || {}; | ||
@@ -86,4 +85,7 @@ var env = this.env; | ||
env.alias = app.toAlias(name, opts); | ||
env.name = app.toFullname(env.alias, opts); | ||
var fp = utils.resolve.sync(filepath); | ||
if (app.isGeneratorPath(fp)) { | ||
env.name = path.basename(path.dirname(fp)); | ||
} | ||
createPaths(app, name, env, opts); | ||
@@ -116,7 +118,5 @@ | ||
function envFn(app, name, env, opts, fn) { | ||
env.alias = name; | ||
env.name = name; | ||
createPaths(app, name, env, opts); | ||
env.path = undefined; | ||
env.fn = fn; | ||
createPaths(app, name, env, opts); | ||
} | ||
@@ -128,3 +128,4 @@ | ||
} | ||
app.name = env.alias; | ||
env.alias = app.toAlias(name, opts); | ||
env.name = env.name || name; | ||
debug('createEnv · name: "%s", alias: "%s"', env.name, env.alias); | ||
@@ -131,0 +132,0 @@ } |
@@ -47,2 +47,4 @@ 'use strict'; | ||
var fn = isFunction ? app : (app.env && app.env.fn); | ||
// if app is not a function, it's already instantiated | ||
if (typeof fn !== 'function') { | ||
@@ -64,14 +66,2 @@ return app; | ||
utils.isGenerator = function(filepath, prefix) { | ||
if (typeof filepath !== 'string') { | ||
return false; | ||
} | ||
var basename = path.basename(path.dirname(filepath)); | ||
return basename.indexOf(prefix) !== -1; | ||
}; | ||
/** | ||
* Return the given value as-is | ||
*/ | ||
utils.identity = function(val) { | ||
@@ -78,0 +68,0 @@ return val; |
{ | ||
"name": "base-generators", | ||
"description": "Adds project-generator support to your `base` application.", | ||
"version": "0.1.17", | ||
"version": "0.1.18", | ||
"homepage": "https://github.com/jonschlinkert/base-generators", | ||
@@ -27,7 +27,7 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"ansi-yellow": "^0.1.1", | ||
"arr-union": "^3.0.0", | ||
"arr-union": "^3.1.0", | ||
"array-unique": "^0.2.1", | ||
"async": "^1.5.2", | ||
"base-cwd": "^0.1.3", | ||
"base-plugins": "^0.4.3", | ||
"base-plugins": "^0.4.4", | ||
"base-resolver": "github:node-base/base-resolver#dev", | ||
@@ -48,9 +48,9 @@ "base-task": "^0.4.1", | ||
"devDependencies": { | ||
"base": "^0.7.4", | ||
"base-option": "^0.6.1", | ||
"base": "^0.7.9", | ||
"base-option": "^0.6.2", | ||
"base-runtimes": "^0.1.4", | ||
"generate-foo": "^0.1.5", | ||
"global-modules": "^0.2.0", | ||
"gulp": "^3.9.0", | ||
"gulp-eslint": "^1.1.1", | ||
"gulp": "^3.9.1", | ||
"gulp-eslint": "^2.0.0", | ||
"gulp-format-md": "^0.1.7", | ||
@@ -60,3 +60,3 @@ "gulp-istanbul": "^0.10.3", | ||
"minimist": "^1.2.0", | ||
"mocha": "*", | ||
"mocha": "^2.4.5", | ||
"spawn-commands": "^0.3.1" | ||
@@ -66,2 +66,3 @@ }, | ||
"ignore": [ | ||
"docs", | ||
"examples/generators" | ||
@@ -68,0 +69,0 @@ ] |
@@ -360,3 +360,3 @@ # base-generators [](https://www.npmjs.com/package/base-generators) [](https://travis-ci.org/jonschlinkert/base-generators) | ||
### [.getSubGenerator](index.js#L271) | ||
### [.getSubGenerator](index.js#L272) | ||
@@ -372,5 +372,5 @@ Get sub-generator `name`, using dot-notation for nested generators. | ||
* `name` **{String}**: The property-path of the generator to get | ||
* `aliasFn` **{Function}** | ||
* `aliasFn` **{Function}** | ||
### [.findGenerator](index.js#L307) | ||
### [.findGenerator](index.js#L308) | ||
@@ -384,6 +384,6 @@ Find generator `name`, by first searching the cache, | ||
* `name` **{String}** | ||
* `aliasFn` **{Function}**: Optionally supply a rename function. | ||
* `returns` **{Object|undefined}**: Returns the generator instance if found, or undefined. | ||
* `options` **{Function}**: Optionally supply a rename function on `options.toAlias` | ||
* `returns` **{Object|undefined}**: Returns the generator instance if found, or undefined. | ||
### [.globalGenerator](index.js#L355) | ||
### [.globalGenerator](index.js#L356) | ||
@@ -396,6 +396,5 @@ Search for globally installed generator `name`. If found, then generator | ||
* `name` **{String}** | ||
* `returns` **{Object|undefined}** | ||
* `returns` **{Object|undefined}** | ||
### [.invoke](index.js#L383) | ||
### [.invoke](index.js#L384) | ||
Invoke the given generator in the context of (`this`) the current instance. | ||
@@ -414,3 +413,3 @@ | ||
### [.extendWith](index.js#L420) | ||
### [.extendWith](index.js#L421) | ||
@@ -435,3 +434,3 @@ Alias for `.invoke`, Extend the current generator instance with the settings of other generators. | ||
### [.generate](index.js#L458) | ||
### [.generate](index.js#L459) | ||
@@ -474,3 +473,3 @@ Run a `generator` and `tasks`, calling the given `callback` function upon completion. | ||
### [.generateEach](index.js#L539) | ||
### [.generateEach](index.js#L540) | ||
@@ -494,3 +493,3 @@ Iterate over an array of generators and tasks, calling [generate](#generate) on each. | ||
### [.alias](index.js#L563) | ||
### [.alias](index.js#L577) | ||
@@ -505,3 +504,3 @@ Create a generator alias from the given `name`. | ||
### [.fullname](index.js#L583) | ||
### [.fullname](index.js#L595) | ||
@@ -516,3 +515,3 @@ Create a generator's full name from the given `alias`. | ||
### [.resolveConfigpath](index.js#L600) | ||
### [.resolveConfigpath](index.js#L612) | ||
@@ -527,3 +526,3 @@ Return the absolute filepath to a generator's main file. | ||
### [.configname](index.js#L618) | ||
### [.configname](index.js#L630) | ||
@@ -533,3 +532,3 @@ Getter/setter for defining the `configname` name to use for lookups. | ||
### [.configfile](index.js#L640) | ||
### [.configfile](index.js#L652) | ||
@@ -539,3 +538,3 @@ Getter/setter for defining the `configfile` name to use for lookups. | ||
### [.configpath](index.js#L658) | ||
### [.configpath](index.js#L670) | ||
@@ -545,3 +544,3 @@ Getter/setter for defining the `configpath` name to use for lookups. | ||
### [.modulename](index.js#L676) | ||
### [.modulename](index.js#L688) | ||
@@ -551,3 +550,3 @@ Getter/setter for defining the `modulename` name to use for lookups. | ||
### [.base](index.js#L703) | ||
### [.base](index.js#L715) | ||
@@ -582,3 +581,3 @@ Getter/setter for the `base` (or shared) instance of `generate`. | ||
* [base-pipeline](https://www.npmjs.com/package/base-pipeline): base-methods plugin that adds pipeline and plugin methods for dynamically composing streaming plugin pipelines. | [homepage](https://github.com/jonschlinkert/base-pipeline) | ||
* [base-plugins](https://www.npmjs.com/package/base-plugins): Upgrade's plugin support in base-methods to allow plugins to be called any time after init. | [homepage](https://github.com/jonschlinkert/base-plugins) | ||
* [base-plugins](https://www.npmjs.com/package/base-plugins): Upgrade's plugin support in base applications to allow plugins to be called any time after… [more](https://www.npmjs.com/package/base-plugins) | [homepage](https://github.com/jonschlinkert/base-plugins) | ||
* [base-task](https://www.npmjs.com/package/base-task): base plugin that provides a very thin wrapper around [https://github.com/doowb/composer](https://github.com/doowb/composer) for adding task methods to… [more](https://www.npmjs.com/package/base-task) | [homepage](https://github.com/node-base/base-task) | ||
@@ -628,2 +627,2 @@ * [composer](https://www.npmjs.com/package/composer): API-first task runner with three methods: task, run and watch. | [homepage](https://github.com/doowb/composer) | ||
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on February 23, 2016._ | ||
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on March 02, 2016._ |
60550
1295
611
Updatedarr-union@^3.1.0
Updatedbase-plugins@^0.4.4