Skip to content

Instantly share code, notes, and snippets.

@shaharke
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shaharke/9843340 to your computer and use it in GitHub Desktop.
Save shaharke/9843340 to your computer and use it in GitHub Desktop.
Outputs all outdated node.js packages
#!/usr/bin/env node
var spawn = require('child_process').spawn
var outdated = spawn('npm', ['outdated']);
outdated.stdout.on('data', function (data) {
var out = data.toString();
var lines = out.split('\n');
if (lines.length > 1) {
lines = lines.slice(1);
var packages = [];
lines.forEach(function(line) {
if (line.length > 0) {
var parts = line.split(/\s+/);
var package = parts[0];
var current = parts[1];
var wanted = parts[2];
if (wanted != current) {
packages.push({name: package, current: current, wanted: wanted})
}
}
})
if (packages.length > 0) {
packages.forEach(function(p) {
console.log(p.name + '\t' + p.current + ' => ' + p.wanted);
})
process.exit(1);
} else {
process.exit(0);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment