Refactor plugins logic into a new file

This commit is contained in:
Juan Cruz Viotti 2015-02-10 11:46:22 -04:00
parent f712064ab4
commit 8d99526a96
2 changed files with 16 additions and 8 deletions

View File

@ -5,6 +5,7 @@ resin = require('resin-sdk')
nplugm = require('nplugm')
actions = require('./actions')
errors = require('./errors')
plugins = require('./plugins')
capitano.permission 'user', (done) ->
resin.auth.isLoggedIn (isLoggedIn) ->
@ -100,20 +101,14 @@ capitano.command(actions.examples.list)
capitano.command(actions.examples.clone)
capitano.command(actions.examples.info)
registerPlugin = (plugin) ->
return capitano.command(plugin) if not _.isArray(plugin)
return _.each(plugin, capitano.command)
changeProjectDirectory = (directory) ->
try
process.chdir(directory)
catch
errors.handle(new Error("Invalid project: #{directory}"))
nplugm.load 'resin-plugin-*', (error, plugin) ->
return console.error(error.message) if error?
registerPlugin(plugin.require())
, (error, loadedPlugins) ->
plugins.register 'resin-plugin-*', (error, loadedPlugins) ->
errors.handle(error) if error?
cli = capitano.parse(process.argv)

13
lib/plugins.coffee Normal file
View File

@ -0,0 +1,13 @@
nplugm = require('nplugm')
_ = require('lodash')
capitano = require('capitano')
registerPlugin = (plugin) ->
return capitano.command(plugin) if not _.isArray(plugin)
return _.each(plugin, capitano.command)
exports.register = (glob, callback) ->
nplugm.load glob, (error, plugin) ->
return console.error(error.message) if error?
registerPlugin(plugin.require())
, callback