Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 247 lines (208 sloc) 7.263 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')
4dd878f @sstephenson Replace Prototype's Selector implementation with Sizzle
authored
12 SIZZLE_DIR = File.join(ROOT_DIR, 'vendor', 'sizzle')
ea9f797 @tobie Refactor Rakefile.
tobie authored
13 TEST_DIR = File.join(ROOT_DIR, 'test')
14 TEST_UNIT_DIR = File.join(TEST_DIR, 'unit')
15 TMP_DIR = File.join(TEST_UNIT_DIR, 'tmp')
16 VERSION = YAML.load(IO.read(File.join(SRC_DIR, 'constants.yml')))['PROTOTYPE_VERSION']
c5372d8 @savetheclocktower Detect if Sizzle hasn't been loaded via submodule.
savetheclocktower authored
17
18 %w[sprockets pdoc unittest_js caja_builder sizzle].each do |name|
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
40 def self.sprocketize(path, source, destination = nil, strip_comments = true)
41 require_sprockets
c5372d8 @savetheclocktower Detect if Sizzle hasn't been loaded via submodule.
savetheclocktower authored
42 require_sizzle
ea9f797 @tobie Refactor Rakefile.
tobie authored
43 secretary = Sprockets::Secretary.new(
44 :root => File.join(ROOT_DIR, path),
4dd878f @sstephenson Replace Prototype's Selector implementation with Sizzle
authored
45 :load_path => [SRC_DIR, SIZZLE_DIR],
ea9f797 @tobie Refactor Rakefile.
tobie authored
46 :source_files => [source],
47 :strip_comments => strip_comments
48 )
49
50 destination = File.join(DIST_DIR, source) unless destination
51 secretary.concatenation.save_to(destination)
a519c02 @sstephenson Sprocketize Prototype
authored
52 end
53
ea9f797 @tobie Refactor Rakefile.
tobie authored
54 def self.build_doc_for(file)
55 mkdir_p TMP_DIR
56 temp_path = File.join(TMP_DIR, "prototype.temp.js")
57 sprocketize('src', file, temp_path, false)
58 rm_rf DOC_DIR
59
60 PDoc::Runner.new(temp_path, {
61 :output => DOC_DIR,
d5947d9 @tobie doc: Add README.markdown as index page to API documentation.
tobie authored
62 :templates => File.join(TEMPLATES_DIR, "html"),
63 :index_page => 'README.markdown'
ea9f797 @tobie Refactor Rakefile.
tobie authored
64 }).run
65
66 rm_rf temp_path
67 end
68
69 def self.require_sprockets
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
70 require_submodule('Sprockets', 'sprockets')
ea9f797 @tobie Refactor Rakefile.
tobie authored
71 end
72
73 def self.require_pdoc
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
74 require_submodule('PDoc', 'pdoc')
ea9f797 @tobie Refactor Rakefile.
tobie authored
75 end
76
77 def self.require_unittest_js
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
78 require_submodule('UnittestJS', 'unittest_js')
ea9f797 @tobie Refactor Rakefile.
tobie authored
79 end
6d70608 @sstephenson Update to Sprockets 0.9.0
authored
80
ea9f797 @tobie Refactor Rakefile.
tobie authored
81 def self.require_caja_builder
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
82 require_submodule('CajaBuilder', 'caja_builder')
ea9f797 @tobie Refactor Rakefile.
tobie authored
83 end
84
c5372d8 @savetheclocktower Detect if Sizzle hasn't been loaded via submodule.
savetheclocktower authored
85 def self.require_sizzle
86 if !File.exists?(File.join(SIZZLE_DIR, 'sizzle.js'))
d3df9ba @savetheclocktower Automate installation of Git submodules.
savetheclocktower authored
87 exit unless get_submodule("Sizzle", "sizzle")
c5372d8 @savetheclocktower Detect if Sizzle hasn't been loaded via submodule.
savetheclocktower authored
88 end
89 end
90
d3df9ba @savetheclocktower Automate installation of Git submodules.
savetheclocktower authored
91 def self.get_submodule(name, path)
92 require_git
93 puts "\nYou seem to be missing #{name}. Obtaining it via git...\n\n"
94
95 Kernel.system("git submodule init")
96 return true if Kernel.system("git submodule update vendor/#{path}")
97
98 # If we got this far, something went wrong.
99 puts "\nLooks like it didn't work. Try it manually:\n\n"
100 puts " $ git submodule init"
101 puts " $ git submodule update vendor/#{path}"
102 false
103 end
104
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
105 def self.require_submodule(name, path)
ea9f797 @tobie Refactor Rakefile.
tobie authored
106 begin
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
107 require path
ea9f797 @tobie Refactor Rakefile.
tobie authored
108 rescue LoadError => e
d3df9ba @savetheclocktower Automate installation of Git submodules.
savetheclocktower authored
109 # Wait until we notice that a submodule is missing before we bother the
110 # user about installing git. (Maybe they brought all the files over
111 # from a different machine.)
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
112 missing_file = e.message.sub('no such file to load -- ', '')
113 if missing_file == path
d3df9ba @savetheclocktower Automate installation of Git submodules.
savetheclocktower authored
114 # Missing a git submodule.
115 retry if get_submodule(name, path)
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
116 else
d3df9ba @savetheclocktower Automate installation of Git submodules.
savetheclocktower authored
117 # Missing a gem.
0a8cf9b @tobie Prevent Rakefile from mishandling missing gem errors.
tobie authored
118 puts "\nIt looks like #{name} is missing the '#{missing_file}' gem. Just run:\n\n"
119 puts " $ gem install #{missing_file}"
120 puts "\nand you should be all set.\n\n"
121 end
ea9f797 @tobie Refactor Rakefile.
tobie authored
122 exit
123 end
124 end
b2597ec @samleb Start PDoc integration.
samleb authored
125 end
126
ea9f797 @tobie Refactor Rakefile.
tobie authored
127 task :default => [:dist, :dist_helper, :package, :clean_package_source]
128
a519c02 @sstephenson Sprocketize Prototype
authored
129 desc "Builds the distribution."
130 task :dist do
ea9f797 @tobie Refactor Rakefile.
tobie authored
131 PrototypeHelper.sprocketize("src", "prototype.js")
a519c02 @sstephenson Sprocketize Prototype
authored
132 end
133
4428747 @savetheclocktower Updated Rakefile to check for presence of PDoc before running 'doc' t…
savetheclocktower authored
134 namespace :doc do
135 desc "Builds the documentation."
136 task :build => [:require] do
63f96ea @tobie Fixed doc template to allow separate building of the documentation of…
tobie authored
137 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
138 end
139
140 task :require do
ea9f797 @tobie Refactor Rakefile.
tobie authored
141 PrototypeHelper.require_pdoc
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
142 end
143 end
144
4428747 @savetheclocktower Updated Rakefile to check for presence of PDoc before running 'doc' t…
savetheclocktower authored
145 task :doc => ['doc:build']
146
cf5d180 @tobie refactored unit tests quite a bit. Added JS and CSS fixtures.
tobie authored
147 desc "Builds the updating helper."
87ce153 @tobie prototype: Complete rewrite of the deprecation helper.
tobie authored
148 task :dist_helper do
ea9f797 @tobie Refactor Rakefile.
tobie authored
149 PrototypeHelper.sprocketize("ext/update_helper", "prototype_update_helper.js")
87ce153 @tobie prototype: Complete rewrite of the deprecation helper.
tobie authored
150 end
151
ea9f797 @tobie Refactor Rakefile.
tobie authored
152 Rake::PackageTask.new('prototype', PrototypeHelper::VERSION) do |package|
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
153 package.need_tar_gz = true
ea9f797 @tobie Refactor Rakefile.
tobie authored
154 package.package_dir = PrototypeHelper::PKG_DIR
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
155 package.package_files.include(
156 '[A-Z]*',
157 'dist/prototype.js',
158 'lib/**',
159 'src/**',
160 'test/**'
161 )
162 end
163
52a781a @tobie Switch to UnittestJS.
tobie authored
164 task :clean_package_source do
ea9f797 @tobie Refactor Rakefile.
tobie authored
165 rm_rf File.join(PrototypeHelper::PKG_DIR, "prototype-#{PrototypeHelper::VERSION}")
52a781a @tobie Switch to UnittestJS.
tobie authored
166 end
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
167
52a781a @tobie Switch to UnittestJS.
tobie authored
168 task :test => ['test:build', 'test:run']
169 namespace :test do
170 desc 'Runs all the JavaScript unit tests and collects the results'
171 task :run => [:require] do
172 testcases = ENV['TESTCASES']
173 browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
174 tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
ea9f797 @tobie Refactor Rakefile.
tobie authored
175 runner = UnittestJS::WEBrickRunner::Runner.new(:test_dir => PrototypeHelper::TMP_DIR)
52a781a @tobie Switch to UnittestJS.
tobie authored
176
ea9f797 @tobie Refactor Rakefile.
tobie authored
177 Dir[File.join(PrototypeHelper::TMP_DIR, '*_test.html')].each do |file|
52a781a @tobie Switch to UnittestJS.
tobie authored
178 file = File.basename(file)
179 test = file.sub('_test.html', '')
180 unless tests_to_run && !tests_to_run.include?(test)
181 runner.add_test(file, testcases)
182 end
183 end
184
185 UnittestJS::Browser::SUPPORTED.each do |browser|
186 unless browsers_to_test && !browsers_to_test.include?(browser)
187 runner.add_browser(browser.to_sym)
188 end
189 end
190
191 trap('INT') { runner.teardown; exit }
192 runner.run
193 end
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
194
52a781a @tobie Switch to UnittestJS.
tobie authored
195 task :build => [:clean, :dist] do
196 builder = UnittestJS::Builder::SuiteBuilder.new({
ea9f797 @tobie Refactor Rakefile.
tobie authored
197 :input_dir => PrototypeHelper::TEST_UNIT_DIR,
198 :assets_dir => PrototypeHelper::DIST_DIR
52a781a @tobie Switch to UnittestJS.
tobie authored
199 })
200 selected_tests = (ENV['TESTS'] || '').split(',')
201 builder.collect(*selected_tests)
202 builder.render
203 end
ba6934e @tobie Make Rake auto-generate test/unit/temp directory if it is missing.
tobie authored
204
52a781a @tobie Switch to UnittestJS.
tobie authored
205 task :clean => [:require] do
ea9f797 @tobie Refactor Rakefile.
tobie authored
206 UnittestJS::Builder.empty_dir!(PrototypeHelper::TMP_DIR)
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
207 end
208
52a781a @tobie Switch to UnittestJS.
tobie authored
209 task :require do
ea9f797 @tobie Refactor Rakefile.
tobie authored
210 PrototypeHelper.require_unittest_js
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
211 end
212 end
41ef42e @tobie Unit test lib reorganizing.
tobie authored
213
52a781a @tobie Switch to UnittestJS.
tobie authored
214 task :test_units do
215 puts '"rake test_units" is deprecated. Please use "rake test" instead.'
41ef42e @tobie Unit test lib reorganizing.
tobie authored
216 end
217
52a781a @tobie Switch to UnittestJS.
tobie authored
218 task :build_unit_tests do
219 puts '"rake test_units" is deprecated. Please use "rake test:build" instead.'
41ef42e @tobie Unit test lib reorganizing.
tobie authored
220 end
221
222 task :clean_tmp do
52a781a @tobie Switch to UnittestJS.
tobie authored
223 puts '"rake clean_tmp" is deprecated. Please use "rake test:clean" instead.'
41ef42e @tobie Unit test lib reorganizing.
tobie authored
224 end
99f74b5 @tobie Add caja_builder for optional cajoled tests.
tobie authored
225
226 namespace :caja do
227 task :test => ['test:build', 'test:run']
228
229 namespace :test do
230 task :run => ['rake:test:run']
231
232 task :build => [:require, 'rake:test:clean', :dist] do
233 builder = UnittestJS::CajaBuilder::SuiteBuilder.new({
ea9f797 @tobie Refactor Rakefile.
tobie authored
234 :input_dir => PrototypeHelper::TEST_UNIT_DIR,
235 :assets_dir => PrototypeHelper::DIST_DIR,
236 :whitelist_dir => File.join(PrototypeHelper::TEST_DIR, 'unit', 'caja_whitelists'),
99f74b5 @tobie Add caja_builder for optional cajoled tests.
tobie authored
237 :html_attrib_schema => 'html_attrib.json'
238 })
239 selected_tests = (ENV['TESTS'] || '').split(',')
240 builder.collect(*selected_tests)
241 builder.render
242 end
243 end
244 task :require => ['rake:test:require'] do
ea9f797 @tobie Refactor Rakefile.
tobie authored
245 PrototypeHelper.require_caja_builder
99f74b5 @tobie Add caja_builder for optional cajoled tests.
tobie authored
246 end
247 end
Something went wrong with that request. Please try again.