mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-11 23:43:18 +00:00
782c92885d
Using the NPM API led to weird issues. See https://github.com/npm/npm/issues/7723.
39 lines
950 B
JavaScript
39 lines
950 B
JavaScript
(function() {
|
|
var _, async, npm;
|
|
|
|
npm = require('npm');
|
|
|
|
async = require('async');
|
|
|
|
_ = require('lodash-contrib');
|
|
|
|
exports.getLatestVersion = function(name, callback) {
|
|
return async.waterfall([
|
|
function(callback) {
|
|
var options;
|
|
options = {
|
|
loglevel: 'silent',
|
|
global: true
|
|
};
|
|
return npm.load(options, _.unary(callback));
|
|
}, function(callback) {
|
|
return npm.commands.view([name], true, function(error, data) {
|
|
var versions;
|
|
versions = _.keys(data);
|
|
return callback(error, _.first(versions));
|
|
});
|
|
}
|
|
], callback);
|
|
};
|
|
|
|
exports.isUpdated = function(name, currentVersion, callback) {
|
|
return exports.getLatestVersion(name, function(error, latestVersion) {
|
|
if (error != null) {
|
|
return callback(error);
|
|
}
|
|
return callback(null, currentVersion === latestVersion);
|
|
});
|
|
};
|
|
|
|
}).call(this);
|