forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_file_sizes.rb
43 lines (34 loc) · 893 Bytes
/
list_file_sizes.rb
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
files = Dir["packages/ember-*/lib/**/*.js"] - Dir["packages/ember-runtime/**/*.js"]
files = Dir["packages/ember-{metal,views,handlebars}/lib/**/*.js"]
def uglify(string)
IO.popen("uglifyjs", "r+") do |io|
io.puts string
io.close_write
return io.read
end
end
def gzip(string)
IO.popen("gzip -f", "r+") do |io|
io.puts string
io.close_write
return io.read
end
end
all_files = ""
sizes = []
files.each do |file|
this_file = File.read(file)
all_files += this_file
size = this_file.size
uglified = uglify(this_file)
gzipped = gzip(uglified)
sizes << [size, uglified.size, gzipped.size, file]
end
# HEADER
puts " RAW MIN MIN+GZ"
sizes.sort{|a,b| b[2] <=> a[2] }.each do |size|
puts "%8d %8d %8d - %s" % size
end
uglified = uglify(all_files)
gzipped = gzip(uglified)
puts "%8d %8d %8d" % [all_files.size, uglified.size, gzipped.size]