From 91a2453ebbf86273f7e079d2b2d6297dd4498d2e Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 24 Feb 2015 13:36:10 -0400 Subject: [PATCH] Make use of new nplug version --- lib/actions/plugin.coffee | 17 +++----- lib/app.coffee | 4 +- lib/plugins.coffee | 86 ++++++++------------------------------- package.json | 5 +-- 4 files changed, 28 insertions(+), 84 deletions(-) diff --git a/lib/actions/plugin.coffee b/lib/actions/plugin.coffee index d286243f..01f0b16b 100644 --- a/lib/actions/plugin.coffee +++ b/lib/actions/plugin.coffee @@ -14,7 +14,7 @@ exports.list = ''' permission: 'user' action: (params, options, done) -> - plugins.list 'resin-plugin-', (error, resinPlugins) -> + plugins.list (error, resinPlugins) -> return done(error) if error? if _.isEmpty(resinPlugins) @@ -41,12 +41,9 @@ exports.install = ''' permission: 'user' action: (params, options, done) -> - plugins.install "resin-plugin-#{params.name}", (error, installedModules) -> + plugins.install params.name, (error) -> return done(error) if error? - - for installedModule in installedModules - console.info("Plugin installed: #{installedModule}") - + console.info("Plugin installed: #{params.name}") return done() exports.remove = @@ -66,10 +63,8 @@ exports.remove = permission: 'user' action: (params, options, done) -> visuals.patterns.remove 'plugin', options.yes, (callback) -> - plugins.remove("resin-plugin-#{params.name}", callback) - , (error, uninstalledPlugin) -> + plugins.remove(params.name, callback) + , (error) -> return done(error) if error? - - console.info("Plugin removed: #{uninstalledPlugin}") - + console.info("Plugin removed: #{params.name}") return done() diff --git a/lib/app.coffee b/lib/app.coffee index 799fb6b9..bc4346cc 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -114,9 +114,9 @@ changeProjectDirectory = (directory) -> async.waterfall([ (callback) -> - plugins.register('resin-plugin-*', callback) + plugins.register('resin-plugin-', callback) - (loadedPlugins, callback) -> + (callback) -> dataPrefix = resin.settings.get('dataPrefix') resin.data.prefix.set(dataPrefix, callback) diff --git a/lib/plugins.coffee b/lib/plugins.coffee index 814cf3bf..d1227d7f 100644 --- a/lib/plugins.coffee +++ b/lib/plugins.coffee @@ -1,81 +1,31 @@ -async = require('async') -npm = require('npm') -nplugm = require('nplugm') +Nplugm = require('nplugm') _ = require('lodash') -_.str = require('underscore.string') capitano = require('capitano') +nplugm = null + 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 - -# TODO: Move all this npm interaction functionality to nplugm - -exports.install = (name, callback) -> - async.waterfall [ - - (callback) -> - npm.load(loglevel: 'silent', 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([ name ], callback) - - (installedModules, modules, lite, callback) -> - installedModules = _.map(installedModules, _.first) - return callback(null, installedModules) - - ], (error, installedModules) -> - return callback(null, installedModules) if not error? - - if error.code is 'E404' - error.message = "Plugin not found: #{params.name}" - +exports.register = (prefix, callback) -> + nplugm = new Nplugm(prefix) + nplugm.list (error, plugins) -> return callback(error) if error? -exports.remove = (name, callback) -> - async.waterfall([ + for plugin in plugins + try + registerPlugin(nplugm.require(plugin)) + catch error + console.error(error.message) - (callback) -> - npm.load(loglevel: 'silent', callback) + return callback() - (data, callback) -> - npm.commands.uninstall([ name ], callback) +exports.list = -> + nplugm.list.apply(nplugm, arguments) - (uninstalledPlugins, callback) -> - if _.isEmpty(uninstalledPlugins) - return callback(new Error("Plugin not found: #{name}")) - return callback(null, _.first(uninstalledPlugins)) +exports.install = -> + nplugm.install.apply(nplugm, arguments) - ], callback) - -exports.list = (prefix, callback) -> - async.waterfall([ - - (callback) -> - npm.load - depth: 0 - parseable: true - , callback - - (data, callback) -> - npm.commands.list([], true, callback) - - (data, lite, callback) -> - plugins = _.filter _.values(data.dependencies), (plugin) -> - - # TODO: Use node-glob - return _.str.startsWith(plugin.name, prefix) - - return callback(null, plugins) - - ], callback) +exports.remove = -> + nplugm.remove.apply(nplugm, arguments) diff --git a/package.json b/package.json index 9df3f9a0..4ebe5b05 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "url": "git@bitbucket.org:rulemotion/resin-cli.git" }, "preferGlobal": true, - "bundled_engine": "v0.12.0", + "bundled_engine": "v0.12.0", "man": [ "./man/resin.1", "./man/resin-completion.1", @@ -58,8 +58,7 @@ "lodash-contrib": "~241.4.14", "mkdirp": "~0.5.0", "node-binary": "^1.0.0", - "nplugm": "^1.0.1", - "npm": "^2.5.1", + "nplugm": "^2.0.0", "open": "0.0.5", "progress-stream": "^0.5.0", "resin-cli-visuals": "git+https://git@github.com/resin-io/resin-cli-visuals.git",