1.12.1
[jquery.git] / Gruntfile.js
blob41d7b616d781c817d21528ad252c90d69452ed69
1 module.exports = function( grunt ) {
2         "use strict";
4         function readOptionalJSON( filepath ) {
5                 var data = {};
6                 try {
7                         data = JSON.parse( stripJSONComments(
8                                 fs.readFileSync( filepath, { encoding: "utf8" } )
9                         ) );
10                 } catch ( e ) {}
11                 return data;
12         }
14         var fs = require( "fs" ),
15                 stripJSONComments = require( "strip-json-comments" ),
16                 gzip = require( "gzip-js" ),
17                 srcHintOptions = readOptionalJSON( "src/.jshintrc" ),
18                 newNode = !/^v0/.test( process.version ),
20                 // Allow to skip jsdom-related tests in Node.js < 1.0.0
21                 runJsdomTests = newNode || ( function() {
22                         try {
23                                 require( "jsdom" );
24                                 return true;
25                         } catch ( e ) {
26                                 return false;
27                         }
28                 } )();
30         // The concatenated file won't pass onevar
31         // But our modules can
32         delete srcHintOptions.onevar;
34         grunt.initConfig( {
35                 pkg: grunt.file.readJSON( "package.json" ),
36                 dst: readOptionalJSON( "dist/.destination.json" ),
37                 "compare_size": {
38                         files: [ "dist/jquery.js", "dist/jquery.min.js" ],
39                         options: {
40                                 compress: {
41                                         gz: function( contents ) {
42                                                 return gzip.zip( contents, {} ).length;
43                                         }
44                                 },
45                                 cache: "build/.sizecache.json"
46                         }
47                 },
48                 babel: {
49                         options: {
50                                 sourceMap: "inline",
51                                 retainLines: true
52                         },
53                         nodeSmokeTests: {
54                                 files: {
55                                         "test/node_smoke_tests/lib/ensure_iterability.js":
56                                                 "test/node_smoke_tests/lib/ensure_iterability_es6.js"
57                                 }
58                         }
59                 },
60                 build: {
61                         all: {
62                                 dest: "dist/jquery.js",
63                                 minimum: [
64                                         "core",
65                                         "selector"
66                                 ],
67                                 removeWith: {
68                                         ajax: [ "manipulation/_evalUrl", "event/ajax" ],
69                                         callbacks: [ "deferred" ],
70                                         css: [ "effects", "dimensions", "offset" ]
71                                 }
72                         }
73                 },
74                 npmcopy: {
75                         all: {
76                                 options: {
77                                         destPrefix: "external"
78                                 },
79                                 files: {
80                                         "sizzle/dist": "sizzle/dist",
81                                         "sizzle/LICENSE.txt": "sizzle/LICENSE.txt",
83                                         "qunit/qunit.js": "qunitjs/qunit/qunit.js",
84                                         "qunit/qunit.css": "qunitjs/qunit/qunit.css",
85                                         "qunit/LICENSE.txt": "qunitjs/LICENSE.txt",
87                                         "qunit-assert-step/qunit-assert-step.js":
88                                         "qunit-assert-step/qunit-assert-step.js",
89                                         "qunit-assert-step/MIT-LICENSE.txt":
90                                         "qunit-assert-step/MIT-LICENSE.txt",
92                                         "requirejs/require.js": "requirejs/require.js",
94                                         "sinon/fake_timers.js": "sinon/lib/sinon/util/fake_timers.js",
95                                         "sinon/timers_ie.js": "sinon/lib/sinon/util/timers_ie.js",
96                                         "sinon/LICENSE.txt": "sinon/LICENSE"
97                                 }
98                         }
99                 },
100                 jsonlint: {
101                         pkg: {
102                                 src: [ "package.json" ]
103                         }
104                 },
105                 jshint: {
106                         all: {
107                                 src: [
108                                         "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js"
109                                 ],
110                                 options: {
111                                         jshintrc: true
112                                 }
113                         },
114                         dist: {
115                                 src: "dist/jquery.js",
116                                 options: srcHintOptions
117                         }
118                 },
119                 jscs: {
120                         src: "src",
121                         gruntfile: "Gruntfile.js",
123                         // Check parts of tests that pass
124                         test: [
125                                 "test/data/testrunner.js",
126                                 "test/unit/basic.js",
127                                 "test/unit/wrap.js"
128                         ],
129                         build: "build"
130                 },
131                 testswarm: {
132                         tests: [
134                                 // A special module with basic tests, meant for
135                                 // not fully supported environments like Android 2.3,
136                                 // jsdom or PhantomJS. We run it everywhere, though,
137                                 // to make sure tests are not broken.
138                                 "basic",
140                                 "ajax",
141                                 "attributes",
142                                 "callbacks",
143                                 "core",
144                                 "css",
145                                 "data",
146                                 "deferred",
147                                 "deprecated",
148                                 "dimensions",
149                                 "effects",
150                                 "event",
151                                 "manipulation",
152                                 "offset",
153                                 "queue",
154                                 "selector",
155                                 "serialize",
156                                 "support",
157                                 "traversing"
158                         ]
159                 },
160                 watch: {
161                         files: [ "<%= jshint.all.src %>" ],
162                         tasks: [ "dev" ]
163                 },
164                 uglify: {
165                         all: {
166                                 files: {
167                                         "dist/jquery.min.js": [ "dist/jquery.js" ]
168                                 },
169                                 options: {
170                                         preserveComments: false,
171                                         sourceMap: true,
172                                         sourceMapName: "dist/jquery.min.map",
173                                         report: "min",
174                                         beautify: {
175                                                 "ascii_only": true
176                                         },
177                                         banner: "/*! jQuery v<%= pkg.version %> | " +
178                                                 "(c) jQuery Foundation | jquery.org/license */",
179                                         compress: {
180                                                 "hoist_funs": false,
181                                                 loops: false,
182                                                 unused: false
183                                         }
184                                 }
185                         }
186                 }
187         } );
189         // Load grunt tasks from NPM packages
190         require( "load-grunt-tasks" )( grunt );
192         // Integrate jQuery specific tasks
193         grunt.loadTasks( "build/tasks" );
195         grunt.registerTask( "lint", [ "jsonlint", "jshint", "jscs" ] );
197         // Don't run Node-related tests in Node.js < 1.0.0 as they require an old
198         // jsdom version that needs compiling, making it harder for people to compile
199         // jQuery on Windows. (see gh-2519)
200         grunt.registerTask( "test_fast", runJsdomTests ? [ "node_smoke_tests" ] : [] );
202         grunt.registerTask( "test", [ "test_fast" ] );
204         // Short list as a high frequency watch task
205         grunt.registerTask( "dev", [ "build:*:*", "lint", "uglify", "remove_map_comment", "dist:*" ] );
207         grunt.registerTask( "default", [ "dev", "test_fast", "compare_size" ] );