Created
October 21, 2011 13:07
-
-
Save mklabs/1303805 to your computer and use it in GitHub Desktop.
npm script to automatically uninstall globally installed packages
This file contains hidden or 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 npm = require('npm'); | |
// simple npm script to automatically uninstall globally installed package | |
// | |
// Usage: [sudo] node npm-clean.js | |
// Or, maybe: npm start | |
// | |
// edit protecteds array below to disable uninstall on these packages | |
var protecteds = ['npm']; | |
npm.load({global: true}, function() { | |
npm.commands.ls([], true, function(e, data) { | |
if(e) throw e; | |
var deps = Object.keys(data.dependencies), | |
protecteds = ['npm']; | |
deps = deps.filter(function(dep) { | |
return !~protecteds.indexOf(dep); | |
}); | |
npm.commands.uninstall(deps, function(e) { | |
if(e) throw e; | |
}); | |
}); | |
}); |
This file contains hidden or 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
{ | |
"author": "mklabs", | |
"name": "npm-clean", | |
"description": "npm script to clean out globally installed package", | |
"version": "0.0.0", | |
"engines": { | |
"node": "~v0.4.12" | |
}, | |
"dependencies": { | |
"npm": "~1.0.99" | |
}, | |
"scripts": { | |
"start": "node npm-clean.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment