From 82ac558d7fb5cc4086f5583acdeecb4134b1fb00 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 12 Feb 2015 12:23:01 -0400 Subject: [PATCH] Implement plugin install command --- lib/actions/plugin.coffee | 41 +++++++++++++++++++++++++++++++++++---- lib/app.coffee | 1 + 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/lib/actions/plugin.coffee b/lib/actions/plugin.coffee index 5cb3a2ff..e23f587b 100644 --- a/lib/actions/plugin.coffee +++ b/lib/actions/plugin.coffee @@ -19,10 +19,6 @@ exports.list = (callback) -> npm.load - - # TODO: Maybe we should check the local modules as well? - global: true - depth: 0 parseable: true , callback @@ -36,6 +32,10 @@ exports.list = # TODO: Reuse plugin glob from app.coffee return _.str.startsWith(resinModule.name, 'resin-plugin') + if _.isEmpty(resinModules) + console.log('You don\'t have any plugins yet') + return done() + console.log visuals.widgets.table.horizontal resinModules, [ 'name' 'version' @@ -46,3 +46,36 @@ exports.list = return callback() ], done) + +exports.install = + signature: 'plugin install ' + description: 'install a plugin' + help: ''' + Use this command to install a resin plugin + + Examples: + $ resin plugin install hello + ''' + permission: 'user' + action: (params, options, done) -> + async.waterfall [ + + (callback) -> + npm.load({}, callback) + + (data, callback) -> + + # TODO: This action outputs installation information that cannot + # be quieted neither with --quiet nor --silent: + # https://github.com/npm/npm/issues/2040 + npm.commands.install([ + "resin-plugin-#{params.name}" + ], callback) + + ], (error) -> + return done() if not error? + + if error.code is 'E404' + error.message = "Plugin not found: #{params.name}" + + return done(error) if error? diff --git a/lib/app.coffee b/lib/app.coffee index 750dcf72..10a9867a 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -102,6 +102,7 @@ capitano.command(actions.examples.info) # ---------- Plugins Module ---------- capitano.command(actions.plugin.list) +capitano.command(actions.plugin.install) changeProjectDirectory = (directory) -> try