-
Notifications
You must be signed in to change notification settings - Fork 32
/
Rakefile
89 lines (75 loc) · 2.08 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
def get_file_as_string(filename)
data = ''
f = File.open(filename, "r")
f.each_line do |line|
data += line
end
return data
end
def minify_js(name, jss)
jscompiler = "closure-compiler.jar"
target = "client/#{name}-min.js"
source_arg = ''
jss.each do |js|
source_arg += " --js #{js} "
end
# ADVANCED_OPTIMIZATIONS SIMPLE_OPTIMIZATIONS
sh "java -jar bin/#{jscompiler} --warning_level QUIET " +
"--compilation_level SIMPLE_OPTIMIZATIONS " +
"--js_output_file '#{target}' #{source_arg}"
end
jscompiler = "closure-compiler.jar"
file "bin/#{jscompiler}" do
mkdir_p 'bin'
sh 'wget http://closure-compiler.googlecode.com/files/compiler-latest.zip' +
' -O /tmp/closure-compiler.zip'
rm_rf '/tmp/compiler.jar'
sh 'unzip /tmp/closure-compiler.zip compiler.jar -d /tmp'
rm_rf '/tmp/closure-compiler.zip'
mv '/tmp/compiler.jar', "bin/#{jscompiler}"
end
task :deps => ["bin/#{jscompiler}"]
dict_jss = FileList['client/jquery.js',
'client/allwords.js',
'client/mustache.js',
'client/tmpls.js',
'client/dict.js']
def gen_jstempls()
print "Generating tmpls.js, please wait....\n"
html_tmpls = FileList["tmpls/**/*.*"]
data = "(function(){var tmpls = {};"
html_tmpls.each do |f|
text = get_file_as_string(f).gsub(/\s+/," ")
name = File.basename(f, ".tpl")
data += "tmpls." + name + " = '" + text + "';\n"
end
data += "window.D = {tmpls: tmpls};})();\n"
File.open("client/tmpls.js", 'w') {|f| f.write(data)}
sh "cp client/tmpls.js android/assets/tmpls.js"
end
desc "generate js template"
task :jstemple do
gen_jstempls()
end
desc "lein swank"
task :swank do
sh "rm classes -rf && lein javac && lein swank"
end
desc "watch for change"
task :watch do
sh 'while inotifywait -r -e modify tmpls/; do rake jstemple; done'
end
desc "deploy"
task :deploy do
sh "scripts/deploy"
end
desc "run"
task :run do
sh "scripts/run"
end
desc "minify js"
task :minify_js do
sh 'rm -f client/dict-min.js*'
minify_js("dict", dict_jss);
sh 'cd client && gzip -9 dict-min.js'
end