Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 198 lines (165 sloc) 5.854 kb
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
1 require 'rake'
2 require 'rake/packagetask'
0445d37 Andrew Dupont Update Rake "doc" task to integrate with Sprockets.
savetheclocktower authored
3 require 'yaml'
4
ea9f797 Tobie Langel 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']
16
17 def self.sprocketize(path, source, destination = nil, strip_comments = true)
18 require_sprockets
19 secretary = Sprockets::Secretary.new(
20 :root => File.join(ROOT_DIR, path),
21 :load_path => [SRC_DIR],
22 :source_files => [source],
23 :strip_comments => strip_comments
24 )
25
26 destination = File.join(DIST_DIR, source) unless destination
27 secretary.concatenation.save_to(destination)
a519c02 Sam Stephenson Sprocketize Prototype
authored
28 end
29
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
30 def self.build_doc_for(file)
31 mkdir_p TMP_DIR
32 temp_path = File.join(TMP_DIR, "prototype.temp.js")
33 sprocketize('src', file, temp_path, false)
34 rm_rf DOC_DIR
35
36 PDoc::Runner.new(temp_path, {
37 :output => DOC_DIR,
38 :templates => File.join(TEMPLATES_DIR, "html")
39 }).run
40
41 rm_rf temp_path
42 end
43
44 def self.require_sprockets
45 require_submodule('sprockets', "You'll need Sprockets to build Prototype")
46 end
47
48 def self.require_pdoc
49 require_submodule('pdoc', "You'll need PDoc to generate the documentation")
50 end
51
52 def self.require_unittest_js
53 require_submodule('unittest_js', "You'll need UnittestJS to run the tests")
54 end
6d70608 Sam Stephenson Update to Sprockets 0.9.0
authored
55
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
56 def self.require_caja_builder
57 require_submodule('caja_builder', "You'll need CajaBuilder to run cajoled tests")
58 end
59
60 def self.require_submodule(submodule, message)
61 message = message.strip.sub(/\.$/, '')
62 begin
63 require submodule
64 rescue LoadError => e
65 puts "\n#{message}. Just run:\n\n"
66 puts " $ git submodule init"
67 puts " $ git submodule update vendor/#{submodule}"
68 puts "\nand you should be all set.\n\n"
69 exit
70 end
71 end
b2597ec Samuel Lebeau Start PDoc integration.
samleb authored
72 end
73
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
74 %w[sprockets pdoc unittest_js caja_builder].each do |name|
75 $:.unshift File.join(PrototypeHelper::ROOT_DIR, 'vendor', name, 'lib')
76 end
77
78 task :default => [:dist, :dist_helper, :package, :clean_package_source]
79
a519c02 Sam Stephenson Sprocketize Prototype
authored
80 desc "Builds the distribution."
81 task :dist do
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
82 PrototypeHelper.sprocketize("src", "prototype.js")
a519c02 Sam Stephenson Sprocketize Prototype
authored
83 end
84
4428747 Andrew Dupont Updated Rakefile to check for presence of PDoc before running 'doc' task...
savetheclocktower authored
85 namespace :doc do
86 desc "Builds the documentation."
87 task :build => [:require] do
63f96ea Tobie Langel Fixed doc template to allow separate building of the documentation of ea...
tobie authored
88 PrototypeHelper.build_doc_for(ENV['SECTION'] ? "#{ENV['SECTION']}.js" : 'prototype.js')
4428747 Andrew Dupont Updated Rakefile to check for presence of PDoc before running 'doc' task...
savetheclocktower authored
89 end
90
91 task :require do
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
92 PrototypeHelper.require_pdoc
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
93 end
94 end
95
4428747 Andrew Dupont Updated Rakefile to check for presence of PDoc before running 'doc' task...
savetheclocktower authored
96 task :doc => ['doc:build']
97
cf5d180 Tobie Langel refactored unit tests quite a bit. Added JS and CSS fixtures.
tobie authored
98 desc "Builds the updating helper."
87ce153 Tobie Langel prototype: Complete rewrite of the deprecation helper.
tobie authored
99 task :dist_helper do
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
100 PrototypeHelper.sprocketize("ext/update_helper", "prototype_update_helper.js")
87ce153 Tobie Langel prototype: Complete rewrite of the deprecation helper.
tobie authored
101 end
102
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
103 Rake::PackageTask.new('prototype', PrototypeHelper::VERSION) do |package|
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
104 package.need_tar_gz = true
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
105 package.package_dir = PrototypeHelper::PKG_DIR
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
106 package.package_files.include(
107 '[A-Z]*',
108 'dist/prototype.js',
109 'lib/**',
110 'src/**',
111 'test/**'
112 )
113 end
114
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
115 task :clean_package_source do
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
116 rm_rf File.join(PrototypeHelper::PKG_DIR, "prototype-#{PrototypeHelper::VERSION}")
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
117 end
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
118
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
119 task :test => ['test:build', 'test:run']
120 namespace :test do
121 desc 'Runs all the JavaScript unit tests and collects the results'
122 task :run => [:require] do
123 testcases = ENV['TESTCASES']
124 browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
125 tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
126 runner = UnittestJS::WEBrickRunner::Runner.new(:test_dir => PrototypeHelper::TMP_DIR)
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
127
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
128 Dir[File.join(PrototypeHelper::TMP_DIR, '*_test.html')].each do |file|
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
129 file = File.basename(file)
130 test = file.sub('_test.html', '')
131 unless tests_to_run && !tests_to_run.include?(test)
132 runner.add_test(file, testcases)
133 end
134 end
135
136 UnittestJS::Browser::SUPPORTED.each do |browser|
137 unless browsers_to_test && !browsers_to_test.include?(browser)
138 runner.add_browser(browser.to_sym)
139 end
140 end
141
142 trap('INT') { runner.teardown; exit }
143 runner.run
144 end
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
145
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
146 task :build => [:clean, :dist] do
147 builder = UnittestJS::Builder::SuiteBuilder.new({
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
148 :input_dir => PrototypeHelper::TEST_UNIT_DIR,
149 :assets_dir => PrototypeHelper::DIST_DIR
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
150 })
151 selected_tests = (ENV['TESTS'] || '').split(',')
152 builder.collect(*selected_tests)
153 builder.render
154 end
ba6934e Tobie Langel Make Rake auto-generate test/unit/temp directory if it is missing.
tobie authored
155
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
156 task :clean => [:require] do
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
157 UnittestJS::Builder.empty_dir!(PrototypeHelper::TMP_DIR)
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
158 end
159
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
160 task :require do
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
161 PrototypeHelper.require_unittest_js
bb4d189 Sam Stephenson prototype: Reorganize the source tree.
authored
162 end
163 end
41ef42e Tobie Langel Unit test lib reorganizing.
tobie authored
164
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
165 task :test_units do
166 puts '"rake test_units" is deprecated. Please use "rake test" instead.'
41ef42e Tobie Langel Unit test lib reorganizing.
tobie authored
167 end
168
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
169 task :build_unit_tests do
170 puts '"rake test_units" is deprecated. Please use "rake test:build" instead.'
41ef42e Tobie Langel Unit test lib reorganizing.
tobie authored
171 end
172
173 task :clean_tmp do
52a781a Tobie Langel Switch to UnittestJS.
tobie authored
174 puts '"rake clean_tmp" is deprecated. Please use "rake test:clean" instead.'
41ef42e Tobie Langel Unit test lib reorganizing.
tobie authored
175 end
99f74b5 Tobie Langel Add caja_builder for optional cajoled tests.
tobie authored
176
177 namespace :caja do
178 task :test => ['test:build', 'test:run']
179
180 namespace :test do
181 task :run => ['rake:test:run']
182
183 task :build => [:require, 'rake:test:clean', :dist] do
184 builder = UnittestJS::CajaBuilder::SuiteBuilder.new({
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
185 :input_dir => PrototypeHelper::TEST_UNIT_DIR,
186 :assets_dir => PrototypeHelper::DIST_DIR,
187 :whitelist_dir => File.join(PrototypeHelper::TEST_DIR, 'unit', 'caja_whitelists'),
99f74b5 Tobie Langel Add caja_builder for optional cajoled tests.
tobie authored
188 :html_attrib_schema => 'html_attrib.json'
189 })
190 selected_tests = (ENV['TESTS'] || '').split(',')
191 builder.collect(*selected_tests)
192 builder.render
193 end
194 end
195 task :require => ['rake:test:require'] do
ea9f797 Tobie Langel Refactor Rakefile.
tobie authored
196 PrototypeHelper.require_caja_builder
99f74b5 Tobie Langel Add caja_builder for optional cajoled tests.
tobie authored
197 end
198 end
Something went wrong with that request. Please try again.