-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean
More file actions
executable file
·43 lines (36 loc) · 908 Bytes
/
clean
File metadata and controls
executable file
·43 lines (36 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby
require 'bytesize'
require 'fileutils'
require 'slop'
opts = Slop.parse do |o|
o.bool '-d', '--dry-run', "Don't actually rename anything", default: false
o.on '-h', '--help' do
puts o
exit
end
end
command = opts.arguments.shift
if command === "npm"
mods = Dir.glob("node_modules") + Dir.glob("*/node_modules")
puts opts.dry_run? ? "Will remove:" : "Removing:"
total = 0
mods.each do |dir|
size = %x(du -d 0 --si #{dir}).chomp.split("\t").first.strip
size += "B"
size.gsub("BB", "B")
bs = ByteSize.new(size)
total += bs.to_bytes
puts " #{bs} #{dir}"
unless opts.dry_run?
FileUtils.rm_rf dir
end
end
puts "Total: #{ByteSize.new(total)}"
puts "Done."
exit(0)
else
puts "
ERROR: Unknown command '#{command}'\n\n"
puts opts
exit 1
end