Skip to content

Commit 3e1ac2a

Browse files
dcneinerwycats
authored andcommitted
Updated Rakefile to mirror the functionality of the Makefile
The Rakefile now supports all the functionality of the Makefile including only rebuilding files when dependent files change. To see availible tasks, run: rake -T
1 parent ef8df7f commit 3e1ac2a

File tree

1 file changed

+102
-17
lines changed

1 file changed

+102
-17
lines changed

Rakefile

Lines changed: 102 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,111 @@
1-
# Basic Rakefile for building jQuery
2-
files = [ "intro", "core", "support", "data", "queue", "event", "selector", "traversing", "attributes", "manipulation", "css", "ajax", "effects", "offset", "dimensions", "outro" ]
1+
prefix = File.dirname( __FILE__ )
32

4-
date = `git log -1 | grep Date: | sed 's/[^:]*: *//'`.gsub(/\n/, "")
5-
version = `cat version.txt`.gsub(/\n/, "")
3+
# Directory variables
4+
src_dir = File.join( prefix, 'src' )
5+
build_dir = File.join( prefix, 'build' )
6+
test_dir = File.join( prefix, 'test' )
67

7-
task :default => :jquery
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' )
811

9-
task :init do
10-
sh "if test ! -d test/qunit; then git clone git://github.com/jquery/qunit.git test/qunit; fi"
11-
sh "if test ! -d src/sizzle; then git clone git://github.com/jeresig/sizzle.git src/sizzle; fi"
12-
sh "cd src/sizzle && git pull origin master &> /dev/null"
13-
sh "cd test/qunit && git pull origin master &> /dev/null"
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" ) }
13+
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" )
18+
19+
qunit_dir = File.join( test_dir, "qunit" )
20+
qunit = File.join( qunit_dir, "qunit", "qunit.js" )
21+
22+
jq = File.join( dist_dir, "jquery.js" )
23+
jq_min = File.join( dist_dir, "jquery.min.js" )
24+
25+
# General Variables
26+
date = `git log -1 | grep Date: | sed 's/[^:]*: *//'`.strip
27+
version = File.read( File.join( prefix, 'version.txt' ) ).strip
28+
29+
# Build tools
30+
rhino = "java -jar #{build_dir}/js.jar"
31+
minfier = "java -jar #{build_dir}/google-compiler-20091218.jar"
32+
33+
# Turn off output other than needed from `sh` and file commands
34+
verbose(false)
35+
36+
37+
# Tasks
38+
task :default => "jquery"
39+
40+
desc "Builds jQuery; Tests with JSLint; Minifies jQuery"
41+
task :all => [:jquery, :lint, :min] do
42+
puts "jQuery build complete."
43+
end
44+
45+
desc "Builds jQuery: jquery.js (Default task)"
46+
task :jquery => [:selector, jq]
47+
48+
desc "Builds a minified version of jQuery: jquery.min.js"
49+
task :min => jq_min
50+
51+
52+
task :init => [sizzle, qunit] do
53+
puts "Updating SizzleJS with latest..."
54+
sh "cd #{sizzle_dir} && git pull origin master &> /dev/null"
55+
56+
puts "Updating QUnit with latest..."
57+
sh "cd #{qunit_dir} && git pull origin master &> /dev/null"
1458
end
1559

16-
task :jquery => [:init, :selector] do
17-
sh "mkdir -p dist"
60+
desc "Removes dist folder, selector.js, and Sizzle/QUnit"
61+
task :clean do
62+
puts "Removing Distribution directory: #{dist_dir}..."
63+
rm_r dist_dir
64+
65+
puts "Removing built copy of Sizzle..."
66+
rm_r selector
67+
68+
puts "Removing cloned directories..."
69+
rm_r qunit_dir
70+
rm_r sizzle_dir
71+
end
72+
73+
desc "Rebuilds selector.js from SizzleJS"
74+
task :selector => [:init, selector]
75+
76+
desc "Tests built jquery.js against JSLint"
77+
task :lint => jq do
78+
puts "Checking jQuery against JSLint..."
79+
sh "#{rhino} #{build_dir}/jslint-check.js"
80+
end
81+
82+
83+
# File and Directory Dependencies
84+
directory dist_dir
85+
86+
file jq => [dist_dir, base_files].flatten do
87+
puts "Building jquery.js..."
88+
sh "cat #{base_files.join(' ')} | sed 's/Date:./&#{date}/' | sed s/@VERSION/#{version}/ > #{jq}"
89+
end
90+
91+
file jq_min => jq do
92+
puts "Building jquery.min.js..."
93+
94+
sh "head -15 #{jq} > #{jq_min}"
95+
sh "#{minfier} --js #{jq} --warning_level QUIET >> #{jq_min}"
96+
end
97+
98+
file selector => [sizzle] do
99+
puts "Building selector code from Sizzle..."
100+
sh "sed '/EXPOSE/r #{src_dir}/sizzle-jquery.js' #{sizzle} > #{selector}"
101+
end
18102

19-
sh "cat " + files.map {|file| "src/" + file + ".js"}.join(" ") +
20-
" | sed 's/Date:./&" + date + "/' | " +
21-
" sed s/@VERSION/" + version + "/ > dist/jquery.js"
103+
file sizzle do
104+
puts "Retrieving SizzleJS from Github..."
105+
sh "git clone git://github.com/jeresig/sizzle.git #{sizzle_dir}"
22106
end
23107

24-
task :selector do
25-
sh "sed '/EXPOSE/r src/sizzle-jquery.js' src/sizzle/sizzle.js > src/selector.js"
108+
file qunit do
109+
puts "Retrieving SizzleJS from Github..."
110+
sh "git clone git://github.com/jquery/qunit.git #{qunit_dir}"
26111
end

0 commit comments

Comments
 (0)