-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathie9build
executable file
·233 lines (172 loc) · 5.51 KB
/
ie9build
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env ruby
require 'ftools'
require 'fileutils'
require 'rubygems'
require 'RMagick'
include Magick
require 'open3'
def merge( files = [] )
merged_file = ""
files.each do |file|
File.open( file, "r") { |f|
merged_file += f.read + "\n"
}
end
merged_file
end
def minify( string = '', type = 'js' )
cmd = "java -jar bin/yuicompressor-2.4.2.jar --type #{type}"
stdin, stdout, stderr = Open3.popen3( cmd )
stdin.write string
stdin.close
stdout.read
end
def minify_to_file( string, type, output )
cmd = "java -jar bin/yuicompressor-2.4.2.jar -v --type #{type} -o #{output} --charset utf-8"
# puts cmd
stdin, stdout, stderr = Open3.popen3( cmd )
stdin.write string
stdin.close
puts stderr.read
end
def string2png( string, output )
image = Magick::Image.new 1,string.length
for i in 0 .. string.length
color = '#%02X0000' % string[i]
pixel = Magick::Pixel.from_color color
image.pixel_color 0, i, pixel
end
image.compression = ZipCompression
image.write("png8:"+ output)
image = nil
end
def png2string(image)
string = ''
Image.read(File.open( image, "r" )).first.each_pixel do |px,x,y|
string += (px.red % 256).chr
end
string
end
def string2pngs( string, output )
puts "original string length #{string.length}"
limit = 8192 #8192 # IE9 max for getImageData
images_count = (string.length * 1.0 / limit ).ceil
files = []
for i in 0 ... images_count
filename = output.split('.')
filename[ filename.length - 2 ] += i.to_s
filename = filename.join('.')
files << filename
from = i * limit
to = from + [ limit, string.length - from ].min
puts "output from #{from} to #{to}"
string2png string[from,to], filename
files << filename
end
# verify
# s = ''
# files.each{ |file| s += png2string(file) }
# raise ('invalid string, expecting ' + s + "\n\n---but got---\n\n " + string) unless s == string
# total_size = 0
# files.each{ |file| puts "#{"%-20.20s" % file} #{"%30s" % File.stat( file ).size}"; total_size += File.stat( file ).size }
# puts total_size
files
end
def pngout files = []
files.each do |file|
cmd = "bin/pngout #{file} -c2 -f3 -b128 -kbKGD -v"
puts `#{cmd}`
end
end
release_path = 'ie9'
# Clean up
puts "Clean up release folder (#{release_path})"
FileUtils.rm_rf release_path
File.makedirs release_path + '/img'
File.makedirs release_path + '/js'
files_to_copy = {
'index.ie9.html' => 'index.html',
# 'ie9fix.css' => 'ie9fix.css',
'img/dir.gif' => 'img/dir.gif',
'img/la.gif' => 'img/la.gif',
'img/la_h.gif' => 'img/la_h.gif',
'img/txt.gif' => 'img/txt.gif',
# 'img/dir.png' => 'img/dir.png',
# 'img/la.png' => 'img/la.png',
# 'img/la_h.png' => 'img/la_h.png',
# 'img/txt.png' => 'img/txt.png',
# 'javascripts/prototype.js' => 'prototype.js',
# 'javascripts/vendors/jsonp.js' => 'jsonp.js',
# 'javascripts/util.js' => 'util.js',
# 'javascripts/f.js' => 'f.js',
# 'javascripts/p.js' => 'p.js',
# 'javascripts/diff.js' => 'diff.js',
# 'javascripts/gh.js' => 'gh.js' ,
# 'javascripts/keyboard.js' => 'keyboard.js',
#
#
# 'javascripts/vendors/difflib.js' => 'difflib.js',
# 'javascripts/vendors/diffview.js' => 'diffview.js'
}
puts "Copy files"
files_to_copy.each do |src,dest|
dest = release_path + '/' + dest
puts " cp #{src} => #{dest}"
File.copy src, dest
end
js_files = [
'javascripts/vendors/jsonp.js',
'javascripts/util.js',
'javascripts/f.js',
'javascripts/p.js',
'javascripts/gh.js',
'javascripts/plugins/base.js',
# 'javascripts/diff.js',
'javascripts/keyboard.js',
# 'javascripts/plugins/resizeable_panel.js',
'javascripts/plugins/github_readme.js',
'javascripts/plugins/bookmarklet.js',
# 'javascripts/plugins/code_highlighter.js',
# 'javascripts/vendors/code_highlighter.js',
# 'javascripts/vendors/difflib.js',
# 'javascripts/vendors/diffview.js',
'javascripts/app.js'
]
puts "bundling js and css:"
puts " minifying js..."
js = minify merge( js_files )
puts " minifying css..."
css = minify(merge([
'styles.css',
# 'github_readme.css'
]), 'css')
puts " bundling..."
# string2png js + "~10K~" + css, release_path + '/c.png' # bundle both js + css into 1 image
code_pngs = string2pngs js + "~10K~" + css, release_path + '/js/c.png'
pngout code_pngs # further compress!
files_to_minify = [
{ :files => [ 'javascripts/bootstrap.js'], :output => 'js/bootstrap.js', :type => 'js' },
# { :files => [ 'ie9fix.css'], :output => 'ie9fix.css', :type => 'css' }
]
files_to_minify.each do |group|
puts "minify #{group[:output]}"
minify_to_file merge(group[:files]), group[:type], release_path + '/' + group[:output]
end
puts "------ Size Report ------"
files_to_skip_counting = [
'prototype.js',
'styles.css',
'img',
'js'
]
total_size = 0
Dir.glob( [release_path + '/*', release_path + '/img/*',release_path + '/js/*' ] ).each do |file|
# puts file
next if files_to_skip_counting.include? File.basename(file)
puts "#{"%-20.20s" % file} #{"%30s" % File.stat( file ).size}"
total_size += File.stat( file ).size
end
puts "Total size: #{total_size}"
puts "10K Limit: #{- total_size + 10240}"
#puts png2string( release_path + '/c.png')[-30,30]
# string2pngs js + "~10K~" + css, release_path + '/c.png'