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' )
32 }.map { |js| File.join( src_dir, "#{js}.js" ) }
34 # Sizzle, QUnit and jQuery files/dirs
35 sizzle_dir = File.join( src_dir, "sizzle" )
36 sizzle = File.join( sizzle_dir, "sizzle.js" )
37 selector = File.join( src_dir, "selector.js" )
39 qunit_dir = File.join( test_dir, "qunit" )
40 qunit = File.join( qunit_dir, "qunit", "qunit.js" )
42 jq = File.join( dist_dir, "jquery.js" )
43 jq_min = File.join( dist_dir, "jquery.min.js" )
46 date = `git log -1`[/^Date:\s+(.+)$/, 1]
47 version = File.read( File.join( prefix, 'version.txt' ) ).strip
50 rhino = "java -jar #{build_dir}/js.jar"
51 minfier = "java -jar #{build_dir}/google-compiler-20100917.jar"
53 # Turn off output other than needed from `sh` and file commands
57 task :default => "all"
59 desc "Builds jQuery; Tests with JSLint; Minifies jQuery"
60 task :all => [:jquery, :lint, :min] do
61 puts "jQuery build complete."
64 desc "Builds jQuery: jquery.js (Default task)"
65 task :jquery => [:selector, jq]
67 desc "Builds a minified version of jQuery: jquery.min.js"
71 task :init => [sizzle, qunit] do
72 sizzle_git = File.join(sizzle_dir, '.git')
73 qunit_git = File.join(qunit_dir, '.git')
75 puts "Updating SizzleJS with latest..."
76 sh "git --git-dir=#{sizzle_git} pull -q origin master"
78 puts "Updating QUnit with latest..."
79 sh "git --git-dir=#{qunit_git} pull -q origin master"
82 desc "Removes dist folder, selector.js, and Sizzle/QUnit"
84 puts "Removing Distribution directory: #{dist_dir}..."
87 puts "Removing built copy of Sizzle..."
90 puts "Removing cloned directories..."
95 desc "Rebuilds selector.js from SizzleJS"
96 task :selector => [:init, selector]
98 desc "Tests built jquery.js against JSLint"
100 puts "Checking jQuery against JSLint..."
101 sh "#{rhino} " + File.join(build_dir, 'jslint-check.js')
105 # File and Directory Dependencies
108 file jq => [dist_dir, base_files].flatten do
109 puts "Building jquery.js..."
111 File.open(jq, 'w') do |f|
112 f.write cat(base_files).
114 gsub(/@VERSION/, version).
115 gsub(/.function..jQuery...\{/, '').
116 gsub(/\}...jQuery..;/, '')
121 puts "Building jquery.min.js..."
123 sh "#{minfier} --js #{jq} --warning_level QUIET --js_output_file #{jq_min}"
125 min = File.read( jq_min )
127 # Equivilent of "head"
128 File.open(jq_min, 'w') do |f|
129 f.write File.readlines(jq)[0..14].join()
134 file selector => [sizzle, :init] do
135 puts "Building selector code from Sizzle..."
137 File.open(selector, 'w') do |f|
138 f.write File.read(sizzle).gsub(
140 '\0' + File.read( File.join( src_dir, 'sizzle-jquery.js' ))
142 /^window.Sizzle.+$\n/, ''
148 puts "Retrieving SizzleJS from Github..."
149 sh "git clone git://github.com/jeresig/sizzle.git #{sizzle_dir}"
153 puts "Retrieving QUnit from Github..."
154 sh "git clone git://github.com/jquery/qunit.git #{qunit_dir}"