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' )
33 }.map { |js| File.join( src_dir, "#{js}.js" ) }
35 # Sizzle, QUnit and jQuery files/dirs
36 sizzle_dir = File.join( src_dir, "sizzle" )
37 sizzle = File.join( sizzle_dir, "sizzle.js" )
38 selector = File.join( src_dir, "selector.js" )
40 qunit_dir = File.join( test_dir, "qunit" )
41 qunit = File.join( qunit_dir, "qunit", "qunit.js" )
43 jq = File.join( dist_dir, "jquery.js" )
44 jq_min = File.join( dist_dir, "jquery.min.js" )
47 date = `git log -1`[/^Date:\s+(.+)$/, 1]
48 version = File.read( File.join( prefix, 'version.txt' ) ).strip
51 rhino = "java -jar #{build_dir}/js.jar"
52 minfier = "java -jar #{build_dir}/google-compiler-20100917.jar"
54 # Turn off output other than needed from `sh` and file commands
58 task :default => "all"
60 desc "Builds jQuery; Tests with JSLint; Minifies jQuery"
61 task :all => [:jquery, :lint, :min] do
62 puts "jQuery build complete."
65 desc "Builds jQuery: jquery.js (Default task)"
66 task :jquery => [:selector, jq]
68 desc "Builds a minified version of jQuery: jquery.min.js"
72 task :init => [sizzle, qunit] do
73 sizzle_git = File.join(sizzle_dir, '.git')
74 qunit_git = File.join(qunit_dir, '.git')
76 puts "Updating SizzleJS with latest..."
77 sh "git --git-dir=#{sizzle_git} pull -q origin master"
79 puts "Updating QUnit with latest..."
80 sh "git --git-dir=#{qunit_git} pull -q origin master"
83 desc "Removes dist folder, selector.js, and Sizzle/QUnit"
85 puts "Removing Distribution directory: #{dist_dir}..."
88 puts "Removing built copy of Sizzle..."
91 puts "Removing cloned directories..."
96 desc "Rebuilds selector.js from SizzleJS"
97 task :selector => [:init, selector]
99 desc "Tests built jquery.js against JSLint"
101 puts "Checking jQuery against JSLint..."
102 sh "#{rhino} " + File.join(build_dir, 'jslint-check.js')
106 # File and Directory Dependencies
109 file jq => [dist_dir, base_files].flatten do
110 puts "Building jquery.js..."
112 File.open(jq, 'w') do |f|
113 f.write cat(base_files).
115 gsub(/@VERSION/, version).
116 gsub(/.function..jQuery...\{/, '').
117 gsub(/\}...jQuery..;/, '')
122 puts "Building jquery.min.js..."
124 sh "#{minfier} --js #{jq} --warning_level QUIET --js_output_file #{jq_min}"
126 min = File.read( jq_min )
128 # Equivilent of "head"
129 File.open(jq_min, 'w') do |f|
130 f.write File.readlines(jq)[0..14].join()
135 file selector => [sizzle, :init] do
136 puts "Building selector code from Sizzle..."
138 File.open(selector, 'w') do |f|
139 f.write File.read(sizzle).gsub(
141 '\0' + File.read( File.join( src_dir, 'sizzle-jquery.js' ))
143 /^window.Sizzle.+$\n/, ''
149 puts "Retrieving SizzleJS from Github..."
150 sh "git clone git://github.com/jeresig/sizzle.git #{sizzle_dir}"
154 puts "Retrieving QUnit from Github..."
155 sh "git clone git://github.com/jquery/qunit.git #{qunit_dir}"