1
- /**
2
- * Resources
3
- *
4
- * https://gist.github.com/2489540
5
- */
6
-
7
1
module . exports = function ( grunt ) {
8
2
9
3
"use strict" ;
10
4
11
- // readOptionalJSON
12
- // by Ben Alman
13
- // https://gist.github.com/2876125
14
- function readOptionalJSON ( filepath ) {
15
- var data = { } ;
16
- try {
17
- data = grunt . file . readJSON ( filepath ) ;
18
- grunt . verbose . write ( "Reading " + filepath + "..." ) . ok ( ) ;
19
- } catch ( e ) { }
20
- return data ;
21
- }
22
-
23
- var file = grunt . file ,
24
- log = grunt . log ,
25
- verbose = grunt . verbose ,
26
- config = grunt . config ,
27
- distpaths = [
5
+ var distpaths = [
28
6
"dist/jquery.js" ,
29
7
"dist/jquery.min.js"
30
- ] ;
8
+ ] ,
9
+ readOptionalJSON = function ( filepath ) {
10
+ var data = { } ;
11
+ try {
12
+ data = grunt . file . readJSON ( filepath ) ;
13
+ } catch ( e ) { }
14
+ return data ;
15
+ } ;
31
16
32
17
grunt . initConfig ( {
33
- pkg : "<json: package.json>" ,
18
+ pkg : grunt . file . readJSON ( " package.json" ) ,
34
19
dst : readOptionalJSON ( "dist/.destination.json" ) ,
35
- meta : {
36
- banner : "/*! jQuery v<%= pkg.version %> jquery.com | jquery.org/license */"
37
- } ,
38
20
compare_size : {
39
21
files : distpaths
40
22
} ,
@@ -74,69 +56,54 @@ module.exports = function( grunt ) {
74
56
"src/outro.js"
75
57
]
76
58
} ,
77
- min : {
78
- "dist/jquery.min.js" : [ "<banner>" , "dist/jquery.js" ]
79
- } ,
80
-
81
- lint : {
82
- dist : "dist/jquery.js" ,
83
- grunt : "grunt.js" ,
84
- // TODO: Once .jshintignore is supported, use that instead.
85
- tests : [ "test/data/{test,testinit,testrunner}.js" , "test/unit/**/*.js" ]
86
- } ,
87
59
88
- jshint : ( function ( ) {
89
- function jshintrc ( path ) {
90
- return readOptionalJSON ( ( path || "" ) + ".jshintrc" ) || { } ;
91
- }
92
-
93
- return {
94
- grunt : {
95
- options : jshintrc ( )
96
- } ,
97
- dist : {
98
- options : jshintrc ( "src/" )
99
- } ,
100
- tests : {
101
- options : jshintrc ( "test/" )
60
+ jshint : {
61
+ dist : {
62
+ src : [ "dist/jquery.js" ] ,
63
+ options : {
64
+ jshintrc : "src/.jshintrc"
102
65
}
103
- } ;
104
- } ) ( ) ,
105
-
106
- qunit : {
107
- files : "test/index.html"
66
+ } ,
67
+ grunt : {
68
+ src : [ "Gruntfile.js" ] ,
69
+ options : {
70
+ jshintrc : ".jshintrc"
71
+ }
72
+ } ,
73
+ tests : {
74
+ // TODO: Once .jshintignore is supported, use that instead.
75
+ src : [ "test/data/{test,testinit,testrunner}.js" , "test/unit/**/*.js" ] ,
76
+ options : {
77
+ jshintrc : "test/.jshintrc"
78
+ }
79
+ }
108
80
} ,
109
81
110
82
testswarm : {
111
83
tests : "ajax attributes callbacks core css data deferred dimensions effects event manipulation offset queue selector serialize support traversing Sizzle" . split ( " " )
112
84
} ,
113
85
114
86
watch : {
115
- files : [
116
- "<config:lint.grunt>" , "<config:lint.tests>" ,
117
- "src/**/*.js"
118
- ] ,
87
+ files : [ "<%= jshint.grunt.src %>" , "<%= jshint.tests.src %>" , "src/**/*.js" ] ,
119
88
tasks : "dev"
120
89
} ,
121
90
122
91
uglify : {
123
- codegen : {
124
- ascii_only : true
92
+ all : {
93
+ files : {
94
+ "dist/jquery.min.js" : [ "dist/jquery.js" ]
95
+ } ,
96
+ options : {
97
+ banner : "/*! jQuery v<%= pkg.version %> jquery.com | jquery.org/license */" ,
98
+ sourceMap : "dist/jquery.source-map.js" ,
99
+ beautify : {
100
+ ascii_only : true
101
+ }
102
+ }
125
103
}
126
104
}
127
105
} ) ;
128
106
129
- // Default grunt.
130
- grunt . registerTask ( "default" , "update_submodules selector build:*:* lint min dist:* compare_size" ) ;
131
-
132
- // Short list as a high frequency watch task
133
- grunt . registerTask ( "dev" , "selector build:*:* lint" ) ;
134
-
135
- // Load grunt tasks from NPM packages
136
- grunt . loadNpmTasks ( "grunt-compare-size" ) ;
137
- grunt . loadNpmTasks ( "grunt-git-authors" ) ;
138
- grunt . loadNpmTasks ( "grunt-update-submodules" ) ;
139
-
140
107
grunt . registerTask ( "testswarm" , function ( commit , configFile ) {
141
108
var jobName ,
142
109
testswarm = require ( "testswarm" ) ,
@@ -179,8 +146,8 @@ module.exports = function( grunt ) {
179
146
var name = this . file . dest ,
180
147
files = this . file . src ,
181
148
sizzle = {
182
- api : file . read ( files [ 0 ] ) ,
183
- src : file . read ( files [ 1 ] )
149
+ api : grunt . file . read ( files [ 0 ] ) ,
150
+ src : grunt . file . read ( files [ 1 ] )
184
151
} ,
185
152
compiled , parts ;
186
153
@@ -218,19 +185,18 @@ module.exports = function( grunt ) {
218
185
// Rejoin the pieces
219
186
compiled = parts . join ( "" ) ;
220
187
221
-
222
- verbose . write ( "Injected sizzle-jquery.js into sizzle.js" ) ;
188
+ grunt . verbose . write ( "Injected sizzle-jquery.js into sizzle.js" ) ;
223
189
224
190
// Write concatenated source to file
225
- file . write ( name , compiled ) ;
191
+ grunt . file . write ( name , compiled ) ;
226
192
227
193
// Fail task if errors were logged.
228
194
if ( this . errorCount ) {
229
195
return false ;
230
196
}
231
197
232
198
// Otherwise, print a success message.
233
- log . writeln ( "File '" + name + "' created." ) ;
199
+ grunt . log . writeln ( "File '" + name + "' created." ) ;
234
200
} ) ;
235
201
236
202
@@ -251,17 +217,17 @@ module.exports = function( grunt ) {
251
217
252
218
grunt . log . writeln ( "Creating custom build...\n" ) ;
253
219
254
- grunt . utils . spawn ( {
220
+ grunt . util . spawn ( {
255
221
cmd : process . platform === "win32" ? "grunt.cmd" : "grunt" ,
256
- args : [ "build:*:*:" + modules , "min " ]
222
+ args : [ "build:*:*:" + modules , "uglify " ]
257
223
} , function ( err , result ) {
258
224
if ( err ) {
259
225
grunt . verbose . error ( ) ;
260
226
done ( err ) ;
261
227
return ;
262
228
}
263
229
264
- grunt . log . writeln ( result . replace ( "Done, without errors." , "" ) ) ;
230
+ grunt . log . writeln ( result . stdout . replace ( "Done, without errors." , "" ) ) ;
265
231
266
232
done ( ) ;
267
233
} ) ;
@@ -279,9 +245,10 @@ module.exports = function( grunt ) {
279
245
optIn = ! modules [ "*" ] ,
280
246
explicit = optIn || Object . keys ( modules ) . length > 1 ,
281
247
name = this . file . dest ,
248
+ src = this . file . srcRaw ,
282
249
deps = { } ,
283
250
excluded = { } ,
284
- version = config ( "pkg.version" ) ,
251
+ version = grunt . config ( "pkg.version" ) ,
285
252
excluder = function ( flag , needsFlag ) {
286
253
// optIn defaults implicit behavior to weak exclusion
287
254
if ( optIn && ! modules [ flag ] && ! modules [ "+" + flag ] ) {
@@ -325,7 +292,7 @@ module.exports = function( grunt ) {
325
292
// *:*:-css all except css and dependents (explicit > implicit)
326
293
// *:*:-css:+effects same (excludes effects because explicit include is trumped by explicit exclude of dependency)
327
294
// *:+effects none except effects and its dependencies (explicit include trumps implicit exclude of dependency)
328
- this . file . src . forEach ( function ( filepath ) {
295
+ src . forEach ( function ( filepath ) {
329
296
var flag = filepath . flag ;
330
297
331
298
if ( flag ) {
@@ -351,7 +318,7 @@ module.exports = function( grunt ) {
351
318
352
319
353
320
// conditionally concatenate source
354
- this . file . src . forEach ( function ( filepath ) {
321
+ src . forEach ( function ( filepath ) {
355
322
var flag = filepath . flag ,
356
323
specified = false ,
357
324
omit = false ,
@@ -389,7 +356,7 @@ module.exports = function( grunt ) {
389
356
}
390
357
391
358
if ( ! omit ) {
392
- compiled += file . read ( filepath ) ;
359
+ compiled += grunt . file . read ( filepath ) ;
393
360
}
394
361
} ) ;
395
362
@@ -408,15 +375,15 @@ module.exports = function( grunt ) {
408
375
} ) ;
409
376
410
377
// Write concatenated source to file
411
- file . write ( name , compiled ) ;
378
+ grunt . file . write ( name , compiled ) ;
412
379
413
380
// Fail task if errors were logged.
414
381
if ( this . errorCount ) {
415
382
return false ;
416
383
}
417
384
418
385
// Otherwise, print a success message.
419
- log . writeln ( "File '" + name + "' created." ) ;
386
+ grunt . log . writeln ( "File '" + name + "' created." ) ;
420
387
} ) ;
421
388
422
389
// Allow custom dist file locations
@@ -425,7 +392,7 @@ module.exports = function( grunt ) {
425
392
426
393
// Check for stored destination paths
427
394
// ( set in dist/.destination.json )
428
- stored = Object . keys ( config ( "dst" ) ) ;
395
+ stored = Object . keys ( grunt . config ( "dst" ) ) ;
429
396
430
397
// Allow command line input as well
431
398
flags = Object . keys ( this . flags ) ;
@@ -438,16 +405,17 @@ module.exports = function( grunt ) {
438
405
// Ensure the dist files are pure ASCII
439
406
var fs = require ( "fs" ) ,
440
407
nonascii = false ;
408
+
441
409
distpaths . forEach ( function ( filename ) {
442
410
var buf = fs . readFileSync ( filename , "utf8" ) ,
443
411
i , c ;
444
412
if ( buf . length !== Buffer . byteLength ( buf , "utf8" ) ) {
445
- log . writeln ( filename + ": Non-ASCII characters detected:" ) ;
413
+ grunt . log . writeln ( filename + ": Non-ASCII characters detected:" ) ;
446
414
for ( i = 0 ; i < buf . length ; i ++ ) {
447
415
c = buf . charCodeAt ( i ) ;
448
416
if ( c > 127 ) {
449
- log . writeln ( "- position " + i + ": " + c ) ;
450
- log . writeln ( "-- " + buf . substring ( i - 20 , i + 20 ) ) ;
417
+ grunt . log . writeln ( "- position " + i + ": " + c ) ;
418
+ grunt . log . writeln ( "-- " + buf . substring ( i - 20 , i + 20 ) ) ;
451
419
nonascii = true ;
452
420
}
453
421
}
@@ -474,11 +442,27 @@ module.exports = function( grunt ) {
474
442
475
443
created = path + filename . replace ( "dist/" , "" ) ;
476
444
477
- file . write ( created , file . read ( filename ) ) ;
445
+ grunt . file . write ( created , grunt . file . read ( filename ) ) ;
478
446
479
- log . writeln ( "File '" + created + "' created." ) ;
447
+ grunt . log . writeln ( "File '" + created + "' created." ) ;
480
448
} ) ;
481
449
} ) ;
482
450
}
483
451
} ) ;
452
+
453
+ // Load grunt tasks from NPM packages
454
+ grunt . loadNpmTasks ( "grunt-compare-size" ) ;
455
+ grunt . loadNpmTasks ( "grunt-git-authors" ) ;
456
+ grunt . loadNpmTasks ( "grunt-update-submodules" ) ;
457
+
458
+ // grunt contrib tasks
459
+ grunt . loadNpmTasks ( "grunt-contrib-watch" ) ;
460
+ grunt . loadNpmTasks ( "grunt-contrib-jshint" ) ;
461
+ grunt . loadNpmTasks ( "grunt-contrib-uglify" ) ;
462
+
463
+ // Default grunt
464
+ grunt . registerTask ( "default" , [ "update_submodules" , "selector" , "build:*:*" , "jshint" , "uglify" , "dist:*" , "compare_size" ] ) ;
465
+
466
+ // Short list as a high frequency watch task
467
+ grunt . registerTask ( "dev" , [ "selector" , "build:*:*" , "jshint" ] ) ;
484
468
} ;
0 commit comments