is-valid-app
Version:
Wrapper around is-valid-instance and is-registered for validating `base` plugins. Returns true if `app` is a valid instance of base and a plugin is not registered yet.
32 lines (25 loc) • 836 B
JavaScript
/*!
* is-valid-app <https://github.com/node-base/is-valid-app>
*
* Copyright (c) 2016-2017, Jon Schlinkert.
* Released under the MIT License.
*/
;
var utils = require('./utils');
module.exports = function(app, name, types) {
if (typeof name !== 'string') {
throw new TypeError('expected plugin name to be a string');
}
// if `app` is not a valid instance of `Base`, or if `app` is a valid
// instance of Base by not one of the given `types` return false
if (!utils.isValid(app, types)) {
return false;
}
// if the `name` has already been registered as a plugin, return false
if (utils.isRegistered(app, name)) {
return false;
}
var debug = utils.debug('base:generate:' + name);
debug('initializing from <%s>', (module.parent && module.parent.id) || __dirname);
return true;
};