Skip to content

Commit 9bf90c6

Browse files
rwaldronjzaefferer
authored andcommitted
Remove compare_size; defer to plugin.
Signed-off-by: Rick Waldron waldron.rick@gmail.com <waldron.rick@gmail.com>
1 parent eaacf82 commit 9bf90c6

File tree

2 files changed

+4
-72
lines changed

2 files changed

+4
-72
lines changed

grunt.js

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ cssFiles.forEach(function( file ) {
6767

6868
// csslint and cssmin tasks
6969
grunt.loadNpmTasks( "grunt-css" );
70+
// file size comparison tasks
71+
grunt.loadNpmTasks( "grunt-compare-size" );
7072

7173
grunt.registerHelper( "strip_all_banners", function( filepath ) {
7274
return grunt.file.read( filepath ).replace( /^\s*\/\*[\s\S]*?\*\/\s*/g, "" );
@@ -508,77 +510,6 @@ grunt.registerTask( "clean", function() {
508510
require( "rimraf" ).sync( "dist" );
509511
});
510512

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-
582513
grunt.registerTask( "default", "lint csslint qunit build compare_size" );
583514
grunt.registerTask( "sizer", "concat:ui min:dist/jquery-ui.min.js compare_size" );
584515
grunt.registerTask( "build", "concat min cssmin" );

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
"devDependencies": {
2929
"grunt": "0.3.7",
3030
"grunt-css": "0.1.1",
31+
"grunt-compare-size": "0.1.1",
3132
"request": "2.9.153",
3233
"rimraf": "2.0.1"
3334
},
3435
"keywords": []
35-
}
36+
}

0 commit comments

Comments
 (0)