-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
255 lines (213 loc) · 7.96 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
require 'rake'
require 'rake/packagetask'
require 'yaml'
ROOT_DIR = File.expand_path(File.dirname(__FILE__))
SRC_DIR = File.join(ROOT_DIR, 'src')
DIST_DIR = File.join(ROOT_DIR,'dist')
DEBUG_DIR = File.join(DIST_DIR, 'debug')
RELEASE_DIR = File.join(DIST_DIR, 'release')
DOCUMENTATION_DIR = File.join(ROOT_DIR, 'doc')
PKG_DIR = File.join(ROOT_DIR, 'pkg')
VERSION = YAML.load(IO.read(File.join(SRC_DIR, 'constants.yml')))['VERSION']
TEST_DIR = File.join(ROOT_DIR, 'test')
TEST_UNIT_DIR = File.join(TEST_DIR, 'unit')
TMP_DIR = File.join(TEST_UNIT_DIR, 'tmp')
DOC_TEMPLATES_ROOT = File.join(ROOT_DIR, "templates")
DOC_TEMPLATES_DIR = File.join(DOC_TEMPLATES_ROOT, "html")
$:.unshift File.join(ROOT_DIR, 'vendor', 'sprockets', 'lib')
def sprocketize(path, source, destination=nil)
destination ||= [*source].first
begin
require "sprockets"
rescue LoadError => e
puts "\nUncharted requires Sprockets to build the files. Just run:\n\n"
puts " $ git submodule init"
puts " $ git submodule update"
puts "\nto pull in the necessary submodules.\n\n"
end
puts "Sprocketizing (#{[*source].join(', ')})..."
secretary = Sprockets::Secretary.new(
:root => File.join(ROOT_DIR, path),
:load_path => [SRC_DIR],
:source_files => [*source]
)
secretary.concatenation.save_to(File.join(DIST_DIR, destination))
end
task :default => [:clean, :dist, :unified, :doc, :package, :clean_package_source]
desc "Clean the distribution directory."
task :clean do
rm_rf DIST_DIR
mkdir DIST_DIR
mkdir DEBUG_DIR
mkdir RELEASE_DIR
end
def dist_from_sources(sources)
sprocketize("src", sources, "uncharted.js")
cp File.join(ROOT_DIR,'lib','prototype.1.7.0.js'), File.join(DIST_DIR,'prototype.1.7.0.js')
cp File.join(ROOT_DIR,'lib','raphael.2.0.0.js'), File.join(DIST_DIR,'raphael.2.0.0.js')
end
desc "Builds the distribution."
task :dist => ['dist:default']
namespace :dist do
task :default do
dist_from_sources(["uncharted.js"])
end
end
def minify(src, target, compressor = 'yui')
puts "Minifying #{src}..."
if compressor == 'yui'
`java -jar vendor/yuicompressor/yuicompressor-2.4.2.jar #{src} -o #{target}`
elsif compressor == 'google'
`java -jar vendor/google-compiler/compiler.jar --js #{src} --summary_detail_level 3 --js_output_file #{target}`
end
cp target, File.join(DEBUG_DIR,'temp.js')
msize = File.size(File.join(DEBUG_DIR,'temp.js'))
`gzip -9 #{File.join(DEBUG_DIR,'temp.js')}`
osize = File.size(src)
dsize = File.size(File.join(DEBUG_DIR,'temp.js.gz'))
rm_rf File.join(DEBUG_DIR,'temp.js.gz')
puts "Original version: %.1fk" % (osize/1024.0)
puts "Minified: %.1fk" % (msize/1024.0)
puts "Minified and gzipped: %.1fk, compression factor %.1f" % [dsize/1024.0, osize/dsize.to_f]
end
desc "Generates a minified version of the distribution (using YUI Compressor)."
task :min do
minify File.join(DIST_DIR,'uncharted.js'), File.join(RELEASE_DIR,'uncharted.min.js')
minify File.join(ROOT_DIR,'lib','prototype.1.7.0.js'), File.join(RELEASE_DIR,'prototype.1.7.0.min.js')
minify File.join(ROOT_DIR,'lib','raphael.2.0.0.js'), File.join(RELEASE_DIR,'raphael.2.0.0.min.js')
end
desc "Generates a minified version of the distribution (using Google Closure Compiler)."
task :min_google do
minify File.join(DIST_DIR,'uncharted.js'), File.join(RELEASE_DIR,'uncharted.min.js'), 'google'
minify File.join(ROOT_DIR,'lib','prototype.1.7.0.js'), File.join(RELEASE_DIR,'prototype.1.7.0.min.js'), 'google'
minify File.join(ROOT_DIR,'lib','raphael.2.0.0.js'), File.join(RELEASE_DIR,'raphael.2.0.0.min.js'), 'google'
end
def unify_distribution
unified = IO.read(File.join(DIST_DIR,'prototype.1.7.0.js')) + IO.read(File.join(DIST_DIR,'raphael.2.0.0.js')) + IO.read(File.join(DIST_DIR,'uncharted.js'))
File.open(File.join(DIST_DIR,'pro.raph.uncharted.js'), 'w') do |file|
file.write unified
end
minify File.join(DIST_DIR,'pro.raph.uncharted.js'), File.join(RELEASE_DIR,'pro.raph.uncharted.min.js')
end
desc "Generate a unified minified version of Prototype, Raphael and Uncharted"
task :unified => ['unified:default']
namespace :unified do
task :default => [:dist, :min] do
unify_distribution
end
end
def doc_from_sources(sources)
require 'tempfile'
begin
require "sprockets"
rescue LoadError => e
puts "\nUncharted requires Sprockets to build the files. Just run:\n\n"
puts " $ git submodule init"
puts " $ git submodule update"
puts "\nto pull in the necessary submodules.\n\n"
end
Tempfile.open("pdoc") do |temp|
secretary = Sprockets::Secretary.new(
:root => File.join(ROOT_DIR, "src"),
:load_path => [SRC_DIR],
:source_files => sources,
:strip_comments => false
)
secretary.concatenation.save_to(temp.path)
rm_rf DOCUMENTATION_DIR
mkdir DOCUMENTATION_DIR
#begin
PDoc::Runner.new(temp.path,
:destination => DOCUMENTATION_DIR
).run
#rescue
# puts "\n\nEXCEPTION WHILE RUNNING PDOC, CONTINUING...\n\n"
#end
end
cp File.join(ROOT_DIR, 'lib', 'prototype.1.7.0.js'), File.join(DOCUMENTATION_DIR, 'javascripts')
cp File.join(ROOT_DIR, 'lib', 'raphael.2.0.0.js'), File.join(DOCUMENTATION_DIR, 'javascripts')
cp File.join(DIST_DIR,'uncharted.js'), File.join(DOCUMENTATION_DIR,'javascripts')
end
namespace :doc do
desc "Builds the documentation."
task :build => [:require] do
doc_from_sources(["uncharted.js"])
end
task :require do
lib = 'vendor/pdoc/lib/pdoc'
unless File.exists?(lib)
puts "\nUncharted requires pDoc to build the documentation. Just run:\n\n"
puts " $ git submodule init"
puts " $ git submodule update"
puts "\nto pull in the necessary submodules.\n\n"
end
require File.join(ROOT_DIR,lib)
end
end
task :doc => ['doc:build']
Rake::PackageTask.new('uncharted', VERSION) do |package|
package.need_tar_gz = true
package.need_zip = true
package.package_dir = PKG_DIR
package.package_files.include(
'README.md',
'BSD-LICENSE',
'dist/**/*',
'doc/**/*',
'src/**/*'
)
end
task :clean_package_source do
rm_rf File.join(PKG_DIR, "uncharted-#{VERSION}")
end
task :test => ['test:build', 'test:run']
namespace :test do
desc 'Runs all the JavaScript unit tests and collects the results'
task :run => [:require] do
testcases = ENV['TESTCASES']
browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
runner = UnittestJS::WEBrickRunner::Runner.new(:test_dir => TMP_DIR)
Dir[File.join(TMP_DIR, '*_test.html')].each do |file|
file = File.basename(file)
test = file.sub('_test.html', '')
unless tests_to_run && !tests_to_run.include?(test)
runner.add_test(file, testcases)
end
end
UnittestJS::Browser::SUPPORTED.each do |browser|
unless browsers_to_test && !browsers_to_test.include?(browser)
runner.add_browser(browser.to_sym)
end
end
trap('INT') { runner.teardown; exit }
runner.run
end
task :build => [:clean, :dist] do
builder = UnittestJS::Builder::SuiteBuilder.new({
:input_dir => TEST_UNIT_DIR,
:assets_dir => DIST_DIR
})
selected_tests = (ENV['TESTS'] || '').split(',')
builder.collect(*selected_tests)
builder.render
# override UnittestJS stuff
cp File.join(ROOT_DIR, 'lib', 'prototype.1.7.0.js'),
File.join(TMP_DIR, 'lib_assets', 'prototype.1.7.0.js')
cp File.join(ROOT_DIR, 'lib', 'raphael.2.0.0.js'),
File.join(TMP_DIR, 'lib_assets', 'prototype.1.7.0.js')
end
task :clean => [:require] do
UnittestJS::Builder.empty_dir!(TMP_DIR)
end
task :require do
lib = 'vendor/unittest_js/lib/unittest_js'
unless File.exists?(lib)
puts "\nUncharted requires UnittestJS to run the test. Just run:\n\n"
puts " $ git submodule init"
puts " $ git submodule update"
puts "\nto pull in the necessary submodules.\n\n"
end
require lib
end
end