-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
183 lines (150 loc) · 5.09 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
require 'rake'
require 'net/http'
require 'uri'
require 'openssl'
require "open-uri"
def download_and_save(arr, path)
begin
if !File.directory?(path)
FileUtils.mkdir_p(path)
puts "Create a #{path} directory"
end
arr.each do |lib|
name = lib.split("/").last
if !File.exist?("#{path}/#{name}")
puts "download: #{name}"
response = URI.parse("#{lib}").read
File.open("#{path}/#{name}", "w") do |f|
f.write(response)
end
end
end
rescue Exception => e
puts "Exception: #{e}"
end
# unzip closure
%x(unzip -u -d vendor vendor/compiler-latest.zip)
end
task :jasmine_install do
deps = %w{
https://raw.githubusercontent.com/jasmine/jasmine/master/lib/jasmine-core/boot/boot.js
https://raw.githubusercontent.com/jasmine/jasmine/master/lib/jasmine-core/jasmine.js
https://raw.githubusercontent.com/jasmine/jasmine/master/lib/jasmine-core/jasmine.css
https://raw.githubusercontent.com/jasmine/jasmine/master/lib/jasmine-core/jasmine-html.js
https://raw.githubusercontent.com/jasmine/jasmine/master/images/jasmine_favicon.png
https://raw.githubusercontent.com/jasmine/jasmine/master/MIT.LICENSE
}
path = "test/jasmine/lib"
download_and_save(deps, path)
end
task :vendor_install do
vendor = "vendor"
deps = [
"https://cdnjs.cloudflare.com/ajax/libs/prototype/1.7.3/prototype.js",
"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js",
"https://raw.githubusercontent.com/dwachss/bililiteRange/master/bililiteRange.js",
"https://raw.githubusercontent.com/dwachss/bililiteRange/master/jquery.sendkeys.js",
"http://dl.google.com/closure-compiler/compiler-latest.zip",
"https://raw.githubusercontent.com/kangax/protolicious/master/event.simulate.js"
]
download_and_save(deps, vendor)
end
desc "Install vendor dependencies and jasmine 2.0"
task :install => [:vendor_install, :jasmine_install] do
end
desc "Compile test sources"
task :test_compile do # => [:build] do
puts "===== recompile..."
%x(coffee -b -c test/fixtures.coffee)
Dir["test/specs/source/*"].each do |file|
name = File.basename(file, ".coffee")
%x(coffee -o test/specs/compile -b -c #{file})
end
puts "===== done"
end
desc "Run test app"
task :test => [:build, :test_compile] do
system("ruby test/app.rb")
end
def coffee(path, arr)
arr.map{|x| "#{path}/#{x}.coffee"}.join(" ")
end
desc "Compile to javascript"
task :build do
puts "build .js"
path = "lib"
if !File.directory?(path)
FileUtils.mkdir_p(path)
puts "Create a #{path} directory"
end
src = "src"
prototype_files = coffee(src, %w(comment_header adapter prototype_js_adapter))
jquery_files = coffee(src, %w(comment_header adapter jquery_adapter))
vanilla_files = coffee(src, %w(comment_header adapter vanilla_js_adapter))
lib_files = coffee(src, %w(
comment_header version adapter vanilla_js_adapter
logger internal promise utils
history_journal
routing sirius validators observer
view base_model collection materialization
))
core_files = coffee(src, %w(
comment_header version adapter vanilla_js_adapter
logger internal promise utils
history_journal routing sirius
))
system("cat #{lib_files} | coffee -c -b --stdio > #{path}/sirius.js")
system("cat #{core_files} | coffee -c -b --stdio > #{path}/sirius-core.js")
system("cat #{prototype_files} | coffee -c -b --stdio > #{path}/prototypejs_adapter.js")
system("cat #{jquery_files} | coffee -c -b --stdio > #{path}/jquery_adapter.js")
system("cat #{vanilla_files} | coffee -c -b --stdio > #{path}/vanillajs_adapter.js")
end
desc "Create doc"
task :doc do
%x(codo src)
end
desc "Minify sources"
task :minify => [:build] do
cc = Dir["vendor/closure-*.jar"]
if cc.empty?
p "Install closure-compiler first"
else
compiler = cc.first
%x[java -jar #{compiler} --js_output_file=sirius-core.min.js lib/sirius-core.js]
%x[java -jar #{compiler} --js_output_file=sirius.min.js lib/sirius.js]
%x[java -jar #{compiler} --js_output_file=jquery_adapter.min.js lib/jquery_adapter.js]
%x[java -jar #{compiler} --js_output_file=prototypejs_adapter.min.js lib/prototypejs_adapter.js]
%x[java -jar #{compiler} --js_output_file=vanillajs_adapter.min.js lib/vanillajs_adapter.js]
end
end
namespace :todo do
desc "install deps for todoapp"
task :install do
Dir.chdir("todomvc") do
`npm install`
end
end
desc "TODOApp compile"
task :compile do #=> [:build] do
app = 'todomvc'
app_files = coffee(app, [
"js/utils/template",
"js/utils/utils",
"js/models/task",
"js/utils/utils",
"js/utils/constants",
"js/utils/renderer",
"js/controllers/main_controller",
"js/controllers/todo_controller",
"js/controllers/additional_info_controller",
"js/controllers/link_controller",
"js/app"
])
system("cat #{app_files} | coffee -c -b --stdio > #{app}/js/app.js")
end
desc "Run TODO app"
task :run => ['todo:compile'] do
system("ruby todomvc/app.rb")
end
end
task :default => :build