From 9038b76d73d779977192dbb0652ccc61f5835f52 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 4 Mar 2015 14:03:08 -0400 Subject: [PATCH] Implement resin update command --- build/actions/index.js | 3 ++- build/actions/update.js | 38 ++++++++++++++++++++++++++++++++++ build/app.js | 2 ++ doc/update/update.md | 10 +++++++++ lib/actions/index.coffee | 1 + lib/actions/update.coffee | 43 +++++++++++++++++++++++++++++++++++++++ lib/app.coffee | 3 +++ package.json | 1 + 8 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 build/actions/update.js create mode 100644 doc/update/update.md create mode 100644 lib/actions/update.coffee diff --git a/build/actions/index.js b/build/actions/index.js index d15e7349..23e87e63 100644 --- a/build/actions/index.js +++ b/build/actions/index.js @@ -13,7 +13,8 @@ os: require('./os'), help: require('./help'), examples: require('./examples'), - plugin: require('./plugin') + plugin: require('./plugin'), + update: require('./update') }; }).call(this); diff --git a/build/actions/update.js b/build/actions/update.js new file mode 100644 index 00000000..fb589023 --- /dev/null +++ b/build/actions/update.js @@ -0,0 +1,38 @@ +(function() { + var _, async, npm, packageJSON; + + async = require('async'); + + _ = require('lodash-contrib'); + + npm = require('npm'); + + packageJSON = require('../../package.json'); + + exports.update = { + signature: 'update', + description: 'update the resin cli', + help: 'Use this command to update the Resin CLI\n\nThis command outputs information about the update process.\nUse `--quiet` to remove that output.\n\nExamples:\n\n $ resin update', + action: function(params, options, done) { + return async.waterfall([ + function(callback) { + options = { + loglevel: 'silent', + global: true + }; + return npm.load(options, _.unary(callback)); + }, function(callback) { + return npm.commands.update([packageJSON.name], callback); + }, function(data, lite, callback) { + var newVersion; + if (_.isEmpty(data)) { + return done(new Error('You are already running the latest version')); + } + newVersion = _.last(_.first(_.last(data)).split('@')); + return console.info("Upgraded " + packageJSON.name + " to v" + newVersion + "."); + } + ], done); + } + }; + +}).call(this); diff --git a/build/app.js b/build/app.js index e953ae57..c2ed822d 100644 --- a/build/app.js +++ b/build/app.js @@ -133,6 +133,8 @@ capitano.command(actions.plugin.remove); + capitano.command(actions.update.update); + changeProjectDirectory = function(directory) { try { return process.chdir(directory); diff --git a/doc/update/update.md b/doc/update/update.md new file mode 100644 index 00000000..c76981ff --- /dev/null +++ b/doc/update/update.md @@ -0,0 +1,10 @@ +# update + +Use this command to update the Resin CLI + +This command outputs information about the update process. +Use `--quiet` to remove that output. + +Examples: + + $ resin update diff --git a/lib/actions/index.coffee b/lib/actions/index.coffee index ee2ce1ab..cd3f234b 100644 --- a/lib/actions/index.coffee +++ b/lib/actions/index.coffee @@ -13,3 +13,4 @@ module.exports = help: require('./help') examples: require('./examples') plugin: require('./plugin') + update: require('./update') diff --git a/lib/actions/update.coffee b/lib/actions/update.coffee new file mode 100644 index 00000000..2eafbe95 --- /dev/null +++ b/lib/actions/update.coffee @@ -0,0 +1,43 @@ +async = require('async') +_ = require('lodash-contrib') +npm = require('npm') +packageJSON = require('../../package.json') + +exports.update = + signature: 'update' + description: 'update the resin cli' + help: ''' + Use this command to update the Resin CLI + + This command outputs information about the update process. + Use `--quiet` to remove that output. + + Examples: + + $ resin update + ''' + action: (params, options, done) -> + async.waterfall([ + + (callback) -> + options = + + # TODO: There is no way to quiet npm install completely. + # Some output is still shown once the module is updated + # https://github.com/npm/npm/issues/2040 + loglevel: 'silent' + global: true + + npm.load(options, _.unary(callback)) + + (callback) -> + npm.commands.update([ packageJSON.name ], callback) + + (data, lite, callback) -> + if _.isEmpty(data) + return done(new Error('You are already running the latest version')) + + newVersion = _.last(_.first(_.last(data)).split('@')) + console.info("Upgraded #{packageJSON.name} to v#{newVersion}.") + + ], done) diff --git a/lib/app.coffee b/lib/app.coffee index 9ac8d767..12bf90cd 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -106,6 +106,9 @@ capitano.command(actions.plugin.install) capitano.command(actions.plugin.update) capitano.command(actions.plugin.remove) +# ---------- Update Module ---------- +capitano.command(actions.update.update) + changeProjectDirectory = (directory) -> try process.chdir(directory) diff --git a/package.json b/package.json index 041e6627..66b6fcd9 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "lodash-contrib": "~241.4.14", "mkdirp": "~0.5.0", "nplugm": "^2.1.0", + "npm": "^2.6.1", "open": "0.0.5", "progress-stream": "^0.5.0", "resin-cli-visuals": "resin-io/resin-cli-visuals",