forked from rictic/reconciliation_ui
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
160 lines (132 loc) · 5.16 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
#A bunch of plumbing for testing, minifying javascript, and deploying
#Freebase Loader will run just fine without worrying about all this stuff
task :default => [:test]
task :test => [:compile_tests, :run_tests]
task :build => [:copy, :compile, :version]
#i.e. don't compile, just copy
task :build_debug => [:clean, :copy_all, :version]
task :deploy => [:clean, :build, :push, :clean_again]
task :deploy_debug => [:clean, :build_debug, :compile_tests, :push, :clean_again]
task :deploy_dev => [:clean, :build_debug, :compile_tests, :push_dev, :clean_again]
file "build/" do
sh "mkdir -p build"
end
task :run_tests => "jsTestDriver.conf" do
sh "jstdServer ; sleep 3 ; open http://localhost:4224/capture" unless `nc -z localhost 4224` =~ /succeeded!/
sh "testjstd"
end
task :clean do
sh "rm -rf build"
sh "rm -f jsTestDriver.conf"
end
task :clean_again do
sh "rm -rf build"
end
task :copy => "build/" do
#copy static resources
sh "cp COPYRIGHT *.css build/"
#make sure our other css and images make it
sh "cp -r lib build/"
sh "cp -r examples build/"
sh "cp -r resources build/"
end
task :copy_all => :copy do
sh "cp -r src build/"
sh "cp recon.html build/"
end
#extract out the js files from recon.html
source = File.read("recon.html")
region_regex = /<!--\s*Begin scripts to compile\s*-->(.*?)<!--\s*End scripts to compile\s*-->/m
scripts_region = region_regex.match(source)[1]
js_files = scripts_region.scan(/src=\"(.*?)\"/).compact.map{|a|a[0]}
libs, src = js_files.partition {|f| f.start_with? "lib/"}
task :compile => [:copy, "build/", "build/compiled.js", "build/recon.html"]
#this file isn't used, it just gives the compiler a chance to catch errors before we even run tests
task :compile_tests => ["build/", "build/src_and_tests_compiled.js"]
file "build/recon.html" => ["build/", "recon.html"] do
new_source = source.sub(region_regex, "<script charset=\"utf-8\" src=\"compiled.js\"></script>")
File.open("build/recon.html", 'w') {|f| f.write(new_source)}
end
file "build/compiled.js" => ["build/libs_compiled.js", "build/src_compiled.js"] do |t|
compilejs(t.prerequisites, t.name, true)
end
file "build/libs_compiled.js" => libs do |t|
compilejs(t.prerequisites, t.name, true)
end
#externs files for libraries
lib_externs = ["src/externs.js"] + FileList["lib/*.externs.js"]
file "build/src_compiled.js" => src + lib_externs do |t|
compilejs(src, t.name, false, lib_externs)
end
file "build/src_and_tests_compiled.js" => src + FileList["test/*.js"] do |t|
compilejs(t.prerequisites, t.name, false, lib_externs + ['test/externs'])
end
file "jsTestDriver.conf" => "recon.html" do
contents = "server: http://localhost:4224\n\nload:\n"
contents += (js_files + ["test/*.js"]).map {|f| " - #{f}"}.join("\n")
File.open("jsTestDriver.conf", 'w') {|f| f.write(contents)}
end
task :version do
version = `git log | head -n 1`.match(/commit (.{40})/)[1]
File.open("build/version",'w'){|f| f.puts(version)}
File.open("build/version.js",'w'){|f| f.puts("LOADER_VERSION='#{version}';")}
end
task :push do
if get_current_branch != "master"
puts "\n" * 2
puts "*************************************************"
puts "* DEPLOYING WHILE NOT ON MASTER *"
puts "*************************************************"
puts "\n" * 2
puts "(you probably meant to do rake deploy_dev)"
puts "Press enter to continue anyways, ^C to stop"
STDIN.gets
end
push "/mw/loader/"
end
task :push_dev do
if get_current_branch == "master"
puts "\n" * 2
puts "*************************************************"
puts "* DEPLOYING MASTER TO DEV *"
puts "*************************************************"
puts "\n" * 2
puts "(you probably meant to do rake deploy)"
puts "Press enter to continue anyways, ^C to stop"
STDIN.gets
end
push "/mw/loader_dev/"
end
def push(target)
sh "scp -q -r server.py build data.labs.freebase.com:#{target}"
end
def compilejs(js_files, output_name, third_party=false, externs=[])
if (third_party)
options= "--third_party true --summary_detail_level 0 --warning_level QUIET --compilation_level WHITESPACE_ONLY"
else
options= "--summary_detail_level 3 --jscomp_warning=visibility --jscomp_warning=checkVars --jscomp_error=deprecated --jscomp_warning=fileoverviewTags --jscomp_warning=invalidCasts --jscomp_error=nonStandardJsDocs --jscomp_error=undefinedVars --jscomp_error=unknownDefines --warning_level VERBOSE"
end
js_files_string = js_files.map{|f| "--js #{f}"}.join(" ")
externs_string = externs.map{|f| "--externs #{f}"}.join(" ")
begin
sh "compilejs #{js_files_string} #{externs_string} #{options} --js_output_file #{output_name}"
rescue Exception => err
sh "rm -f #{output_name}"
throw err
end
end
def get_current_branch
`git branch`.match(/^\* (.*?)$/m)[1]
end
#tabulates savings by compiling and by gzipping
task :savings => "build/compiled.js" do
sh "cat #{js_files.join ' '} > catted.js"
sh "du -h catted.js"
sh "gzip catted.js"
sh "du -h catted.js.gz"
sh "du -h build/compiled.js"
sh "cat build/compiled.js | gzip > build/compiled.js.gz"
sh "du -h build/compiled.js.gz"
sh "rm catted.js.gz"
sh "rm build/compiled.js.gz"
end