base-generators
Advanced tools
Comparing version 0.1.1 to 0.1.2
37
index.js
@@ -66,3 +66,3 @@ /*! | ||
this.define('generator', function(name, fn) { | ||
debug('generator: "%s"', name); | ||
debug('registering generator: "%s"', name); | ||
this.emit('generator', name); | ||
@@ -126,3 +126,2 @@ | ||
var fn = this.alias.bind(this); | ||
var names = name.split('.'); | ||
@@ -136,3 +135,3 @@ var app = this; | ||
if (typeof app === 'undefined') { | ||
app = this.base.generators.get(name); | ||
app = this.base.generators.get(name, fn); | ||
if (!app) break; | ||
@@ -224,2 +223,6 @@ } | ||
this.define('generate', function(name, tasks, cb) { | ||
if (Array.isArray(name)) { | ||
return this.generateEach(name, tasks); | ||
} | ||
var args = [].slice.call(arguments); | ||
@@ -269,4 +272,4 @@ cb = args.pop(); | ||
var args = task.split(':').concat(next); | ||
app.generate.apply(app, args); | ||
}, cb); | ||
this.generate.apply(this, args); | ||
}.bind(this), cb); | ||
}); | ||
@@ -300,10 +303,26 @@ | ||
function generatorError(err, app, name, cb) { | ||
if (!/Invalid/.test(err.message)) { | ||
return cb(err); | ||
var match = /Invalid task `(.*?)`/.exec(err.message); | ||
if (!match) return cb(err); | ||
var taskName = match[1]; | ||
if (~name.indexOf(':')) { | ||
var segs = name.split(':'); | ||
taskName = segs[1]; | ||
name = segs[0]; | ||
} | ||
var msg = 'Cannot find generator or task: "' + name + '"'; | ||
var cwd = app.get('options.argv.cwd'); | ||
var msg = 'Cannot find '; | ||
if (app.hasGenerator(name) && name !== taskName) { | ||
msg += 'task: "' + taskName + '" in generator'; | ||
} else if (app.hasGenerator(name)) { | ||
msg += 'task'; | ||
} else { | ||
msg += 'generator'; | ||
} | ||
msg += ': "' + name + '"'; | ||
var cwd = app.get('options.cwd'); | ||
if (cwd) msg += ' in "' + cwd + '/' + app.configfile + '"'; | ||
return cb(new Error(msg)); | ||
} |
@@ -47,3 +47,5 @@ 'use strict'; | ||
parent = parent || base; | ||
var generator; | ||
if (util.isObject(fn) && fn.isGenerator) { | ||
@@ -58,3 +60,3 @@ generator = fn; | ||
generator.define('parent', parent || base); | ||
generator.define('parent', parent); | ||
generator.isGenerator = true; | ||
@@ -64,2 +66,4 @@ generator.createEnv(name, base.options, fn); | ||
generator.namespace = (parent.namespace ? parent.namespace + '.' : '') + alias; | ||
Object.defineProperty(this, alias, { | ||
@@ -66,0 +70,0 @@ configurable: true, |
@@ -32,20 +32,21 @@ 'use strict'; | ||
if (!this.env) this.env = {}; | ||
var env = this.env; | ||
this.env.alias = utils.toAlias(name, opts); | ||
this.env.name = utils.toFullname(this.env.alias, { | ||
env.alias = utils.toAlias(name, opts); | ||
env.name = utils.toFullname(env.alias, { | ||
prefix: this.modulename || 'generate' | ||
}); | ||
this.name = this.env.alias; | ||
this.name = env.alias; | ||
debug('createEnv · name: "%s", alias: "%s"', name, this.env.alias); | ||
debug('createEnv · name: "%s", alias: "%s"', env.name, env.alias); | ||
if (typeof fn === 'string') { | ||
this.env.path = this.resolve(fn); | ||
env.path = this.resolve(fn); | ||
if (typeof this.env.path === 'undefined') { | ||
if (typeof env.path === 'undefined') { | ||
throw new Error('cannot find generator: ' + fn); | ||
} | ||
Object.defineProperty(this.env, 'fn', { | ||
Object.defineProperty(env, 'fn', { | ||
configurable: true, | ||
@@ -59,10 +60,10 @@ enumerable: true, | ||
} else if (typeof fn === 'function') { | ||
this.env.path = undefined; | ||
this.env.fn = fn; | ||
env.path = undefined; | ||
env.fn = fn; | ||
} | ||
debug('created: %j', this.env); | ||
return this.env; | ||
debug('created: %j', env); | ||
return env; | ||
}); | ||
}; | ||
}; |
@@ -10,2 +10,10 @@ 'use strict'; | ||
/** | ||
* Resolve generators and tasks to run | ||
* | ||
* @param {String|Array} `names` If names is an array, it must be task names, otherwise it can be a generator name or a task name. | ||
* @param {String|Array} `tasks` one or more tasks to run. | ||
* @return {Object} Returns an object with the `generator` to use and a `tasks` array. | ||
*/ | ||
this.define('resolveTasks', function(names, tasks) { | ||
@@ -23,3 +31,8 @@ var prop = this.stringifyTasks(names, tasks); | ||
res.tasks = segs[1] ? segs[1].split(',') : ['default']; | ||
} else if (this.hasGenerator('default')) { | ||
var gen = this.getGenerator('default'); | ||
return gen.resolveTasks(names, tasks); | ||
} | ||
return res; | ||
@@ -26,0 +39,0 @@ }); |
'use strict'; | ||
var path = require('path'); | ||
/** | ||
@@ -11,9 +9,7 @@ * Module dependencies | ||
var utils = require('lazy-cache')(require); | ||
/* eslint-disable no-native-reassign */ | ||
var fn = require; | ||
/* eslint-disable no-undef */ | ||
require = utils; | ||
/** | ||
* Lazily required module dependencies | ||
* Utils | ||
*/ | ||
@@ -20,0 +16,0 @@ |
{ | ||
"name": "base-generators", | ||
"description": "Adds project-generator support to your `base` application.", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"homepage": "https://github.com/jonschlinkert/base-generators", | ||
@@ -26,3 +26,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"base-cwd": "^0.1.1", | ||
"base-tasks": "^0.2.0", | ||
"base-tasks": "^0.3.0", | ||
"debug": "^2.2.0", | ||
@@ -38,2 +38,3 @@ "generator-util": "^0.1.1", | ||
"composer-runtimes": "^0.7.0", | ||
"generate-foo": "^0.1.1", | ||
"gulp": "^3.9.0", | ||
@@ -40,0 +41,0 @@ "gulp-eslint": "^1.1.1", |
# base-generators [](https://www.npmjs.com/package/base-generators) [](https://travis-ci.org/jonschlinkert/base-generators) | ||
> Add 'project generator' support to your `base` application. | ||
> Adds project-generator support to your `base` application. | ||
@@ -304,3 +304,3 @@ - [Install](#install) | ||
### [.invoke](index.js#L153) | ||
### [.invoke](index.js#L152) | ||
@@ -320,3 +320,3 @@ Invoke the given generator in the context of the current instance. | ||
### [.extendWith](index.js#L182) | ||
### [.extendWith](index.js#L181) | ||
@@ -341,3 +341,3 @@ Alias for `.invoke`, Extend the current generator instance with the settings of other generators. | ||
### [.generate](index.js#L220) | ||
### [.generate](index.js#L219) | ||
@@ -380,3 +380,3 @@ Run a `generator` and `tasks`, calling the given `callback` function upon completion. | ||
### [.generateEach](index.js#L254) | ||
### [.generateEach](index.js#L257) | ||
@@ -400,3 +400,3 @@ Iterate over an array of generators and tasks, calling [generate](#generate) on each. | ||
### [.alias](index.js#L279) | ||
### [.alias](index.js#L282) | ||
@@ -484,3 +484,3 @@ Create a generator alias from the given `name`. | ||
* [bach](https://www.npmjs.com/package/bach): Compose your async functions with elegance | [homepage](https://github.com/phated/bach) | ||
* [bach](https://www.npmjs.com/package/bach): Compose your async functions with elegance | [homepage](https://github.com/gulpjs/bach#readme) | ||
* [base](https://www.npmjs.com/package/base): base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://www.npmjs.com/package/base) | [homepage](https://github.com/node-base/base) | ||
@@ -491,3 +491,3 @@ * [base-fs](https://www.npmjs.com/package/base-fs): base-methods plugin that adds vinyl-fs methods to your 'base' application for working with the file… [more](https://www.npmjs.com/package/base-fs) | [homepage](https://github.com/jonschlinkert/base-fs) | ||
* [base-tasks](https://www.npmjs.com/package/base-tasks): base-methods plugin that provides a very thin wrapper around [https://github.com/jonschlinkert/composer](https://github.com/jonschlinkert/composer) for adding task methods to… [more](https://www.npmjs.com/package/base-tasks) | [homepage](https://github.com/jonschlinkert/base-tasks) | ||
* [composer](https://www.npmjs.com/package/composer): API-first task runner with three methods: task, run and watch. | [homepage](https://github.com/jonschlinkert/composer) | ||
* [composer](https://www.npmjs.com/package/composer): API-first task runner with three methods: task, run and watch. | [homepage](https://github.com/doowb/composer) | ||
* [gulp](https://www.npmjs.com/package/gulp): The streaming build system | [homepage](http://gulpjs.com) | ||
@@ -521,2 +521,2 @@ | ||
_This file was generated by [verb](https://github.com/verbose/verb) on January 28, 2016._ | ||
_This file was generated by [verb](https://github.com/verbose/verb) on January 29, 2016._ |
36814
625
13
22482
+ Addedbach@0.5.0(transitive)
+ Addedbase-tasks@0.3.0(transitive)
+ Addedco@4.6.0(transitive)
+ Addedcomposer@0.11.4(transitive)
+ Addedis-generator@1.0.3(transitive)
+ Addedlodash.filter@4.6.0(transitive)
+ Addedlodash.flatten@4.4.0(transitive)
+ Addedlodash.foreach@4.5.0(transitive)
+ Addedlodash.initial@4.1.1(transitive)
+ Addedlodash.last@3.0.0(transitive)
+ Addedlodash.map@4.6.0(transitive)
- Removedanymatch@1.3.2(transitive)
- Removedarr-diff@4.0.0(transitive)
- Removedarr-union@3.1.0(transitive)
- Removedarray-unique@0.3.2(transitive)
- Removedassign-symbols@1.0.0(transitive)
- Removedasync-each@1.0.6(transitive)
- Removedatob@2.1.2(transitive)
- Removedbach@0.4.2(transitive)
- Removedbase@0.11.2(transitive)
- Removedbase-tasks@0.2.0(transitive)
- Removedbinary-extensions@1.13.1(transitive)
- Removedbindings@1.5.0(transitive)
- Removedbraces@2.3.2(transitive)
- Removedcache-base@1.0.1(transitive)
- Removedchokidar@1.7.0(transitive)
- Removedclass-utils@0.3.6(transitive)
- Removedcollection-visit@1.0.0(transitive)
- Removedcomposer@0.10.0(transitive)
- Removedcopy-descriptor@0.1.1(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removeddefine-property@1.0.02.0.2(transitive)
- Removedexpand-brackets@2.1.4(transitive)
- Removedextend-shallow@3.0.2(transitive)
- Removedextglob@2.0.4(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
- Removedfill-range@4.0.0(transitive)
- Removedfragment-cache@0.2.1(transitive)
- Removedfsevents@1.2.13(transitive)
- Removedget-value@2.0.6(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-value@0.3.11.0.0(transitive)
- Removedhas-values@0.1.41.0.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-binary-path@1.0.1(transitive)
- Removedis-descriptor@1.0.3(transitive)
- Removedis-extendable@1.0.1(transitive)
- Removedis-number@3.0.0(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedisobject@3.0.1(transitive)
- Removedkind-of@4.0.0(transitive)
- Removedlodash@3.10.1(transitive)
- Removedmap-cache@0.2.2(transitive)
- Removedmap-visit@1.0.0(transitive)
- Removedmicromatch@3.1.10(transitive)
- Removedmixin-deep@1.3.2(transitive)
- Removednan@2.22.2(transitive)
- Removednanomatch@1.2.13(transitive)
- Removedobject-copy@0.1.0(transitive)
- Removedobject-visit@1.0.1(transitive)
- Removedobject.pick@1.3.0(transitive)
- Removedpascalcase@0.1.1(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedposix-character-classes@0.1.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedreaddirp@2.2.1(transitive)
- Removedregex-not@1.0.2(transitive)
- Removedresolve-url@0.2.1(transitive)
- Removedret@0.1.15(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedsafe-regex@1.1.0(transitive)
- Removedset-value@2.0.1(transitive)
- Removedsnapdragon@0.8.2(transitive)
- Removedsnapdragon-node@2.1.1(transitive)
- Removedsnapdragon-util@3.0.1(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedsource-map-resolve@0.5.3(transitive)
- Removedsource-map-url@0.4.1(transitive)
- Removedsplit-string@3.1.0(transitive)
- Removedstatic-extend@0.1.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedto-object-path@0.3.0(transitive)
- Removedto-regex@3.0.2(transitive)
- Removedto-regex-range@2.1.1(transitive)
- Removedunion-value@1.0.1(transitive)
- Removedunset-value@1.0.0(transitive)
- Removedurix@0.1.0(transitive)
- Removeduse@3.1.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updatedbase-tasks@^0.3.0