Last active
August 29, 2015 13:57
-
-
Save shaharke/9843340 to your computer and use it in GitHub Desktop.
Outputs all outdated node.js packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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