2007-01-18 22:24:27 +00:00
|
|
|
require 'rake'
|
|
|
|
require 'rake/packagetask'
|
2009-03-06 18:26:50 +00:00
|
|
|
require 'yaml'
|
|
|
|
|
2009-08-22 01:29:50 +00:00
|
|
|
module PrototypeHelper
|
|
|
|
ROOT_DIR = File.expand_path(File.dirname(__FILE__))
|
|
|
|
SRC_DIR = File.join(ROOT_DIR, 'src')
|
|
|
|
DIST_DIR = File.join(ROOT_DIR, 'dist')
|
|
|
|
DOC_DIR = File.join(ROOT_DIR, 'doc')
|
|
|
|
TEMPLATES_DIR = File.join(ROOT_DIR, 'templates')
|
|
|
|
PKG_DIR = File.join(ROOT_DIR, 'pkg')
|
2009-09-19 19:42:59 +00:00
|
|
|
SIZZLE_DIR = File.join(ROOT_DIR, 'vendor', 'sizzle')
|
2009-08-22 01:29:50 +00:00
|
|
|
TEST_DIR = File.join(ROOT_DIR, 'test')
|
|
|
|
TEST_UNIT_DIR = File.join(TEST_DIR, 'unit')
|
|
|
|
TMP_DIR = File.join(TEST_UNIT_DIR, 'tmp')
|
|
|
|
VERSION = YAML.load(IO.read(File.join(SRC_DIR, 'constants.yml')))['PROTOTYPE_VERSION']
|
2009-10-11 00:07:37 +00:00
|
|
|
|
|
|
|
%w[sprockets pdoc unittest_js caja_builder sizzle].each do |name|
|
|
|
|
$:.unshift File.join(PrototypeHelper::ROOT_DIR, 'vendor', name, 'lib')
|
|
|
|
end
|
2009-10-11 23:49:14 +00:00
|
|
|
|
|
|
|
def self.has_git?
|
|
|
|
begin
|
|
|
|
`git --version`
|
|
|
|
return true
|
|
|
|
rescue Error => e
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.require_git
|
|
|
|
return if has_git?
|
|
|
|
puts "\nPrototype requires Git in order to load its dependencies."
|
|
|
|
puts "\nMake sure you've got Git installed and in your path."
|
|
|
|
puts "\nFor more information, visit:\n\n"
|
|
|
|
puts " http://book.git-scm.com/2_installing_git.html"
|
|
|
|
exit
|
|
|
|
end
|
2009-08-22 01:29:50 +00:00
|
|
|
|
|
|
|
def self.sprocketize(path, source, destination = nil, strip_comments = true)
|
|
|
|
require_sprockets
|
2009-10-11 00:07:37 +00:00
|
|
|
require_sizzle
|
2009-10-23 05:18:52 +00:00
|
|
|
require_nwmatcher
|
2009-08-22 01:29:50 +00:00
|
|
|
secretary = Sprockets::Secretary.new(
|
|
|
|
:root => File.join(ROOT_DIR, path),
|
2009-10-23 03:49:40 +00:00
|
|
|
:load_path => self.load_path,
|
2009-08-22 01:29:50 +00:00
|
|
|
:source_files => [source],
|
|
|
|
:strip_comments => strip_comments
|
|
|
|
)
|
|
|
|
|
|
|
|
destination = File.join(DIST_DIR, source) unless destination
|
|
|
|
secretary.concatenation.save_to(destination)
|
2009-01-27 21:42:32 +00:00
|
|
|
end
|
|
|
|
|
2009-10-23 03:49:40 +00:00
|
|
|
def self.load_path
|
|
|
|
selector = ENV['SELECTOR_ENGINE'] || 'sizzle'
|
|
|
|
selector_path = File.join(ROOT_DIR, 'vendor', selector)
|
|
|
|
if File.exists?(selector_path)
|
|
|
|
[SRC_DIR, selector_path]
|
|
|
|
else
|
|
|
|
puts "\nYou seem to be missing vendor/#{selector}."
|
|
|
|
puts "Built Prototype using Sizzle instead.\n\n"
|
|
|
|
[SRC_DIR, SIZZLE_DIR]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-22 01:29:50 +00:00
|
|
|
def self.build_doc_for(file)
|
|
|
|
mkdir_p TMP_DIR
|
|
|
|
temp_path = File.join(TMP_DIR, "prototype.temp.js")
|
|
|
|
sprocketize('src', file, temp_path, false)
|
|
|
|
rm_rf DOC_DIR
|
|
|
|
|
|
|
|
PDoc::Runner.new(temp_path, {
|
|
|
|
:output => DOC_DIR,
|
2009-08-23 02:16:23 +00:00
|
|
|
:templates => File.join(TEMPLATES_DIR, "html"),
|
|
|
|
:index_page => 'README.markdown'
|
2009-08-22 01:29:50 +00:00
|
|
|
}).run
|
|
|
|
|
|
|
|
rm_rf temp_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.require_sprockets
|
2009-09-02 16:38:31 +00:00
|
|
|
require_submodule('Sprockets', 'sprockets')
|
2009-08-22 01:29:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.require_pdoc
|
2009-09-02 16:38:31 +00:00
|
|
|
require_submodule('PDoc', 'pdoc')
|
2009-08-22 01:29:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.require_unittest_js
|
2009-09-02 16:38:31 +00:00
|
|
|
require_submodule('UnittestJS', 'unittest_js')
|
2009-08-22 01:29:50 +00:00
|
|
|
end
|
2009-02-10 17:18:24 +00:00
|
|
|
|
2009-08-22 01:29:50 +00:00
|
|
|
def self.require_caja_builder
|
2009-09-02 16:38:31 +00:00
|
|
|
require_submodule('CajaBuilder', 'caja_builder')
|
2009-08-22 01:29:50 +00:00
|
|
|
end
|
|
|
|
|
2009-10-11 00:07:37 +00:00
|
|
|
def self.require_sizzle
|
2009-10-23 03:49:40 +00:00
|
|
|
if !File.exists?(File.join(SIZZLE_DIR, 'sizzle', 'sizzle.js'))
|
|
|
|
exit unless get_submodule("Sizzle", "sizzle/sizzle")
|
2009-10-11 00:07:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-23 05:18:52 +00:00
|
|
|
def self.require_nwmatcher
|
|
|
|
if !File.exists?(File.join(ROOT_DIR, 'vendor', 'nwmatcher', 'src', 'nwmatcher.js'))
|
|
|
|
exit unless get_submodule("NWMmatcher", "nwmatcher/nwmatcher")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-11 23:49:14 +00:00
|
|
|
def self.get_submodule(name, path)
|
|
|
|
require_git
|
|
|
|
puts "\nYou seem to be missing #{name}. Obtaining it via git...\n\n"
|
|
|
|
|
|
|
|
Kernel.system("git submodule init")
|
|
|
|
return true if Kernel.system("git submodule update vendor/#{path}")
|
|
|
|
|
|
|
|
# If we got this far, something went wrong.
|
|
|
|
puts "\nLooks like it didn't work. Try it manually:\n\n"
|
|
|
|
puts " $ git submodule init"
|
|
|
|
puts " $ git submodule update vendor/#{path}"
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2009-09-02 16:38:31 +00:00
|
|
|
def self.require_submodule(name, path)
|
2009-08-22 01:29:50 +00:00
|
|
|
begin
|
2009-09-02 16:38:31 +00:00
|
|
|
require path
|
2009-08-22 01:29:50 +00:00
|
|
|
rescue LoadError => e
|
2009-10-11 23:49:14 +00:00
|
|
|
# Wait until we notice that a submodule is missing before we bother the
|
|
|
|
# user about installing git. (Maybe they brought all the files over
|
|
|
|
# from a different machine.)
|
2009-09-02 16:38:31 +00:00
|
|
|
missing_file = e.message.sub('no such file to load -- ', '')
|
|
|
|
if missing_file == path
|
2009-10-11 23:49:14 +00:00
|
|
|
# Missing a git submodule.
|
|
|
|
retry if get_submodule(name, path)
|
2009-09-02 16:38:31 +00:00
|
|
|
else
|
2009-10-11 23:49:14 +00:00
|
|
|
# Missing a gem.
|
2009-09-02 16:38:31 +00:00
|
|
|
puts "\nIt looks like #{name} is missing the '#{missing_file}' gem. Just run:\n\n"
|
|
|
|
puts " $ gem install #{missing_file}"
|
|
|
|
puts "\nand you should be all set.\n\n"
|
|
|
|
end
|
2009-08-22 01:29:50 +00:00
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
2008-12-14 04:36:59 +00:00
|
|
|
end
|
|
|
|
|
2009-08-22 01:29:50 +00:00
|
|
|
task :default => [:dist, :dist_helper, :package, :clean_package_source]
|
|
|
|
|
2009-01-27 21:42:32 +00:00
|
|
|
desc "Builds the distribution."
|
|
|
|
task :dist do
|
2009-08-22 01:29:50 +00:00
|
|
|
PrototypeHelper.sprocketize("src", "prototype.js")
|
2009-01-27 21:42:32 +00:00
|
|
|
end
|
|
|
|
|
2009-01-12 15:00:42 +00:00
|
|
|
namespace :doc do
|
|
|
|
desc "Builds the documentation."
|
|
|
|
task :build => [:require] do
|
2009-08-22 01:56:41 +00:00
|
|
|
PrototypeHelper.build_doc_for(ENV['SECTION'] ? "#{ENV['SECTION']}.js" : 'prototype.js')
|
2009-01-12 15:00:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
task :require do
|
2009-08-22 01:29:50 +00:00
|
|
|
PrototypeHelper.require_pdoc
|
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-08-22 01:29:50 +00:00
|
|
|
PrototypeHelper.sprocketize("ext/update_helper", "prototype_update_helper.js")
|
2008-03-15 16:43:00 +00:00
|
|
|
end
|
|
|
|
|
2009-08-22 01:29:50 +00:00
|
|
|
Rake::PackageTask.new('prototype', PrototypeHelper::VERSION) do |package|
|
2007-01-18 22:24:27 +00:00
|
|
|
package.need_tar_gz = true
|
2009-08-22 01:29:50 +00:00
|
|
|
package.package_dir = PrototypeHelper::PKG_DIR
|
2007-01-18 22:24:27 +00:00
|
|
|
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
|
2009-08-22 01:29:50 +00:00
|
|
|
rm_rf File.join(PrototypeHelper::PKG_DIR, "prototype-#{PrototypeHelper::VERSION}")
|
2008-12-11 17:01:31 +00:00
|
|
|
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(',')
|
2009-08-22 01:29:50 +00:00
|
|
|
runner = UnittestJS::WEBrickRunner::Runner.new(:test_dir => PrototypeHelper::TMP_DIR)
|
2008-12-11 17:01:31 +00:00
|
|
|
|
2009-08-22 01:29:50 +00:00
|
|
|
Dir[File.join(PrototypeHelper::TMP_DIR, '*_test.html')].each do |file|
|
2008-12-11 17:01:31 +00:00
|
|
|
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({
|
2009-08-22 01:29:50 +00:00
|
|
|
:input_dir => PrototypeHelper::TEST_UNIT_DIR,
|
|
|
|
:assets_dir => PrototypeHelper::DIST_DIR
|
2008-12-11 17:01:31 +00:00
|
|
|
})
|
|
|
|
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
|
2009-08-22 01:29:50 +00:00
|
|
|
UnittestJS::Builder.empty_dir!(PrototypeHelper::TMP_DIR)
|
2007-01-18 22:24:27 +00:00
|
|
|
end
|
|
|
|
|
2008-12-11 17:01:31 +00:00
|
|
|
task :require do
|
2009-08-22 01:29:50 +00:00
|
|
|
PrototypeHelper.require_unittest_js
|
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({
|
2009-08-22 01:29:50 +00:00
|
|
|
:input_dir => PrototypeHelper::TEST_UNIT_DIR,
|
|
|
|
:assets_dir => PrototypeHelper::DIST_DIR,
|
|
|
|
:whitelist_dir => File.join(PrototypeHelper::TEST_DIR, 'unit', 'caja_whitelists'),
|
2008-12-12 12:55:28 +00:00
|
|
|
: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
|
2009-08-22 01:29:50 +00:00
|
|
|
PrototypeHelper.require_caja_builder
|
2008-12-12 12:55:28 +00:00
|
|
|
end
|
|
|
|
end
|