nesh
Version:
An enhanced, extensible shell for Node.js
82 lines (68 loc) • 2.3 kB
JavaScript
// Generated by CoffeeScript 1.11.1
/*
Autoloader Plugin
=================
Loads the list of plugins specified in ~/.nesh_config.js if it exists,
otherwise loads a default set of plugins or a passed-in set of plugins.
This plugin is loaded by default when the `nesh` command is executed
in a terminal.
Config options:
{
...
plugins: ['builtins', 'eval', ...],
pluginsExclude: ['foo']
...
}
*/
(function() {
var _, fs, nesh, path,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
_ = require('underscore');
fs = require('fs');
nesh = require('../nesh');
path = require('path');
exports.name = 'autoload';
exports.description = 'Loads a default list of plugins';
exports.setup = function(context, next) {
var already_errored, completed, config, defaultPlugins, defaults, i, len, plugin, results;
defaults = context.nesh.defaults;
nesh.log.debug('Loading plugin autoload');
defaultPlugins = ['builtins', 'eval', 'history', 'version', 'welcome', 'require', 'doc'];
config = nesh.config.get();
if (config.plugins != null) {
defaultPlugins = _(defaultPlugins.concat(config.plugins)).uniq();
}
if (config.pluginsExclude != null) {
defaultPlugins = _(defaultPlugins).reject(function(item) {
return indexOf.call(config.pluginsExclude, item) >= 0;
});
}
if (defaults.plugins == null) {
defaults.plugins = defaultPlugins;
}
completed = 0;
already_errored = false;
results = [];
for (i = 0, len = defaultPlugins.length; i < len; i++) {
plugin = defaultPlugins[i];
results.push((function(plugin) {
nesh.log.debug("Loading plugin " + plugin);
return nesh.loadPlugin(plugin, function(err) {
if (err) {
if (!already_errored) {
next("Error loading plugin " + plugin + ": " + err);
}
return already_errored = true;
} else {
completed += 1;
if (completed >= defaultPlugins.length) {
return next();
}
}
});
})(plugin));
}
return results;
};
}).call(this);
//# sourceMappingURL=autoload.js.map