Removes temp var, shaves 2 bytes from gzipped size
[jquery.git] / grunt.js
blobbdc6e8a1d9ba1b42cab7bd5b5b3c19d104cb7e28
1 // Resources
2 // https://gist.github.com/2489540
4 /*global config:true, task:true*/
5 module.exports = function( grunt ) {
7         var task = grunt.task;
8         var file = grunt.file;
9         var utils = grunt.utils;
10         var log = grunt.log;
11         var verbose = grunt.verbose;
12         var fail = grunt.fail;
13         var option = grunt.option;
14         var config = grunt.config;
15         var template = grunt.template;
17         grunt.initConfig({
18                 pkg: "<json:package.json>",
19                 meta: {
20                         banner: "/*! jQuery v@<%= pkg.version %> jquery.com | jquery.org/license */"
21                 },
22                 compare_size: {
23                         files: [
24                                 "dist/jquery.js",
25                                 "dist/jquery.min.js"
26                         ]
27                 },
28                 selector: {
29                         "src/selector.js": [
30                                 "src/sizzle-jquery.js",
31                                 "src/sizzle/sizzle.js"
32                         ]
33                 },
34                 build: {
35                         "dist/jquery.js": [
36                                 "src/intro.js",
37                                 "src/core.js",
38                                 "src/callbacks.js",
39                                 "src/deferred.js",
40                                 "src/support.js",
41                                 "src/data.js",
42                                 "src/queue.js",
43                                 "src/attributes.js",
44                                 "src/event.js",
45                                 "src/selector.js",
46                                 "src/traversing.js",
47                                 "src/manipulation.js",
48                                 "src/css.js",
49                                 "src/ajax.js",
50                                 "src/ajax/jsonp.js",
51                                 "src/ajax/script.js",
52                                 "src/ajax/xhr.js",
53                                 { flag: "effects", src: "src/effects.js" },
54                                 "src/offset.js",
55                                 "src/dimensions.js",
56                                 "src/exports.js",
57                                 "src/outro.js"
58                         ]
59                 },
60                 min: {
61                         "dist/jquery.min.js": [ "<banner>", "dist/jquery.js" ]
62                 },
63                 lint: {
64                         files: [ "grunt.js", "dist/jquery.js" ]
65                 },
66                 qunit: {
67                         files: "test/index.html"
68                 },
69                 watch: {
70                         files: "<config:lint.files>",
71                         tasks: "concat lint"
72                 },
73                 jshint: {
74                         options: {
75                                 evil: true,
76                                 browser: true,
77                                 wsh: true,
78                                 eqnull: true,
79                                 expr: true,
80                                 curly: true,
81                                 trailing: true,
82                                 undef: true,
83                                 smarttabs: true,
84                                 predef: [
85                                         "define",
86                                         "DOMParser",
87                                         "__dirname"
88                                 ],
89                                 maxerr: 100
90                         },
91                         globals: {
92                                 jQuery: true,
93                                 global: true,
94                                 module: true,
95                                 exports: true,
96                                 require: true,
97                                 file: true,
98                                 log: true,
99                                 console: true
100                         }
101                 },
102                 uglify: {}
103         });
105         // Default grunt.
106         grunt.registerTask( "default", "selector build:*:* lint min compare_size" );
108         grunt.loadNpmTasks("grunt-compare-size");
110         grunt.registerTask( "testswarm", function( commit, configFile ) {
111                 var testswarm = require( "testswarm" ),
112                         testUrls = [];
113                 var tests = "ajax attributes callbacks core css data deferred dimensions effects event manipulation offset queue selector support traversing".split( " " );
114                 tests.forEach(function( test ) {
115                         testUrls.push( "http://swarm.jquery.org/git/jquery/" + commit + "/test/index.html?filter=" + test );
116                 });
117                 testswarm({
118                         url: "http://swarm.jquery.org/",
119                         pollInterval: 10000,
120                         timeout: 1000 * 60 * 30,
121                         done: this.async()
122                 }, {
123                         authUsername: "jquery",
124                         authToken: grunt.file.readJSON( configFile ).jquery.authToken,
125                         jobName: 'jQuery commit #<a href="https://github.com/jquery/jquery/commit/' + commit + '">' + commit.substr( 0, 10 ) + '</a>',
126                         runMax: 4,
127                         "runNames[]": tests,
128                         "runUrls[]": testUrls,
129                         "browserSets[]": ["popular"]
130                 });
131         });
133         // Build src/selector.js
134         grunt.registerMultiTask( "selector", "Build src/selector.js", function() {
136                 var name = this.file.dest,
137                                 files = this.file.src,
138                                 sizzle = {
139                                         api: file.read( files[0] ),
140                                         src: file.read( files[1] )
141                                 },
142                                 compiled;
144                 // sizzle-jquery.js -> sizzle after "EXPOSE", replace window.Sizzle
145                 compiled = sizzle.src.replace( "window.Sizzle = Sizzle;", sizzle.api );
146                 verbose.write("Injected sizzle-jquery.js into sizzle.js");
148                 // Write concatenated source to file
149                 file.write( name, compiled );
151                 // Fail task if errors were logged.
152                 if ( this.errorCount ) {
153                         return false;
154                 }
156                 // Otherwise, print a success message.
157                 log.writeln( "File '" + name + "' created." );
158         });
161         // Special concat/build task to handle various jQuery build requirements
162         grunt.registerMultiTask(
163                 "build",
164                 "Concatenate source (include/exclude modules with +/- flags), embed date/version",
165                 function() {
166                         // Concat specified files.
167                         var compiled = "",
168                                         modules = this.flags,
169                                         optIn = !modules["*"],
170                                         name = this.file.dest;
172                         this.file.src.forEach(function( filepath ) {
173                                 // Include optional modules per build flags; exclusion trumps inclusion
174                                 var flag = filepath.flag;
175                                 if ( flag ) {
176                                         if ( modules[ "-" + flag ] ||
177                                                 optIn && !modules[ flag ] && !modules[ "+" + flag ] ) {
179                                                 log.writeln( "Excluding " + filepath.flag + ": '" + filepath.src + "'." );
180                                                 return;
181                                         }
182                                         log.writeln( "Including " + filepath.flag + ": '" + filepath.src + "'." );
183                                         filepath = filepath.src;
184                                 }
186                                 // Unwrap redundant IIFEs
187                                 compiled += file.read( filepath ).replace( /^\(function\( jQuery \) \{|\}\)\( jQuery \);\s*$/g, "" );
188                         });
190                         // Embed Date
191                         // Embed Version
192                         compiled = compiled.replace( "@DATE", new Date() )
193                                                                                 .replace( "@VERSION", config("pkg.version") );
195                         // Write concatenated source to file
196                         file.write( name, compiled );
198                         // Fail task if errors were logged.
199                         if ( this.errorCount ) {
200                                 return false;
201                         }
203                         // Otherwise, print a success message.
204                         log.writeln( "File '" + name + "' created." );
205                 });