@@ -70,6 +70,8 @@ cssFiles.forEach(function( file ) {
70
70
71
71
// csslint and cssmin tasks
72
72
grunt . loadNpmTasks ( "grunt-css" ) ;
73
+ // file size comparison tasks
74
+ grunt . loadNpmTasks ( "grunt-compare-size" ) ;
73
75
74
76
grunt . registerHelper ( "strip_all_banners" , function ( filepath ) {
75
77
return grunt . file . read ( filepath ) . replace ( / ^ \s * \/ \* [ \s \S ] * ?\* \/ \s * / g, "" ) ;
@@ -537,77 +539,6 @@ grunt.registerTask( "clean", function() {
537
539
require ( "rimraf" ) . sync ( "dist" ) ;
538
540
} ) ;
539
541
540
- // TODO merge with code in jQuery Core, share as grunt plugin/npm
541
- // this here actually uses the provided filenames in the output
542
- // the helpers should just be regular functions, no need to share those with the world
543
- grunt . registerMultiTask ( "compare_size" , "Compare size of this branch to master" , function ( ) {
544
- var files = grunt . file . expandFiles ( this . file . src ) ,
545
- done = this . async ( ) ,
546
- sizecache = __dirname + "/dist/.sizecache.json" ,
547
- sources = {
548
- min : grunt . file . read ( files [ 1 ] ) ,
549
- max : grunt . file . read ( files [ 0 ] )
550
- } ,
551
- oldsizes = { } ,
552
- sizes = { } ;
553
-
554
- try {
555
- oldsizes = JSON . parse ( grunt . file . read ( sizecache ) ) ;
556
- } catch ( e ) {
557
- oldsizes = { } ;
558
- }
559
-
560
- // Obtain the current branch and continue...
561
- grunt . helper ( "git_current_branch" , function ( err , branch ) {
562
- var key , diff ;
563
-
564
- // Derived and adapted from Corey Frang's original `sizer`
565
- grunt . log . writeln ( "sizes - compared to master" ) ;
566
-
567
- sizes [ files [ 0 ] ] = sources . max . length ;
568
- sizes [ files [ 1 ] ] = sources . min . length ;
569
- sizes [ files [ 1 ] + ".gz" ] = grunt . helper ( "gzip" , sources . min ) . length ;
570
-
571
- for ( key in sizes ) {
572
- diff = oldsizes [ key ] && ( sizes [ key ] - oldsizes [ key ] ) ;
573
- if ( diff > 0 ) {
574
- diff = "+" + diff ;
575
- }
576
- console . log ( "%s %s %s" ,
577
- grunt . helper ( "lpad" , sizes [ key ] , 8 ) ,
578
- grunt . helper ( "lpad" , diff ? "(" + diff + ")" : "(-)" , 8 ) ,
579
- key
580
- ) ;
581
- }
582
-
583
- if ( branch === "master" ) {
584
- // If master, write to file - this makes it easier to compare
585
- // the size of your current code state to the master branch,
586
- // without returning to the master to reset the cache
587
- grunt . file . write ( sizecache , JSON . stringify ( sizes ) ) ;
588
- }
589
- done ( ) ;
590
- } ) ;
591
- } ) ;
592
- grunt . registerHelper ( "git_current_branch" , function ( done ) {
593
- grunt . utils . spawn ( {
594
- cmd : "git" ,
595
- args : [ "branch" , "--no-color" ]
596
- } , function ( err , result ) {
597
- var branch ;
598
-
599
- result . split ( "\n" ) . forEach ( function ( branch ) {
600
- var matches = / ^ \* ( .* ) / . exec ( branch ) ;
601
- if ( matches !== null && matches . length && matches [ 1 ] ) {
602
- done ( null , matches [ 1 ] ) ;
603
- }
604
- } ) ;
605
- } ) ;
606
- } ) ;
607
- grunt . registerHelper ( "lpad" , function ( str , len , chr ) {
608
- return ( Array ( len + 1 ) . join ( chr || " " ) + str ) . substr ( - len ) ;
609
- } ) ;
610
-
611
542
grunt . registerTask ( "default" , "lint csslint qunit build compare_size" ) ;
612
543
grunt . registerTask ( "sizer" , "concat:ui min:dist/jquery-ui.min.js compare_size" ) ;
613
544
grunt . registerTask ( "build" , "concat min cssmin" ) ;
0 commit comments