Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 271 lines (229 sloc) 8.028 kb
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
1 require 'rake'
2 require 'rake/packagetask'
0445d37 @savetheclocktower Update Rake "doc" task to integrate with Sprockets.
savetheclocktower authored
3 require 'yaml'
4
ea9f797 @tobie Refactor Rakefile.
tobie authored
5 module PrototypeHelper
6 ROOT_DIR = File.expand_path(File.dirname(__FILE__))
7 SRC_DIR = File.join(ROOT_DIR, 'src')
8 DIST_DIR = File.join(ROOT_DIR, 'dist')
9 DOC_DIR = File.join(ROOT_DIR, 'doc')
10 TEMPLATES_DIR = File.join(ROOT_DIR, 'templates')
11 PKG_DIR = File.join(ROOT_DIR, 'pkg')
12 TEST_DIR = File.join(ROOT_DIR, 'test')
13 TEST_UNIT_DIR = File.join(TEST_DIR, 'unit')
14 TMP_DIR = File.join(TEST_UNIT_DIR, 'tmp')
15 VERSION = YAML.load(IO.read(File.join(SRC_DIR, 'constants.yml')))['PROTOTYPE_VERSION']
a44a8db @tobie Avoid automatically fetching the vendor/sizzle git submodule.
tobie authored
16 DEFAULT_SELECTOR_ENGINE = 'sizzle'
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
17
75aab03 @tobie Repo and Rakefile refactoring.
tobie authored
18 %w[sprockets pdoc unittest_js caja_builder].each do |name|
c5372d8 @savetheclocktower Detect if Sizzle hasn't been loaded via submodule.
savetheclocktower authored
19 $:.unshift File.join(PrototypeHelper::ROOT_DIR, 'vendor', name, 'lib')
20 end
d3df9ba @savetheclocktower Automate installation of Git submodules.
savetheclocktower authored
21
22 def self.has_git?
23 begin
24 `git --version`
25 return true
26 rescue Error => e
27 return false
28 end
29 end
30
31 def self.require_git
32 return if has_git?
33 puts "\nPrototype requires Git in order to load its dependencies."
34 puts "\nMake sure you've got Git installed and in your path."
35 puts "\nFor more information, visit:\n\n"
36 puts " http://book.git-scm.com/2_installing_git.html"
37 exit
38 end
ea9f797 @tobie Refactor Rakefile.
tobie authored
39
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
40 def self.sprocketize(options = {})
41 options = {
42 :destination => File.join(DIST_DIR, options[:source]),
43 :strip_comments => true
44 }.merge(options)
45
ea9f797 @tobie Refactor Rakefile.
tobie authored
46 require_sprockets
74c5d45 @samleb Fix custom selector engine load path resolution.
samleb authored
47 load_path = [SRC_DIR]
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
48
a44a8db @tobie Avoid automatically fetching the vendor/sizzle git submodule.
tobie authored
49 if selector_path = get_selector_engine(options[:selector_engine])
50 load_path << selector_path
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
51 end
52
ea9f797 @tobie Refactor Rakefile.
tobie authored
53 secretary = Sprockets::Secretary.new(
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
54 :root => File.join(ROOT_DIR, options[:path]),
55 :load_path => load_path,
56 :source_files => [options[:source]],
57 :strip_comments => options[:strip_comments]
ea9f797 @tobie Refactor Rakefile.
tobie authored
58 )
59
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
60 secretary.concatenation.save_to(options[:destination])
7762e00 @tobie Reorder repository to allow for custom selector engines to be include…
tobie authored
61 end
62
ea9f797 @tobie Refactor Rakefile.
tobie authored
63 def self.build_doc_for(file)
64 mkdir_p TMP_DIR
65 temp_path = File.join(TMP_DIR, "prototype.temp.js")
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
66 sprocketize(
67 :path => 'src',
68 :source => file,
69 :destination => temp_path,
a44a8db @tobie Avoid automatically fetching the vendor/sizzle git submodule.
tobie authored
70 :selector_engine => ENV['SELECTOR_ENGINE'] || DEFAULT_SELECTOR_ENGINE,
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
71 :strip_comments => false
72 )
ea9f797 @tobie Refactor Rakefile.
tobie authored
73 rm_rf DOC_DIR
74
75 PDoc::Runner.new(temp_path, {
76 :output => DOC_DIR,
d5947d9 @tobie doc: Add README.markdown as index page to API documentation.
tobie authored
77 :templates => File.join(TEMPLATES_DIR, "html"),
78 :index_page => 'README.markdown'
ea9f797 @tobie Refactor Rakefile.
tobie authored
79 }).run
80
81 rm_rf temp_path
82 end
83
84 def self.require_sprockets
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
85 require_submodule('Sprockets', 'sprockets')
ea9f797 @tobie Refactor Rakefile.
tobie authored
86 end
87
88 def self.require_pdoc
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
89 require_submodule('PDoc', 'pdoc')
ea9f797 @tobie Refactor Rakefile.
tobie authored
90 end
91
92 def self.require_unittest_js
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
93 require_submodule('UnittestJS', 'unittest_js')
ea9f797 @tobie Refactor Rakefile.
tobie authored
94 end
6d70608 @sstephenson Update to Sprockets 0.9.0
authored
95
ea9f797 @tobie Refactor Rakefile.
tobie authored
96 def self.require_caja_builder
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
97 require_submodule('CajaBuilder', 'caja_builder')
ea9f797 @tobie Refactor Rakefile.
tobie authored
98 end
99
75aab03 @tobie Repo and Rakefile refactoring.
tobie authored
100 def self.get_selector_engine(name)
74c5d45 @samleb Fix custom selector engine load path resolution.
samleb authored
101 submodule_path = File.join(ROOT_DIR, "vendor", name)
102 return submodule_path if File.exist?(File.join(submodule_path, "repository", ".git"))
a44a8db @tobie Avoid automatically fetching the vendor/sizzle git submodule.
tobie authored
103 return if name == DEFAULT_SELECTOR_ENGINE
74c5d45 @samleb Fix custom selector engine load path resolution.
samleb authored
104
105 get_submodule('the required selector engine', "#{name}/repository")
9d47112 @tobie Fix typo in Rakefile.
tobie authored
106 unless File.exist?(submodule_path)
74c5d45 @samleb Fix custom selector engine load path resolution.
samleb authored
107 puts "The selector engine you required isn't available at vendor/#{name}.\n\n"
108 exit
15c323b @tobie Include NWMatcher as a submodule.
tobie authored
109 end
110 end
111
d3df9ba @savetheclocktower Automate installation of Git submodules.
savetheclocktower authored
112 def self.get_submodule(name, path)
113 require_git
114 puts "\nYou seem to be missing #{name}. Obtaining it via git...\n\n"
115
116 Kernel.system("git submodule init")
117 return true if Kernel.system("git submodule update vendor/#{path}")
118 # If we got this far, something went wrong.
119 puts "\nLooks like it didn't work. Try it manually:\n\n"
120 puts " $ git submodule init"
121 puts " $ git submodule update vendor/#{path}"
122 false
123 end
124
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
125 def self.require_submodule(name, path)
ea9f797 @tobie Refactor Rakefile.
tobie authored
126 begin
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
127 require path
ea9f797 @tobie Refactor Rakefile.
tobie authored
128 rescue LoadError => e
d3df9ba @savetheclocktower Automate installation of Git submodules.
savetheclocktower authored
129 # Wait until we notice that a submodule is missing before we bother the
130 # user about installing git. (Maybe they brought all the files over
131 # from a different machine.)
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
132 missing_file = e.message.sub('no such file to load -- ', '')
133 if missing_file == path
d3df9ba @savetheclocktower Automate installation of Git submodules.
savetheclocktower authored
134 # Missing a git submodule.
135 retry if get_submodule(name, path)
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
136 else
d3df9ba @savetheclocktower Automate installation of Git submodules.
savetheclocktower authored
137 # Missing a gem.
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
138 puts "\nIt looks like #{name} is missing the '#{missing_file}' gem. Just run:\n\n"
139 puts " $ gem install #{missing_file}"
140 puts "\nand you should be all set.\n\n"
141 end
ea9f797 @tobie Refactor Rakefile.
tobie authored
142 exit
143 end
144 end
b2597ec @samleb Start PDoc integration.
samleb authored
145 end
146
ea9f797 @tobie Refactor Rakefile.
tobie authored
147 task :default => [:dist, :dist_helper, :package, :clean_package_source]
148
a519c02 @sstephenson Sprocketize Prototype
authored
149 desc "Builds the distribution."
150 task :dist do
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
151 PrototypeHelper.sprocketize(
152 :path => 'src',
153 :source => 'prototype.js',
a44a8db @tobie Avoid automatically fetching the vendor/sizzle git submodule.
tobie authored
154 :selector_engine => ENV['SELECTOR_ENGINE'] || PrototypeHelper::DEFAULT_SELECTOR_ENGINE
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
155 )
a519c02 @sstephenson Sprocketize Prototype
authored
156 end
157
4428747 @savetheclocktower Updated Rakefile to check for presence of PDoc before running 'doc' t…
savetheclocktower authored
158 namespace :doc do
159 desc "Builds the documentation."
160 task :build => [:require] do
63f96ea @tobie Fixed doc template to allow separate building of the documentation of…
tobie authored
161 PrototypeHelper.build_doc_for(ENV['SECTION'] ? "#{ENV['SECTION']}.js" : 'prototype.js')
4428747 @savetheclocktower Updated Rakefile to check for presence of PDoc before running 'doc' t…
savetheclocktower authored
162 end
163
164 task :require do
ea9f797 @tobie Refactor Rakefile.
tobie authored
165 PrototypeHelper.require_pdoc
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
166 end
167 end
168
4428747 @savetheclocktower Updated Rakefile to check for presence of PDoc before running 'doc' t…
savetheclocktower authored
169 task :doc => ['doc:build']
170
cf5d180 @tobie refactored unit tests quite a bit. Added JS and CSS fixtures.
tobie authored
171 desc "Builds the updating helper."
87ce153 @tobie prototype: Complete rewrite of the deprecation helper.
tobie authored
172 task :dist_helper do
107f812 @tobie Modify PrototypeHelper.sprocketize to take a hash of options rather t…
tobie authored
173 PrototypeHelper.sprocketize(:path => 'ext/update_helper', :source => 'prototype_update_helper.js')
87ce153 @tobie prototype: Complete rewrite of the deprecation helper.
tobie authored
174 end
175
ea9f797 @tobie Refactor Rakefile.
tobie authored
176 Rake::PackageTask.new('prototype', PrototypeHelper::VERSION) do |package|
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
177 package.need_tar_gz = true
ea9f797 @tobie Refactor Rakefile.
tobie authored
178 package.package_dir = PrototypeHelper::PKG_DIR
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
179 package.package_files.include(
180 '[A-Z]*',
181 'dist/prototype.js',
182 'lib/**',
183 'src/**',
184 'test/**'
185 )
186 end
187
52a781a @tobie Switch to UnittestJS.
tobie authored
188 task :clean_package_source do
ea9f797 @tobie Refactor Rakefile.
tobie authored
189 rm_rf File.join(PrototypeHelper::PKG_DIR, "prototype-#{PrototypeHelper::VERSION}")
52a781a @tobie Switch to UnittestJS.
tobie authored
190 end
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
191
52a781a @tobie Switch to UnittestJS.
tobie authored
192 task :test => ['test:build', 'test:run']
193 namespace :test do
194 desc 'Runs all the JavaScript unit tests and collects the results'
195 task :run => [:require] do
196 testcases = ENV['TESTCASES']
197 browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
198 tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
ea9f797 @tobie Refactor Rakefile.
tobie authored
199 runner = UnittestJS::WEBrickRunner::Runner.new(:test_dir => PrototypeHelper::TMP_DIR)
52a781a @tobie Switch to UnittestJS.
tobie authored
200
ea9f797 @tobie Refactor Rakefile.
tobie authored
201 Dir[File.join(PrototypeHelper::TMP_DIR, '*_test.html')].each do |file|
52a781a @tobie Switch to UnittestJS.
tobie authored
202 file = File.basename(file)
203 test = file.sub('_test.html', '')
204 unless tests_to_run && !tests_to_run.include?(test)
205 runner.add_test(file, testcases)
206 end
207 end
208
209 UnittestJS::Browser::SUPPORTED.each do |browser|
210 unless browsers_to_test && !browsers_to_test.include?(browser)
211 runner.add_browser(browser.to_sym)
212 end
213 end
214
215 trap('INT') { runner.teardown; exit }
216 runner.run
217 end
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
218
52a781a @tobie Switch to UnittestJS.
tobie authored
219 task :build => [:clean, :dist] do
220 builder = UnittestJS::Builder::SuiteBuilder.new({
ea9f797 @tobie Refactor Rakefile.
tobie authored
221 :input_dir => PrototypeHelper::TEST_UNIT_DIR,
222 :assets_dir => PrototypeHelper::DIST_DIR
52a781a @tobie Switch to UnittestJS.
tobie authored
223 })
224 selected_tests = (ENV['TESTS'] || '').split(',')
225 builder.collect(*selected_tests)
226 builder.render
227 end
ba6934e @tobie Make Rake auto-generate test/unit/temp directory if it is missing.
tobie authored
228
52a781a @tobie Switch to UnittestJS.
tobie authored
229 task :clean => [:require] do
ea9f797 @tobie Refactor Rakefile.
tobie authored
230 UnittestJS::Builder.empty_dir!(PrototypeHelper::TMP_DIR)
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
231 end
232
52a781a @tobie Switch to UnittestJS.
tobie authored
233 task :require do
ea9f797 @tobie Refactor Rakefile.
tobie authored
234 PrototypeHelper.require_unittest_js
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
235 end
236 end
41ef42e @tobie Unit test lib reorganizing.
tobie authored
237
52a781a @tobie Switch to UnittestJS.
tobie authored
238 task :test_units do
239 puts '"rake test_units" is deprecated. Please use "rake test" instead.'
41ef42e @tobie Unit test lib reorganizing.
tobie authored
240 end
241
52a781a @tobie Switch to UnittestJS.
tobie authored
242 task :build_unit_tests do
243 puts '"rake test_units" is deprecated. Please use "rake test:build" instead.'
41ef42e @tobie Unit test lib reorganizing.
tobie authored
244 end
245
246 task :clean_tmp do
52a781a @tobie Switch to UnittestJS.
tobie authored
247 puts '"rake clean_tmp" is deprecated. Please use "rake test:clean" instead.'
41ef42e @tobie Unit test lib reorganizing.
tobie authored
248 end
99f74b5 @tobie Add caja_builder for optional cajoled tests.
tobie authored
249
250 namespace :caja do
251 task :test => ['test:build', 'test:run']
252
253 namespace :test do
254 task :run => ['rake:test:run']
255
256 task :build => [:require, 'rake:test:clean', :dist] do
257 builder = UnittestJS::CajaBuilder::SuiteBuilder.new({
ea9f797 @tobie Refactor Rakefile.
tobie authored
258 :input_dir => PrototypeHelper::TEST_UNIT_DIR,
259 :assets_dir => PrototypeHelper::DIST_DIR,
260 :whitelist_dir => File.join(PrototypeHelper::TEST_DIR, 'unit', 'caja_whitelists'),
99f74b5 @tobie Add caja_builder for optional cajoled tests.
tobie authored
261 :html_attrib_schema => 'html_attrib.json'
262 })
263 selected_tests = (ENV['TESTS'] || '').split(',')
264 builder.collect(*selected_tests)
265 builder.render
266 end
267 end
268 task :require => ['rake:test:require'] do
ea9f797 @tobie Refactor Rakefile.
tobie authored
269 PrototypeHelper.require_caja_builder
99f74b5 @tobie Add caja_builder for optional cajoled tests.
tobie authored
270 end
271 end
Something went wrong with that request. Please try again.