/
Rakefile
65 lines (51 loc) · 1.53 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
require 'rake'
require 'rake/clean'
# You need this: http://code.google.com/closure/compiler/
COMPILER = 'closure' # --compilation_level ADVANCED_OPTIMIZATIONS'
CLEAN.include('system/miniLOL.min.js')
def minify (file, out=nil)
if !File.exists?(file)
return false
end
if !out
out = file.clone;
out[out.length - 3, 3] = '.min.js'
end
if !File.exists?(out) || File.mtime(file) > File.mtime(out)
result = `#{COMPILER} --js '#{file}' --js_output_file '#{out}'`
if $? != 0
File.delete(out) rescue nil
return false
end
else
return 1
end
return true
end
def miniHeader (file)
content = File.read(file)
file = File.new(file, 'w');
file.puts '/* miniLOL is released under AGPLv3. Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org] */'
file.write content
file.close
end
task :default do
updated = false
if !File.exists?('system/miniLOL.min.js')
updated = true
else
['miniLOL', 'miniLOL-framework'].each {|file|
if File.mtime("system/#{file}.js") >= File.mtime('system/miniLOL.min.js')
updated = true
break
end
}
end
if updated
minified = File.new(`mktemp -u`.strip, 'w')
minified.write(File.read('system/miniLOL.js') + File.read('system/miniLOL-framework.js'))
minified.close
minify(minified.path, 'system/miniLOL.min.js') || exit
miniHeader('system/miniLOL.min.js')
end
end