2007-01-18 22:24:27 +00:00
|
|
|
require 'rake'
|
|
|
|
require 'rake/packagetask'
|
|
|
|
|
2009-03-06 18:26:50 +00:00
|
|
|
require 'yaml'
|
|
|
|
|
2008-12-11 17:01:31 +00:00
|
|
|
PROTOTYPE_ROOT = File.expand_path(File.dirname(__FILE__))
|
|
|
|
PROTOTYPE_SRC_DIR = File.join(PROTOTYPE_ROOT, 'src')
|
|
|
|
PROTOTYPE_DIST_DIR = File.join(PROTOTYPE_ROOT, 'dist')
|
2009-01-12 15:00:42 +00:00
|
|
|
PROTOTYPE_DOC_DIR = File.join(PROTOTYPE_ROOT, 'doc')
|
2009-03-06 18:26:50 +00:00
|
|
|
PROTOTYPE_TEMPLATES_DIR = File.join(PROTOTYPE_ROOT, 'templates')
|
2008-12-11 17:01:31 +00:00
|
|
|
PROTOTYPE_PKG_DIR = File.join(PROTOTYPE_ROOT, 'pkg')
|
|
|
|
PROTOTYPE_TEST_DIR = File.join(PROTOTYPE_ROOT, 'test')
|
|
|
|
PROTOTYPE_TEST_UNIT_DIR = File.join(PROTOTYPE_TEST_DIR, 'unit')
|
|
|
|
PROTOTYPE_TMP_DIR = File.join(PROTOTYPE_TEST_UNIT_DIR, 'tmp')
|
2009-02-10 16:52:08 +00:00
|
|
|
PROTOTYPE_VERSION = YAML.load(IO.read(File.join(PROTOTYPE_SRC_DIR, 'constants.yml')))['PROTOTYPE_VERSION']
|
2007-01-18 22:24:27 +00:00
|
|
|
|
2009-01-27 21:42:32 +00:00
|
|
|
$:.unshift File.join(PROTOTYPE_ROOT, 'vendor', 'sprockets', 'lib')
|
2008-12-14 04:36:59 +00:00
|
|
|
|
2008-03-15 16:43:00 +00:00
|
|
|
task :default => [:dist, :dist_helper, :package, :clean_package_source]
|
2007-01-18 22:24:27 +00:00
|
|
|
|
2009-01-27 21:42:32 +00:00
|
|
|
def sprocketize(path, source, destination = source)
|
|
|
|
begin
|
|
|
|
require "sprockets"
|
|
|
|
rescue LoadError => e
|
|
|
|
puts "\nYou'll need Sprockets to build Prototype. Just run:\n\n"
|
|
|
|
puts " $ git submodule init"
|
|
|
|
puts " $ git submodule update"
|
|
|
|
puts "\nand you should be all set.\n\n"
|
|
|
|
end
|
|
|
|
|
2009-02-10 17:18:24 +00:00
|
|
|
secretary = Sprockets::Secretary.new(
|
|
|
|
:root => File.join(PROTOTYPE_ROOT, path),
|
|
|
|
:load_path => [PROTOTYPE_SRC_DIR],
|
|
|
|
:source_files => [source]
|
|
|
|
)
|
|
|
|
|
|
|
|
secretary.concatenation.save_to(File.join(PROTOTYPE_DIST_DIR, destination))
|
2008-12-14 04:36:59 +00:00
|
|
|
end
|
|
|
|
|
2009-01-27 21:42:32 +00:00
|
|
|
desc "Builds the distribution."
|
|
|
|
task :dist do
|
|
|
|
sprocketize("src", "prototype.js")
|
|
|
|
end
|
|
|
|
|
2009-01-12 15:00:42 +00:00
|
|
|
namespace :doc do
|
|
|
|
desc "Builds the documentation."
|
|
|
|
task :build => [:require] do
|
2009-03-06 18:26:50 +00:00
|
|
|
|
|
|
|
TEMPLATES_ROOT = File.join(PROTOTYPE_ROOT, "vendor", "pdoc",
|
|
|
|
"new_templates")
|
|
|
|
|
|
|
|
TEMPLATES_DIRECTORY = File.join(TEMPLATES_ROOT, "html")
|
|
|
|
|
2009-01-12 15:00:42 +00:00
|
|
|
require 'tempfile'
|
2009-03-06 18:26:50 +00:00
|
|
|
begin
|
|
|
|
require "sprockets"
|
|
|
|
rescue LoadError => e
|
|
|
|
puts "\nYou'll need Sprockets to build Prototype. Just run:\n\n"
|
|
|
|
puts " $ git submodule init"
|
|
|
|
puts " $ git submodule update"
|
|
|
|
puts "\nand you should be all set.\n\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
Tempfile.open("pdoc") do |temp|
|
|
|
|
secretary = Sprockets::Secretary.new(
|
|
|
|
:root => File.join(PROTOTYPE_ROOT, "src"),
|
|
|
|
:load_path => [PROTOTYPE_SRC_DIR],
|
|
|
|
:source_files => ["prototype.js"],
|
|
|
|
:strip_comments => false
|
|
|
|
)
|
|
|
|
|
|
|
|
secretary.concatenation.save_to(temp.path)
|
2009-01-12 15:00:42 +00:00
|
|
|
rm_rf PROTOTYPE_DOC_DIR
|
2009-03-06 18:26:50 +00:00
|
|
|
PDoc::Runner.new(temp.path, {
|
|
|
|
:output => PROTOTYPE_DOC_DIR,
|
|
|
|
:templates => File.join(PROTOTYPE_TEMPLATES_DIR, "html")
|
|
|
|
}).run
|
2009-01-12 15:00:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task :require do
|
|
|
|
lib = 'vendor/pdoc/lib/pdoc'
|
|
|
|
unless File.exists?(lib)
|
|
|
|
puts "\nYou'll need PDoc to generate the documentation. Just run:\n\n"
|
|
|
|
puts " $ git submodule init"
|
|
|
|
puts " $ git submodule update"
|
|
|
|
puts "\nand you should be all set.\n\n"
|
|
|
|
end
|
|
|
|
require lib
|
2007-01-18 22:24:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-12 15:00:42 +00:00
|
|
|
task :doc => ['doc:build']
|
|
|
|
|
2008-04-23 07:55:23 +00:00
|
|
|
desc "Builds the updating helper."
|
2008-03-15 16:43:00 +00:00
|
|
|
task :dist_helper do
|
2009-01-27 21:42:32 +00:00
|
|
|
sprocketize("ext/update_helper", "prototype_update_helper.js")
|
2008-03-15 16:43:00 +00:00
|
|
|
end
|
|
|
|
|
2007-01-18 22:24:27 +00:00
|
|
|
Rake::PackageTask.new('prototype', PROTOTYPE_VERSION) do |package|
|
|
|
|
package.need_tar_gz = true
|
|
|
|
package.package_dir = PROTOTYPE_PKG_DIR
|
|
|
|
package.package_files.include(
|
|
|
|
'[A-Z]*',
|
|
|
|
'dist/prototype.js',
|
|
|
|
'lib/**',
|
|
|
|
'src/**',
|
|
|
|
'test/**'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2008-12-11 17:01:31 +00:00
|
|
|
task :clean_package_source do
|
|
|
|
rm_rf File.join(PROTOTYPE_PKG_DIR, "prototype-#{PROTOTYPE_VERSION}")
|
|
|
|
end
|
2007-01-18 22:24:27 +00:00
|
|
|
|
2008-12-11 17:01:31 +00:00
|
|
|
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 => PROTOTYPE_TMP_DIR)
|
|
|
|
|
|
|
|
Dir[File.join(PROTOTYPE_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
|
2007-01-18 22:24:27 +00:00
|
|
|
|
2008-12-11 17:01:31 +00:00
|
|
|
task :build => [:clean, :dist] do
|
|
|
|
builder = UnittestJS::Builder::SuiteBuilder.new({
|
|
|
|
:input_dir => PROTOTYPE_TEST_UNIT_DIR,
|
|
|
|
:assets_dir => PROTOTYPE_DIST_DIR
|
|
|
|
})
|
|
|
|
selected_tests = (ENV['TESTS'] || '').split(',')
|
|
|
|
builder.collect(*selected_tests)
|
|
|
|
builder.render
|
|
|
|
end
|
2008-04-23 10:05:30 +00:00
|
|
|
|
2008-12-11 17:01:31 +00:00
|
|
|
task :clean => [:require] do
|
|
|
|
UnittestJS::Builder.empty_dir!(PROTOTYPE_TMP_DIR)
|
2007-01-18 22:24:27 +00:00
|
|
|
end
|
|
|
|
|
2008-12-11 17:01:31 +00:00
|
|
|
task :require do
|
|
|
|
lib = 'vendor/unittest_js/lib/unittest_js'
|
|
|
|
unless File.exists?(lib)
|
|
|
|
puts "\nYou'll need UnittestJS to run the tests. Just run:\n\n"
|
|
|
|
puts " $ git submodule init"
|
|
|
|
puts " $ git submodule update"
|
|
|
|
puts "\nand you should be all set.\n\n"
|
|
|
|
end
|
|
|
|
require lib
|
2007-01-18 22:24:27 +00:00
|
|
|
end
|
|
|
|
end
|
2008-09-08 08:23:20 +00:00
|
|
|
|
2008-12-11 17:01:31 +00:00
|
|
|
task :test_units do
|
|
|
|
puts '"rake test_units" is deprecated. Please use "rake test" instead.'
|
2008-09-08 08:23:20 +00:00
|
|
|
end
|
|
|
|
|
2008-12-11 17:01:31 +00:00
|
|
|
task :build_unit_tests do
|
|
|
|
puts '"rake test_units" is deprecated. Please use "rake test:build" instead.'
|
2008-09-08 08:23:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
task :clean_tmp do
|
2008-12-11 17:01:31 +00:00
|
|
|
puts '"rake clean_tmp" is deprecated. Please use "rake test:clean" instead.'
|
2008-09-08 08:23:20 +00:00
|
|
|
end
|
2008-12-12 12:55:28 +00:00
|
|
|
|
|
|
|
namespace :caja do
|
|
|
|
task :test => ['test:build', 'test:run']
|
|
|
|
|
|
|
|
namespace :test do
|
|
|
|
task :run => ['rake:test:run']
|
|
|
|
|
|
|
|
task :build => [:require, 'rake:test:clean', :dist] do
|
|
|
|
builder = UnittestJS::CajaBuilder::SuiteBuilder.new({
|
|
|
|
:input_dir => PROTOTYPE_TEST_UNIT_DIR,
|
|
|
|
:assets_dir => PROTOTYPE_DIST_DIR,
|
|
|
|
:whitelist_dir => File.join(PROTOTYPE_TEST_DIR, 'unit', 'caja_whitelists'),
|
|
|
|
:html_attrib_schema => 'html_attrib.json'
|
|
|
|
})
|
|
|
|
selected_tests = (ENV['TESTS'] || '').split(',')
|
|
|
|
builder.collect(*selected_tests)
|
|
|
|
builder.render
|
|
|
|
end
|
|
|
|
end
|
|
|
|
task :require => ['rake:test:require'] do
|
|
|
|
lib = 'vendor/caja_builder/lib/caja_builder'
|
|
|
|
unless File.exists?(lib)
|
|
|
|
puts "\nYou'll need UnittestJS to run the tests. Just run:\n\n"
|
|
|
|
puts " $ git submodule init"
|
|
|
|
puts " $ git submodule update"
|
|
|
|
puts "\nand you should be all set.\n\n"
|
|
|
|
end
|
|
|
|
require lib
|
|
|
|
end
|
|
|
|
end
|