balena-cli/lib/npm.coffee
Juan Cruz Viotti 782c92885d Use child_process to trigger self update
Using the NPM API led to weird issues.

See https://github.com/npm/npm/issues/7723.
2015-03-24 08:44:02 -04:00

30 lines
788 B
CoffeeScript

npm = require('npm')
async = require('async')
_ = require('lodash-contrib')
exports.getLatestVersion = (name, callback) ->
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.view [ name ], true, (error, data) ->
versions = _.keys(data)
return callback(error, _.first(versions))
], callback)
exports.isUpdated = (name, currentVersion, callback) ->
exports.getLatestVersion name, (error, latestVersion) ->
return callback(error) if error?
return callback(null, currentVersion is latestVersion)