Notify the user if there is an available update

For this we use the `update-notifier` module with its default settings.

This module will print a nice banner prompting the user to run the
corresponding npm command to update.
This commit is contained in:
Juan Cruz Viotti 2015-08-18 08:53:06 -04:00
parent d6305df48e
commit f19588032f
5 changed files with 43 additions and 1 deletions

View File

@ -1,5 +1,5 @@
(function() {
var _, actions, async, capitano, errors, plugins, resin;
var _, actions, async, capitano, errors, plugins, resin, update;
_ = require('lodash');
@ -15,6 +15,8 @@
plugins = require('./plugins');
update = require('./utils/update');
capitano.permission('user', function(done) {
return resin.auth.isLoggedIn().then(function(isLoggedIn) {
if (!isLoggedIn) {
@ -100,6 +102,8 @@
capitano.command(actions.plugin.remove);
update.notify();
async.waterfall([
function(callback) {
return plugins.register('resin-plugin-', callback);

23
build/utils/update.js Normal file
View File

@ -0,0 +1,23 @@
(function() {
var notifier, packageJSON, updateNotifier;
updateNotifier = require('update-notifier');
packageJSON = require('../../package.json');
notifier = updateNotifier({
pkg: packageJSON
});
exports.hasAvailableUpdate = function() {
return notifier != null;
};
exports.notify = function() {
if (!exports.hasAvailableUpdate()) {
return;
}
return notifier.notify();
};
}).call(this);

View File

@ -5,6 +5,7 @@ resin = require('resin-sdk')
actions = require('./actions')
errors = require('./errors')
plugins = require('./plugins')
update = require('./utils/update')
capitano.permission 'user', (done) ->
resin.auth.isLoggedIn().then (isLoggedIn) ->
@ -73,6 +74,8 @@ capitano.command(actions.plugin.install)
capitano.command(actions.plugin.update)
capitano.command(actions.plugin.remove)
update.notify()
async.waterfall([
(callback) ->

11
lib/utils/update.coffee Normal file
View File

@ -0,0 +1,11 @@
updateNotifier = require('update-notifier')
packageJSON = require('../../package.json')
notifier = updateNotifier(pkg: packageJSON)
exports.hasAvailableUpdate = ->
return notifier?
exports.notify = ->
return if not exports.hasAvailableUpdate()
notifier.notify()

View File

@ -62,6 +62,7 @@
"resin-vcs": "^2.0.0",
"selfupdate": "^1.1.0",
"underscore.string": "^3.1.1",
"update-notifier": "^0.5.0",
"valid-email": "0.0.2"
}
}