forked from millerbrands/soysaucejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrakefile.rb
304 lines (232 loc) · 8.15 KB
/
rakefile.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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/usr/bin/ruby
require "rake"
require "jammit"
require "yaml"
require "aws-sdk"
task :default => [:build]
task :build do
# Check if config exists
config_file = File.join(File.dirname(__FILE__), "/config/cdn.yml")
unless File.exist?(config_file)
abort("Soysauce: File '/config/cdn.yml' does not exist. Ask @egaba88 for the key or create your own. Aborting.")
end
# Create build directory
version = "v" + ENV["v"]
puts "Soysauce: Creating build " + version + "..."
if (!File.directory? "build")
Dir::mkdir("build")
end
if (!File.directory? "build/latest")
Dir::mkdir("build/latest")
end
begin
Dir::mkdir("build/" + version)
rescue
puts "Soysauce: " + version + " already exists. Overwriting..."
begin
FileUtils.rm_r "build/" + version, :force => true
Dir::mkdir("build/" + version)
rescue
abort("Soysauce: Unable to overwrite directory. Aborting.")
end
end
# Create soysauce.js, soysauce.min.js, and soysauce.css
puts "Soysauce: Compiling assets..."
bundleMutex = Mutex.new
bundleCompressed = Thread.new {
bundleMutex.synchronize do
Jammit.package!
end
}
bundleCompressed.join
bundleUncompressed = Thread.new {
bundleMutex.synchronize do
config = File.read("config/assets.yml")
config = config.gsub(/(compress_assets:\s+)on/, "\\1off")
config = config.gsub(/soysauce\.min/, "soysauce\\1")
File.rename("config/assets.yml", "config/assets2.yml")
File.open("config/assets.yml", "w") {
|file| file.write(config)
}
Jammit.package!
end
}
compileCSS = Thread.new {
system "compass compile"
}
bundleUncompressed.join
compileCSS.join
# Copy files to build directory
File.delete("config/assets.yml");
File.rename("config/assets2.yml", "config/assets.yml")
FileUtils.copy("public/soysauce.js.gz", "build/" + version + "/soysauce.js")
FileUtils.copy("public/soysauce.min.js.gz", "build/" + version + "/soysauce.min.js")
FileUtils.copy("public/soysauce.css", "build/" + version)
FileUtils.copy("public/soysauce.js.gz", "build/latest/soysauce.js")
FileUtils.copy("public/soysauce.min.js.gz", "build/latest/soysauce.min.js")
FileUtils.copy("public/soysauce.css", "build/latest")
# Publish to CDN
puts "Soysauce: Uploading to CDN..."
config = YAML.load(File.read(config_file))
unless config.kind_of?(Hash)
abort("Soysauce: File '/config/cdn.yml' is incorrectly configured. Aborting.")
end
AWS.config(config)
s3 = AWS::S3.new
bucket = s3.buckets["express-cdn"]
if !bucket.exists?
bucket = s3.buckets.create("express-cdn")
end
bucketMutex = Mutex.new
uploadCurrent = Thread.new {
Dir.foreach("build/" + version) do |file|
next if file == '.' or file == '..'
file_path = version + "/" + file
puts "Uploading soysauce/" + file_path + "..."
bucketMutex.synchronize do
o = bucket.objects["soysauce/" + file_path]
if File.extname(file) =~ /\.css/
o.write(:file => "build/" + file_path, :content_type => "text/css", :acl => :public_read)
else
o.write(:file => "build/" + file_path, :content_type => "text/javascript", :content_encoding => "gzip", :acl => :public_read)
end
end
end
}
updateLatest = Thread.new {
Dir.foreach("build/latest") do |file|
next if file == '.' or file == '..'
puts "Uploading soysauce/latest/" + file + "..."
bucketMutex.synchronize do
o = bucket.objects["soysauce/latest/" + file]
if File.extname(file) =~ /\.css/
o.write(:file => "build/latest/" + file, :content_type => "text/css", :acl => :public_read)
else
o.write(:file => "build/latest/" + file, :content_type => "text/javascript", :content_encoding => "gzip", :acl => :public_read)
end
end
end
}
uploadCurrent.join
updateLatest.join
# Update Readme
readme = File.read("README.md")
readme = readme.gsub(/v[\d\.]+/, version)
size = '%.2f' % (File.size("public/soysauce.min.js.gz").to_f / 1000)
readme = readme.gsub(/(Compressed \()[\d\.]+/, "\\1" + size)
size = '%.2f' % (File.size("public/soysauce.js.gz").to_f / 1000)
readme = readme.gsub(/(Uncompressed \()[\d\.]+/, "\\1" + size)
size = '%.2f' % (File.size("public/soysauce.css").to_f / 1000)
readme = readme.gsub(/(CSS \()[\d\.]+/, "\\1" + size)
File.open("README.md", "w") {
|file| file.write(readme)
}
# Update bower.json
bower = File.read("bower.json")
bower = bower.gsub(/"version":\s+"[\d\.]+"/, '"version": "' + ENV["v"] + '"')
File.open("bower.json", "w") {
|file| file.write(bower)
}
# Create build tag
pushTag = Thread.new {
puts "Soysauce: Pushing tag to github..."
system "git commit -am 'Creating build " + version + "'"
system "git tag -a " + version + " -m 'Creating build " + version + "' -f"
system "git push --tags -f"
system "git push origin master"
}
pushTag.join
puts "Soysauce: Build " + version + " successful!"
end
task :beta do
# Check if config exists
config_file = File.join(File.dirname(__FILE__), "/config/cdn.yml")
unless File.exist?(config_file)
abort("Soysauce: File '/config/cdn.yml' does not exist. Ask @egaba88 for the key or create your own. Aborting.")
end
# Create build directory
version = "v" + ENV["v"]
puts "Soysauce: Creating build " + version + "..."
if (!File.directory? "build")
Dir::mkdir("build")
end
if (!File.directory? "build/latest")
Dir::mkdir("build/latest")
end
begin
Dir::mkdir("build/" + version)
rescue
puts "Soysauce: " + version + " already exists. Overwriting..."
begin
FileUtils.rm_r "build/" + version, :force => true
Dir::mkdir("build/" + version)
rescue
abort("Soysauce: Unable to overwrite directory. Aborting.")
end
end
# Create soysauce.js, soysauce.min.js, and soysauce.css
puts "Soysauce: Compiling assets..."
bundleMutex = Mutex.new
bundleCompressed = Thread.new {
bundleMutex.synchronize do
Jammit.package!
end
}
bundleCompressed.join
bundleUncompressed = Thread.new {
bundleMutex.synchronize do
config = File.read("config/assets.yml")
config = config.gsub(/(compress_assets:\s+)on/, "\\1off")
config = config.gsub(/soysauce\.min/, "soysauce\\1")
File.rename("config/assets.yml", "config/assets2.yml")
File.open("config/assets.yml", "w") {
|file| file.write(config)
}
Jammit.package!
end
}
compileCSS = Thread.new {
system "compass compile"
}
bundleUncompressed.join
compileCSS.join
# Copy files to build directory
File.delete("config/assets.yml");
File.rename("config/assets2.yml", "config/assets.yml")
FileUtils.copy("public/soysauce.js.gz", "build/" + version + "/soysauce.js")
FileUtils.copy("public/soysauce.min.js.gz", "build/" + version + "/soysauce.min.js")
FileUtils.copy("public/soysauce.css", "build/" + version)
FileUtils.copy("public/soysauce.js.gz", "build/latest/soysauce.js")
FileUtils.copy("public/soysauce.min.js.gz", "build/latest/soysauce.min.js")
FileUtils.copy("public/soysauce.css", "build/latest")
# Publish to CDN
puts "Soysauce: Uploading to CDN..."
config = YAML.load(File.read(config_file))
unless config.kind_of?(Hash)
abort("Soysauce: File '/config/cdn.yml' is incorrectly configured. Aborting.")
end
AWS.config(config)
s3 = AWS::S3.new
bucket = s3.buckets["express-cdn"]
if !bucket.exists?
bucket = s3.buckets.create("express-cdn")
end
bucketMutex = Mutex.new
uploadCurrent = Thread.new {
Dir.foreach("build/" + version) do |file|
next if file == '.' or file == '..'
file_path = version + "/" + file
puts "Uploading soysauce/" + file_path + "..."
bucketMutex.synchronize do
o = bucket.objects["soysauce/" + file_path]
if File.extname(file) =~ /\.css/
o.write(:file => "build/" + file_path, :content_type => "text/css", :acl => :public_read)
else
o.write(:file => "build/" + file_path, :content_type => "text/javascript", :content_encoding => "gzip", :acl => :public_read)
end
end
end
}
uploadCurrent.join
puts "Soysauce: Build " + version + " successful!"
end