Created
January 30, 2012 15:30
-
-
Save youurayy/1704980 to your computer and use it in GitHub Desktop.
Script to search and print top-level module versions for NPM's package.json file (dependencies). Run in project root.
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
var fs = require('fs'); | |
var res = {}; | |
var base = process.cwd() + '/node_modules'; | |
var dirs = fs.readdirSync(base); | |
for(var i = 0; i < dirs.length; i++) { | |
var module = dirs[i]; | |
var bdir = base + '/' + module; | |
var cfg = bdir + '/package.json'; | |
var ok; | |
try { ok = fs.lstatSync(cfg).isFile(); } catch(e) {} | |
if(!ok) { | |
console.log('skipping: ' + bdir); | |
continue; | |
} | |
try { | |
var config = JSON.parse(fs.readFileSync(cfg)); | |
if(config.version) | |
res[module] = config.version; | |
else | |
console.log('No version information for module ' + module); | |
} | |
catch(e) { | |
console.log('error during parsing: ' + cfg, e.stack); | |
process.exit(1); | |
} | |
} | |
console.log(JSON.stringify(res, null, '\t')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requested to be added to NPM core: https://github.com/isaacs/npm/issues/2105