mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 05:37:51 +00:00
Implement self update functionality and notification
This commit is contained in:
parent
9038b76d73
commit
06020c0344
@ -26,10 +26,11 @@
|
||||
}, function(data, lite, callback) {
|
||||
var newVersion;
|
||||
if (_.isEmpty(data)) {
|
||||
return done(new Error('You are already running the latest version'));
|
||||
return callback(new Error('You are already running the latest version'));
|
||||
}
|
||||
newVersion = _.last(_.first(_.last(data)).split('@'));
|
||||
return console.info("Upgraded " + packageJSON.name + " to v" + newVersion + ".");
|
||||
console.info("Upgraded " + packageJSON.name + " to v" + newVersion + ".");
|
||||
return callback();
|
||||
}
|
||||
], done);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
var _, actions, async, capitano, changeProjectDirectory, errors, plugins, resin;
|
||||
var _, actions, async, capitano, changeProjectDirectory, errors, plugins, resin, update;
|
||||
|
||||
_ = require('lodash');
|
||||
|
||||
@ -15,6 +15,8 @@
|
||||
|
||||
plugins = require('./plugins');
|
||||
|
||||
update = require('./update');
|
||||
|
||||
capitano.permission('user', function(done) {
|
||||
return resin.auth.isLoggedIn(function(isLoggedIn) {
|
||||
if (!isLoggedIn) {
|
||||
@ -145,6 +147,8 @@
|
||||
|
||||
async.waterfall([
|
||||
function(callback) {
|
||||
return update.check(callback);
|
||||
}, function(callback) {
|
||||
return plugins.register('resin-plugin-', callback);
|
||||
}, function(callback) {
|
||||
var dataPrefix;
|
||||
|
37
build/update.js
Normal file
37
build/update.js
Normal file
@ -0,0 +1,37 @@
|
||||
(function() {
|
||||
var packageJSON, updateAction, updateNotifier;
|
||||
|
||||
updateNotifier = require('update-notifier');
|
||||
|
||||
packageJSON = require('../package.json');
|
||||
|
||||
updateAction = require('./actions/update');
|
||||
|
||||
exports.perform = function(callback) {
|
||||
return updateAction.update.action(null, null, callback);
|
||||
};
|
||||
|
||||
exports.notify = function(update) {
|
||||
if (!process.stdout.isTTY) {
|
||||
return;
|
||||
}
|
||||
return console.log("> Major update available: " + update.current + " -> " + update.latest + "\n> Run resin update to update.\n> Beware that a major release might introduce breaking changes.\n");
|
||||
};
|
||||
|
||||
exports.check = function(callback) {
|
||||
var notifier;
|
||||
notifier = updateNotifier({
|
||||
pkg: packageJSON
|
||||
});
|
||||
if (notifier.update == null) {
|
||||
return callback();
|
||||
}
|
||||
if (notifier.update.type === 'major') {
|
||||
exports.notify(notifier.update);
|
||||
return callback();
|
||||
}
|
||||
console.log("Performing " + notifier.update.type + " update, hold tight...");
|
||||
return exports.perform(callback);
|
||||
};
|
||||
|
||||
}).call(this);
|
@ -35,9 +35,11 @@ exports.update =
|
||||
|
||||
(data, lite, callback) ->
|
||||
if _.isEmpty(data)
|
||||
return done(new Error('You are already running the latest version'))
|
||||
return callback(new Error('You are already running the latest version'))
|
||||
|
||||
newVersion = _.last(_.first(_.last(data)).split('@'))
|
||||
console.info("Upgraded #{packageJSON.name} to v#{newVersion}.")
|
||||
|
||||
return callback()
|
||||
|
||||
], done)
|
||||
|
@ -5,6 +5,7 @@ resin = require('resin-sdk')
|
||||
actions = require('./actions')
|
||||
errors = require('./errors')
|
||||
plugins = require('./plugins')
|
||||
update = require('./update')
|
||||
|
||||
capitano.permission 'user', (done) ->
|
||||
resin.auth.isLoggedIn (isLoggedIn) ->
|
||||
@ -117,6 +118,9 @@ changeProjectDirectory = (directory) ->
|
||||
|
||||
async.waterfall([
|
||||
|
||||
(callback) ->
|
||||
update.check(callback)
|
||||
|
||||
(callback) ->
|
||||
plugins.register('resin-plugin-', callback)
|
||||
|
||||
|
26
lib/update.coffee
Normal file
26
lib/update.coffee
Normal file
@ -0,0 +1,26 @@
|
||||
updateNotifier = require('update-notifier')
|
||||
packageJSON = require('../package.json')
|
||||
updateAction = require('./actions/update')
|
||||
|
||||
exports.perform = (callback) ->
|
||||
updateAction.update.action(null, null, callback)
|
||||
|
||||
exports.notify = (update) ->
|
||||
return if not process.stdout.isTTY
|
||||
|
||||
console.log """
|
||||
> Major update available: #{update.current} -> #{update.latest}
|
||||
> Run resin update to update.
|
||||
> Beware that a major release might introduce breaking changes.\n
|
||||
"""
|
||||
|
||||
exports.check = (callback) ->
|
||||
notifier = updateNotifier(pkg: packageJSON)
|
||||
return callback() if not notifier.update?
|
||||
|
||||
if notifier.update.type is 'major'
|
||||
exports.notify(notifier.update)
|
||||
return callback()
|
||||
|
||||
console.log("Performing #{notifier.update.type} update, hold tight...")
|
||||
exports.perform(callback)
|
@ -63,6 +63,7 @@
|
||||
"progress-stream": "^0.5.0",
|
||||
"resin-cli-visuals": "resin-io/resin-cli-visuals",
|
||||
"resin-sdk": "^0.0.1",
|
||||
"underscore.string": "~2.4.0"
|
||||
"underscore.string": "~2.4.0",
|
||||
"update-notifier": "^0.3.1"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user