@@ -67,6 +67,8 @@ cssFiles.forEach(function( file ) {
67
67
68
68
// csslint and cssmin tasks
69
69
grunt . loadNpmTasks ( "grunt-css" ) ;
70
+ // file size comparison tasks
71
+ grunt . loadNpmTasks ( "grunt-compare-size" ) ;
70
72
71
73
grunt . registerHelper ( "strip_all_banners" , function ( filepath ) {
72
74
return grunt . file . read ( filepath ) . replace ( / ^ \s * \/ \* [ \s \S ] * ?\* \/ \s * / g, "" ) ;
@@ -508,77 +510,6 @@ grunt.registerTask( "clean", function() {
508
510
require ( "rimraf" ) . sync ( "dist" ) ;
509
511
} ) ;
510
512
511
- // TODO merge with code in jQuery Core, share as grunt plugin/npm
512
- // this here actually uses the provided filenames in the output
513
- // the helpers should just be regular functions, no need to share those with the world
514
- grunt . registerMultiTask ( "compare_size" , "Compare size of this branch to master" , function ( ) {
515
- var files = grunt . file . expandFiles ( this . file . src ) ,
516
- done = this . async ( ) ,
517
- sizecache = __dirname + "/dist/.sizecache.json" ,
518
- sources = {
519
- min : grunt . file . read ( files [ 1 ] ) ,
520
- max : grunt . file . read ( files [ 0 ] )
521
- } ,
522
- oldsizes = { } ,
523
- sizes = { } ;
524
-
525
- try {
526
- oldsizes = JSON . parse ( grunt . file . read ( sizecache ) ) ;
527
- } catch ( e ) {
528
- oldsizes = { } ;
529
- }
530
-
531
- // Obtain the current branch and continue...
532
- grunt . helper ( "git_current_branch" , function ( err , branch ) {
533
- var key , diff ;
534
-
535
- // Derived and adapted from Corey Frang's original `sizer`
536
- grunt . log . writeln ( "sizes - compared to master" ) ;
537
-
538
- sizes [ files [ 0 ] ] = sources . max . length ;
539
- sizes [ files [ 1 ] ] = sources . min . length ;
540
- sizes [ files [ 1 ] + ".gz" ] = grunt . helper ( "gzip" , sources . min ) . length ;
541
-
542
- for ( key in sizes ) {
543
- diff = oldsizes [ key ] && ( sizes [ key ] - oldsizes [ key ] ) ;
544
- if ( diff > 0 ) {
545
- diff = "+" + diff ;
546
- }
547
- console . log ( "%s %s %s" ,
548
- grunt . helper ( "lpad" , sizes [ key ] , 8 ) ,
549
- grunt . helper ( "lpad" , diff ? "(" + diff + ")" : "(-)" , 8 ) ,
550
- key
551
- ) ;
552
- }
553
-
554
- if ( branch === "master" ) {
555
- // If master, write to file - this makes it easier to compare
556
- // the size of your current code state to the master branch,
557
- // without returning to the master to reset the cache
558
- grunt . file . write ( sizecache , JSON . stringify ( sizes ) ) ;
559
- }
560
- done ( ) ;
561
- } ) ;
562
- } ) ;
563
- grunt . registerHelper ( "git_current_branch" , function ( done ) {
564
- grunt . utils . spawn ( {
565
- cmd : "git" ,
566
- args : [ "branch" , "--no-color" ]
567
- } , function ( err , result ) {
568
- var branch ;
569
-
570
- result . split ( "\n" ) . forEach ( function ( branch ) {
571
- var matches = / ^ \* ( .* ) / . exec ( branch ) ;
572
- if ( matches !== null && matches . length && matches [ 1 ] ) {
573
- done ( null , matches [ 1 ] ) ;
574
- }
575
- } ) ;
576
- } ) ;
577
- } ) ;
578
- grunt . registerHelper ( "lpad" , function ( str , len , chr ) {
579
- return ( Array ( len + 1 ) . join ( chr || " " ) + str ) . substr ( - len ) ;
580
- } ) ;
581
-
582
513
grunt . registerTask ( "default" , "lint csslint qunit build compare_size" ) ;
583
514
grunt . registerTask ( "sizer" , "concat:ui min:dist/jquery-ui.min.js compare_size" ) ;
584
515
grunt . registerTask ( "build" , "concat min cssmin" ) ;
0 commit comments