mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-08 20:04:14 +00:00
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:
parent
d6305df48e
commit
f19588032f
@ -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
23
build/utils/update.js
Normal 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);
|
@ -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
11
lib/utils/update.coffee
Normal 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()
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user