Skip to content

HTTPS clone URL

Subversion checkout URL

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