1 prefix = File.dirname( __FILE__ )
4 src_dir = File.join( prefix, 'src' )
5 build_dir = File.join( prefix, 'build' )
6 test_dir = File.join( prefix, 'test' )
8 # A different destination directory can be set by
9 # setting DIST_DIR before calling rake
10 dist_dir = ENV['DIST_DIR'] || File.join( prefix, 'dist' )
12 base_files = %w{intro core support data queue attributes event selector traversing manipulation css ajax effects offset dimensions outro}.map { |js| File.join( src_dir, "#{js}.js" ) }
14 # Sizzle, QUnit and jQuery files/dirs
15 sizzle_dir = File.join( src_dir, "sizzle" )
16 sizzle = File.join( sizzle_dir, "sizzle.js" )
17 selector = File.join( src_dir, "selector.js" )
19 qunit_dir = File.join( test_dir, "qunit" )
20 qunit = File.join( qunit_dir, "qunit", "qunit.js" )
22 jq = File.join( dist_dir, "jquery.js" )
23 jq_min = File.join( dist_dir, "jquery.min.js" )
26 date = `git log -1`[/^Date:\s+(.+)$/, 1]
27 version = File.read( File.join( prefix, 'version.txt' ) ).strip
30 rhino = "java -jar #{build_dir}/js.jar"
31 minfier = "java -jar #{build_dir}/google-compiler-20091218.jar"
33 # Turn off output other than needed from `sh` and file commands
37 task :default => "all"
39 desc "Builds jQuery; Tests with JSLint; Minifies jQuery"
40 task :all => [:jquery, :lint, :min] do
41 puts "jQuery build complete."
44 desc "Builds jQuery: jquery.js (Default task)"
45 task :jquery => [:selector, jq]
47 desc "Builds a minified version of jQuery: jquery.min.js"
51 task :init => [sizzle, qunit] do
52 sizzle_git = File.join(sizzle_dir, '.git')
53 qunit_git = File.join(qunit_dir, '.git')
55 puts "Updating SizzleJS with latest..."
56 sh "git --git-dir=#{sizzle_git} pull -q origin master"
58 puts "Updating QUnit with latest..."
59 sh "git --git-dir=#{qunit_git} pull -q origin master"
62 desc "Removes dist folder, selector.js, and Sizzle/QUnit"
64 puts "Removing Distribution directory: #{dist_dir}..."
67 puts "Removing built copy of Sizzle..."
70 puts "Removing cloned directories..."
75 desc "Rebuilds selector.js from SizzleJS"
76 task :selector => [:init, selector]
78 desc "Tests built jquery.js against JSLint"
80 puts "Checking jQuery against JSLint..."
81 sh "#{rhino} " + File.join(build_dir, 'jslint-check.js')
85 # File and Directory Dependencies
88 file jq => [dist_dir, base_files].flatten do
89 puts "Building jquery.js..."
91 File.open(jq, 'w') do |f|
92 f.write cat(base_files).gsub(/(Date:.)/, "\\1#{date}" ).gsub(/@VERSION/, version)
97 puts "Building jquery.min.js..."
99 sh "#{minfier} --js #{jq} --warning_level QUIET --js_output_file #{jq_min}"
101 min = File.read( jq_min )
103 # Equivilent of "head"
104 File.open(jq_min, 'w') do |f|
105 f.write File.readlines(jq)[0..14].join()
110 file selector => [sizzle, :init] do
111 puts "Building selector code from Sizzle..."
113 File.open(selector, 'w') do |f|
114 f.write File.read(sizzle).gsub(
116 '\0' + File.read( File.join( src_dir, 'sizzle-jquery.js' ))
118 /^window.Sizzle.+$\n/, ''
124 puts "Retrieving SizzleJS from Github..."
125 sh "git clone git://github.com/jeresig/sizzle.git #{sizzle_dir}"
129 puts "Retrieving QUnit from Github..."
130 sh "git clone git://github.com/jquery/qunit.git #{qunit_dir}"