2010-06-13 03:55:49 +00:00
|
|
|
prefix = File.dirname( __FILE__ )
|
2009-11-29 21:21:54 +00:00
|
|
|
|
2010-06-13 03:55:49 +00:00
|
|
|
# Directory variables
|
|
|
|
src_dir = File.join( prefix, 'src' )
|
|
|
|
build_dir = File.join( prefix, 'build' )
|
|
|
|
test_dir = File.join( prefix, 'test' )
|
2009-11-29 21:21:54 +00:00
|
|
|
|
2010-06-13 03:55:49 +00:00
|
|
|
# A different destination directory can be set by
|
|
|
|
# setting DIST_DIR before calling rake
|
|
|
|
dist_dir = ENV['DIST_DIR'] || File.join( prefix, 'dist' )
|
2009-11-29 21:21:54 +00:00
|
|
|
|
2010-12-30 07:38:28 +00:00
|
|
|
base_files = %w{
|
|
|
|
intro
|
|
|
|
core
|
|
|
|
support
|
|
|
|
data
|
|
|
|
queue
|
|
|
|
attributes
|
|
|
|
event
|
|
|
|
selector
|
|
|
|
traversing
|
|
|
|
manipulation
|
|
|
|
css
|
|
|
|
ajax
|
2011-01-06 00:17:31 +00:00
|
|
|
ajax/jsonp
|
|
|
|
ajax/script
|
|
|
|
ajax/xhr
|
2010-12-30 07:38:28 +00:00
|
|
|
effects
|
|
|
|
offset
|
|
|
|
dimensions
|
|
|
|
outro
|
|
|
|
}.map { |js| File.join( src_dir, "#{js}.js" ) }
|
2010-06-13 03:55:49 +00:00
|
|
|
|
|
|
|
# Sizzle, QUnit and jQuery files/dirs
|
|
|
|
sizzle_dir = File.join( src_dir, "sizzle" )
|
|
|
|
sizzle = File.join( sizzle_dir, "sizzle.js" )
|
|
|
|
selector = File.join( src_dir, "selector.js" )
|
|
|
|
|
|
|
|
qunit_dir = File.join( test_dir, "qunit" )
|
|
|
|
qunit = File.join( qunit_dir, "qunit", "qunit.js" )
|
|
|
|
|
|
|
|
jq = File.join( dist_dir, "jquery.js" )
|
|
|
|
jq_min = File.join( dist_dir, "jquery.min.js" )
|
|
|
|
|
|
|
|
# General Variables
|
2010-06-14 06:05:06 +00:00
|
|
|
date = `git log -1`[/^Date:\s+(.+)$/, 1]
|
2010-06-13 03:55:49 +00:00
|
|
|
version = File.read( File.join( prefix, 'version.txt' ) ).strip
|
|
|
|
|
|
|
|
# Build tools
|
|
|
|
rhino = "java -jar #{build_dir}/js.jar"
|
2010-10-14 20:57:12 +00:00
|
|
|
minfier = "java -jar #{build_dir}/google-compiler-20100917.jar"
|
2010-06-13 03:55:49 +00:00
|
|
|
|
|
|
|
# Turn off output other than needed from `sh` and file commands
|
2010-12-30 06:34:48 +00:00
|
|
|
verbose(false)
|
2010-06-13 03:55:49 +00:00
|
|
|
|
|
|
|
# Tasks
|
2010-06-14 15:17:13 +00:00
|
|
|
task :default => "all"
|
2010-06-13 03:55:49 +00:00
|
|
|
|
|
|
|
desc "Builds jQuery; Tests with JSLint; Minifies jQuery"
|
|
|
|
task :all => [:jquery, :lint, :min] do
|
|
|
|
puts "jQuery build complete."
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Builds jQuery: jquery.js (Default task)"
|
|
|
|
task :jquery => [:selector, jq]
|
|
|
|
|
|
|
|
desc "Builds a minified version of jQuery: jquery.min.js"
|
|
|
|
task :min => jq_min
|
|
|
|
|
|
|
|
|
|
|
|
task :init => [sizzle, qunit] do
|
2010-06-14 06:05:06 +00:00
|
|
|
sizzle_git = File.join(sizzle_dir, '.git')
|
|
|
|
qunit_git = File.join(qunit_dir, '.git')
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-06-13 03:55:49 +00:00
|
|
|
puts "Updating SizzleJS with latest..."
|
2010-06-14 06:05:06 +00:00
|
|
|
sh "git --git-dir=#{sizzle_git} pull -q origin master"
|
2010-06-13 03:55:49 +00:00
|
|
|
|
|
|
|
puts "Updating QUnit with latest..."
|
2010-06-14 06:05:06 +00:00
|
|
|
sh "git --git-dir=#{qunit_git} pull -q origin master"
|
2009-11-30 20:56:40 +00:00
|
|
|
end
|
|
|
|
|
2010-06-13 03:55:49 +00:00
|
|
|
desc "Removes dist folder, selector.js, and Sizzle/QUnit"
|
|
|
|
task :clean do
|
2010-12-30 06:34:48 +00:00
|
|
|
puts "Removing Distribution directory: #{dist_dir}..."
|
2010-06-14 19:03:13 +00:00
|
|
|
rm_rf dist_dir
|
2010-06-13 03:55:49 +00:00
|
|
|
|
|
|
|
puts "Removing built copy of Sizzle..."
|
2010-06-14 19:03:13 +00:00
|
|
|
rm_rf selector
|
2010-06-13 03:55:49 +00:00
|
|
|
|
|
|
|
puts "Removing cloned directories..."
|
2010-06-14 19:03:13 +00:00
|
|
|
rm_rf qunit_dir
|
|
|
|
rm_rf sizzle_dir
|
2010-06-13 03:55:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "Rebuilds selector.js from SizzleJS"
|
|
|
|
task :selector => [:init, selector]
|
|
|
|
|
|
|
|
desc "Tests built jquery.js against JSLint"
|
|
|
|
task :lint => jq do
|
|
|
|
puts "Checking jQuery against JSLint..."
|
2010-06-14 06:05:06 +00:00
|
|
|
sh "#{rhino} " + File.join(build_dir, 'jslint-check.js')
|
2010-06-13 03:55:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# File and Directory Dependencies
|
|
|
|
directory dist_dir
|
|
|
|
|
|
|
|
file jq => [dist_dir, base_files].flatten do
|
|
|
|
puts "Building jquery.js..."
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-06-14 06:05:06 +00:00
|
|
|
File.open(jq, 'w') do |f|
|
2010-12-30 07:38:28 +00:00
|
|
|
f.write cat(base_files).
|
|
|
|
gsub(/@DATE/, date).
|
|
|
|
gsub(/@VERSION/, version).
|
|
|
|
gsub(/.function..jQuery...\{/, '').
|
|
|
|
gsub(/\}...jQuery..;/, '')
|
2010-06-14 06:05:06 +00:00
|
|
|
end
|
2010-06-13 03:55:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
file jq_min => jq do
|
|
|
|
puts "Building jquery.min.js..."
|
|
|
|
|
2010-06-14 06:05:06 +00:00
|
|
|
sh "#{minfier} --js #{jq} --warning_level QUIET --js_output_file #{jq_min}"
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-06-14 06:05:06 +00:00
|
|
|
min = File.read( jq_min )
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-06-14 06:05:06 +00:00
|
|
|
# Equivilent of "head"
|
|
|
|
File.open(jq_min, 'w') do |f|
|
|
|
|
f.write File.readlines(jq)[0..14].join()
|
|
|
|
f.write min
|
|
|
|
end
|
2010-06-13 03:55:49 +00:00
|
|
|
end
|
|
|
|
|
2010-12-30 06:34:48 +00:00
|
|
|
file selector => [sizzle, :init] do
|
2010-06-13 03:55:49 +00:00
|
|
|
puts "Building selector code from Sizzle..."
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-06-14 06:05:06 +00:00
|
|
|
File.open(selector, 'w') do |f|
|
2010-12-30 06:34:48 +00:00
|
|
|
f.write File.read(sizzle).gsub(
|
|
|
|
/^.+EXPOSE$\n/,
|
2010-06-14 06:05:06 +00:00
|
|
|
'\0' + File.read( File.join( src_dir, 'sizzle-jquery.js' ))
|
|
|
|
).gsub(
|
|
|
|
/^window.Sizzle.+$\n/, ''
|
|
|
|
)
|
|
|
|
end
|
2010-06-13 03:55:49 +00:00
|
|
|
end
|
2009-11-29 21:21:54 +00:00
|
|
|
|
2010-06-13 03:55:49 +00:00
|
|
|
file sizzle do
|
|
|
|
puts "Retrieving SizzleJS from Github..."
|
|
|
|
sh "git clone git://github.com/jeresig/sizzle.git #{sizzle_dir}"
|
2009-11-29 21:21:54 +00:00
|
|
|
end
|
|
|
|
|
2010-06-13 03:55:49 +00:00
|
|
|
file qunit do
|
2010-06-14 06:07:21 +00:00
|
|
|
puts "Retrieving QUnit from Github..."
|
2010-06-13 03:55:49 +00:00
|
|
|
sh "git clone git://github.com/jquery/qunit.git #{qunit_dir}"
|
2009-11-29 21:21:54 +00:00
|
|
|
end
|
2010-06-14 06:05:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def cat( files )
|
|
|
|
files.map do |file|
|
|
|
|
File.read(file)
|
|
|
|
end.join('')
|
2010-10-14 20:57:12 +00:00
|
|
|
end
|