Skip to content

Commit d22edc8

Browse files
committed
Remove compare_size; defer to plugin.
Signed-off-by: Rick Waldron waldron.rick@gmail.com <waldron.rick@gmail.com>
1 parent 92c7481 commit d22edc8

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
@@ -70,6 +70,8 @@ cssFiles.forEach(function( file ) {
7070

7171
// csslint and cssmin tasks
7272
grunt.loadNpmTasks( "grunt-css" );
73+
// file size comparison tasks
74+
grunt.loadNpmTasks( "grunt-compare-size" );
7375

7476
grunt.registerHelper( "strip_all_banners", function( filepath ) {
7577
return grunt.file.read( filepath ).replace( /^\s*\/\*[\s\S]*?\*\/\s*/g, "" );
@@ -537,77 +539,6 @@ grunt.registerTask( "clean", function() {
537539
require( "rimraf" ).sync( "dist" );
538540
});
539541

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