Last active
July 1, 2018 08:55
-
-
Save zprima/f1f845a916f25c5ad79546051bda1a6d to your computer and use it in GitHub Desktop.
Ruby script to remove npm modules globally
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
File.open("li.txt", "w") | |
File.truncate("li.txt", 0) | |
system("npm -g ls | grep -v 'npm@' | awk '/@/ {print $2}' | awk -F@ '{print $1}' >> li.txt") | |
npm_modules = [] | |
File.open("li.txt").each do |line| | |
next if line.start_with?('│') || line.start_with?('├') || line.start_with?('└') | |
npm_modules << line | |
end | |
puts "Listing npm modules" | |
puts npm_modules | |
puts "------------------" | |
puts "Removing npm modules" | |
npm_modules.each do |mod| | |
cmd = "npm -g uninstall #{mod}" | |
puts "#{cmd}" | |
system(cmd) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment