/
rakefile
319 lines (273 loc) · 8.28 KB
/
rakefile
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# coding: utf-8
BASE_PORT = 4101
MIN_NPM_VERSION = "1.1.18"
MIN_GEM_VERSION = "1.8.23"
LOCAL_DOMAIN = "binaryage.org"
ROOT = File.expand_path('.')
WWW = File.join(ROOT, 'www')
BLOG = File.join(ROOT, 'blog')
SUPPORT = File.join(ROOT, 'support')
TOTALFINDER = File.join(ROOT, 'totalfinder-web')
TOTALTERMINAL = File.join(ROOT, 'totalterminal-web')
TOTALSPACES = File.join(ROOT, 'totalspaces-web')
ASEPSIS = File.join(ROOT, 'asepsis-web')
VISOR = File.join(ROOT, 'visor')
FIREQUERY = File.join(ROOT, 'firequery')
FIRERAINBOW = File.join(ROOT, 'firerainbow')
FIRELOGGER = File.join(ROOT, 'firelogger')
DRYDROP = File.join(ROOT, 'drydrop')
XREFRESH = File.join(ROOT, 'xrefresh')
HINTS = File.join(ROOT, 'hints')
RESTATIC = File.join(ROOT, 'restatic-web')
def subdomain(path)
name = (path.split("/"))[-1] # get last component of the path
name.split("-")[0] # strips -web postfixes
end
$master = WWW # this repo will hold real submodules _layouts and shared, slaves will hard-link them
$slaves = [BLOG, SUPPORT, VISOR, TOTALFINDER, TOTALSPACES, FIREQUERY, FIRELOGGER, FIRERAINBOW, DRYDROP, XREFRESH, TOTALTERMINAL, ASEPSIS, HINTS, RESTATIC]
$all = [$master].concat $slaves
$all_domains = $all.collect {|x| subdomain(x)}
require 'json'
begin
require 'term/ansicolor'
include Term::ANSIColor
rescue LoadError
raise 'Run "gem install term-ansicolor"'
end
def file_color(text); yellow(text); end
def dir_color(text); blue(text); end
def cmd_color(text); green(text); end
def die(msg, code=1)
puts red(msg)
exit(code)
end
def sys(cmd)
puts blue("> "+cmd)
system(cmd)
end
def port_for_domain(domain)
BASE_PORT + $all_domains.index(domain)
end
def path_for_domain(domain)
$all[$all_domains.index(domain)]
end
def require_rmagick!
begin
require 'rmagick'
include Magick
rescue LoadError
raise 'You must "sudo gem install rmagick"'
end
end
################################################################################
desc "install npm dependencies"
task :init_npm do
die "install npm (>=v#{MIN_NPM_VERSION}) => http://npmjs.org" unless Gem::Version.new(`npm --version`) >= Gem::Version.new(MIN_NPM_VERSION)
sys("npm install")
end
desc "install gem dependencies"
task :init_gem do
die "install rubygems (>=v#{MIN_GEM_VERSION}, no sudo, consider rvm) => http://rubygems.org, http://beginrescueend.com" unless Gem::Version.new(`gem --version`) >= Gem::Version.new(MIN_GEM_VERSION)
sys("gem install term-ansicolor")
end
desc "init repositories - needs special care"
task :init => [:init_gem, :init_npm] do
sys("git submodule update --init")
# cleanup subsubmodules
$slaves.each do |slave|
["_layouts", "shared"].each do |submodule|
sys("rm -rf \"#{slave}/#{submodule}\"")
end
end
# download _layouts and shared submodule into master repo
Dir.chdir($master) do
sys("git checkout gh-pages")
sys("git submodule update --init --recursive")
end
# for each slave, "symlink" _layouts and shared submodule from master repo
$slaves.each do |slave|
Dir.chdir(slave) do
sys("git checkout gh-pages")
sys("git submodule init")
end
["_layouts", "shared"].each do |submodule|
sys("./.bin/hlink/hlink \"#{$master}/#{submodule}\" \"#{slave}/#{submodule}\"")
end
end
end
desc "prints info how to setup /etc/hosts"
task :hosts do
puts "add this section into your /etc/hosts:"
puts
puts "#### #{LOCAL_DOMAIN} test site ####"
$all_domains.each do |domain|
puts "127.0.0.1 #{domain}.#{LOCAL_DOMAIN}"
end
puts "#### #{LOCAL_DOMAIN} test site ####"
end
desc "generate proxy config"
task :proxy_config do
hash = {
"host" => "localhost",
"port" => 80,
"hostnameOnly" => true,
"router" => {
}
}
$all_domains.each do |domain|
port = port_for_domain(domain)
hash["router"]["#{domain}.#{LOCAL_DOMAIN}"] = "127.0.0.1:#{port}"
end
puts JSON.pretty_generate(hash)
end
desc "run dev server"
task :serve do
puts "note: make sure you have /etc/hosts properly configured, see> rake hosts"
what = (ENV["what"] || $all_domains.join(",")).split(",")
# run stylus
sys("cd \"#{WWW}/shared/css\" && \"#{ROOT}/node_modules/.bin/stylus\" -w site2.styl &")
sleep 2
# run jekyll sites
$all_domains.each do |domain|
path = path_for_domain(domain)
port = port_for_domain(domain)
sys("cd \"#{path}\" && jekyll --auto --server #{port} --url http://#{domain}.#{LOCAL_DOMAIN} &") if what.include?(domain)
end
sleep 8
# run reverse proxy
sys("rake proxy_config > .proxy.config")
puts "Launching proxy server on port 80 (root needed)"
sys("sudo ./node_modules/.bin/node-http-proxy --config .proxy.config &")
# wait for signal and instantly kill all ofsprings
# http://autonomousmachine.com/posts/2011/6/2/cleaning-up-processes-in-ruby
trap("INT") do
Process.kill('INT', -Process.getpgrp)
exit
end
puts "=> www.#{LOCAL_DOMAIN}, use CTRL^C to kill all"
sleep
end
desc "force github pages update"
task :force do
$slaves.each do |path|
puts path
layouts = File.join(path, "_layouts")
shared = File.join(path, "shared")
Dir.chdir(path) do
`touch _force_github_pages_update_the_site`
`git add .`
`git commit -m "force github pages update the site"`
`git push`
end
end
end
desc "update layouts and shared"
task :update do
$slaves.each do |path|
puts path
Dir.chdir(path) do
`git add .`
`git commit -m "update submodules to latest version with Mark's changes"`
end
end
end
desc "push all"
task :push do
$all.each do |path|
puts path
Dir.chdir(path) do
`git push`
end
end
end
desc "adhoc multiop"
task :do do
# better use: git submodule foreach 'cmds'
$slaves.each do |path|
puts path
Dir.chdir(path) do
`git add .`
`git commit -m "update submodules"`
end
end
end
desc "convert pngs to loseless jpgs"
task :strip do
require_rmagick!
Dir.glob(File.join(WWW, 'shared', "img", "*.png")) do |file|
next unless file =~ /body-repeat/
puts file
image = ImageList.new(file)
image.strip!
image.write(file) #{ self.quality = 100; }
end
end
desc "convert pngs to loseless jpgs"
task :print do
require_rmagick!
Dir.glob(File.join(WWW, 'shared', "img", "*.png")) do |file|
next unless file =~ /tabs-background/
puts file
img = Magick::Image::read(file).first
puts " Format: #{img.format}"
puts " Geometry: #{img.columns}x#{img.rows}"
puts " Class: " + case img.class_type
when Magick::DirectClass
"DirectClass"
when Magick::PseudoClass
"PseudoClass"
end
puts " Depth: #{img.depth} bits-per-pixel"
puts " Colors: #{img.number_colors}"
puts " Filesize: #{img.filesize}"
puts " Resolution: #{img.x_resolution.to_i}x#{img.y_resolution.to_i} "+"pixels/#{img.units == Magick::PixelsPerInchResolution ? "inch" : "centimeter"}"
if img.properties.length > 0
puts " Properties:"
img.properties { |name,value| puts %Q| #{name} = "#{value}"| }
end
end
end
desc "convert icons to other formats"
task :icons do
require_rmagick!
Dir.glob(File.join(WWW, 'shared', "img", "icons", "leechgate-512.png")) do |file|
puts file
image = ImageList.new(file)
file64 = file.gsub('512', '64')
image64 = image.resize(64, 64)
image64.write(file64)
file128 = file.gsub('512', '128')
image128 = image.resize(128, 128)
image128.write(file128)
file256 = file.gsub('512', '256')
image256 = image.resize(256, 256)
image256.write(file256)
file512white = file.gsub('512', '512-white')
bg = Image.new(image.columns, image.rows) {
self.background_color = "white"
}
bg = bg.composite(image, CenterGravity, OverCompositeOp)
bg.write(file512white)
file256white = file.gsub('512', '256-white')
bg = Image.new(image.columns, image.rows) {
self.background_color = "white"
}
bg = bg.composite(image, CenterGravity, OverCompositeOp)
bg = bg.resize(256, 256)
bg.write(file256white)
end
end
desc "optimize png images"
task :optimize do
Dir.glob(File.join(WWW, 'shared', "**", "*.png")) do |file|
puts file
`optipng −i1 −o7 "#{file}"`
break
end
Dir.glob(File.join(WWW, 'images', "**", "*.png")) do |file|
puts file
`optipng −i1 −o7 "#{file}"`
break
end
end
task :default => :serve