2015-03-04 18:03:08 +00:00
|
|
|
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) ->
|
2015-03-04 18:46:34 +00:00
|
|
|
npm.commands.update [ packageJSON.name ], (error, data) ->
|
|
|
|
return callback(error, data)
|
2015-03-04 18:03:08 +00:00
|
|
|
|
2015-03-04 18:46:34 +00:00
|
|
|
(data, callback) ->
|
2015-03-04 18:03:08 +00:00
|
|
|
if _.isEmpty(data)
|
2015-03-04 18:40:40 +00:00
|
|
|
return callback(new Error('You are already running the latest version'))
|
2015-03-04 18:03:08 +00:00
|
|
|
|
|
|
|
newVersion = _.last(_.first(_.last(data)).split('@'))
|
|
|
|
console.info("Upgraded #{packageJSON.name} to v#{newVersion}.")
|
|
|
|
|
2015-03-04 18:40:40 +00:00
|
|
|
return callback()
|
|
|
|
|
2015-03-04 18:03:08 +00:00
|
|
|
], done)
|