mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-20 03:36:44 +00:00
40 lines
880 B
JavaScript
40 lines
880 B
JavaScript
|
(function() {
|
||
|
var Nplugm, _, capitano, nplugm, registerPlugin;
|
||
|
|
||
|
Nplugm = require('nplugm');
|
||
|
|
||
|
_ = require('lodash');
|
||
|
|
||
|
capitano = require('capitano');
|
||
|
|
||
|
nplugm = null;
|
||
|
|
||
|
registerPlugin = function(plugin) {
|
||
|
if (!_.isArray(plugin)) {
|
||
|
return capitano.command(plugin);
|
||
|
}
|
||
|
return _.each(plugin, capitano.command);
|
||
|
};
|
||
|
|
||
|
exports.register = function(prefix, callback) {
|
||
|
nplugm = new Nplugm(prefix);
|
||
|
return nplugm.list(function(error, plugins) {
|
||
|
var i, len, plugin;
|
||
|
if (error != null) {
|
||
|
return callback(error);
|
||
|
}
|
||
|
for (i = 0, len = plugins.length; i < len; i++) {
|
||
|
plugin = plugins[i];
|
||
|
try {
|
||
|
registerPlugin(nplugm.require(plugin));
|
||
|
} catch (_error) {
|
||
|
error = _error;
|
||
|
console.error(error.message);
|
||
|
}
|
||
|
}
|
||
|
return callback();
|
||
|
});
|
||
|
};
|
||
|
|
||
|
}).call(this);
|