Skip to content

Instantly share code, notes, and snippets.

@zprima
Last active July 1, 2018 08:55
Show Gist options
  • Save zprima/f1f845a916f25c5ad79546051bda1a6d to your computer and use it in GitHub Desktop.
Save zprima/f1f845a916f25c5ad79546051bda1a6d to your computer and use it in GitHub Desktop.
Ruby script to remove npm modules globally
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