From: Rick Waldron waldron.rick@gmail.com Date: Thu, 12 Apr 2012 17:32:11 +0000 (-0400) Subject: Remove compare_size; defer to plugin. X-Git-Tag: 1.9.0m8~146 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F633%2Fhead;p=jquery-ui.git Remove compare_size; defer to plugin. Signed-off-by: Rick Waldron waldron.rick@gmail.com --- diff --git a/grunt.js b/grunt.js index 0887cad4c..83657849e 100644 --- a/grunt.js +++ b/grunt.js @@ -70,6 +70,8 @@ cssFiles.forEach(function( file ) { // csslint and cssmin tasks grunt.loadNpmTasks( "grunt-css" ); +// file size comparison tasks +grunt.loadNpmTasks( "grunt-compare-size" ); grunt.registerHelper( "strip_all_banners", function( filepath ) { return grunt.file.read( filepath ).replace( /^\s*\/\*[\s\S]*?\*\/\s*/g, "" ); @@ -537,77 +539,6 @@ grunt.registerTask( "clean", function() { require( "rimraf" ).sync( "dist" ); }); -// TODO merge with code in jQuery Core, share as grunt plugin/npm -// this here actually uses the provided filenames in the output -// the helpers should just be regular functions, no need to share those with the world -grunt.registerMultiTask( "compare_size", "Compare size of this branch to master", function() { - var files = grunt.file.expandFiles( this.file.src ), - done = this.async(), - sizecache = __dirname + "/dist/.sizecache.json", - sources = { - min: grunt.file.read( files[1] ), - max: grunt.file.read( files[0] ) - }, - oldsizes = {}, - sizes = {}; - - try { - oldsizes = JSON.parse( grunt.file.read( sizecache ) ); - } catch( e ) { - oldsizes = {}; - } - - // Obtain the current branch and continue... - grunt.helper( "git_current_branch", function( err, branch ) { - var key, diff; - - // Derived and adapted from Corey Frang's original `sizer` - grunt.log.writeln( "sizes - compared to master" ); - - sizes[ files[0] ] = sources.max.length; - sizes[ files[1] ] = sources.min.length; - sizes[ files[1] + ".gz" ] = grunt.helper( "gzip", sources.min ).length; - - for ( key in sizes ) { - diff = oldsizes[ key ] && ( sizes[ key ] - oldsizes[ key ] ); - if ( diff > 0 ) { - diff = "+" + diff; - } - console.log( "%s %s %s", - grunt.helper("lpad", sizes[ key ], 8 ), - grunt.helper("lpad", diff ? "(" + diff + ")" : "(-)", 8 ), - key - ); - } - - if ( branch === "master" ) { - // If master, write to file - this makes it easier to compare - // the size of your current code state to the master branch, - // without returning to the master to reset the cache - grunt.file.write( sizecache, JSON.stringify(sizes) ); - } - done(); - }); -}); -grunt.registerHelper( "git_current_branch", function( done ) { - grunt.utils.spawn({ - cmd: "git", - args: [ "branch", "--no-color" ] - }, function( err, result ) { - var branch; - - result.split( "\n" ).forEach(function( branch ) { - var matches = /^\* (.*)/.exec( branch ); - if ( matches !== null && matches.length && matches[ 1 ] ) { - done( null, matches[ 1 ] ); - } - }); - }); -}); -grunt.registerHelper( "lpad", function( str, len, chr ) { - return ( Array( len + 1 ).join( chr || " " ) + str ).substr( -len ); -}); - grunt.registerTask( "default", "lint csslint qunit build compare_size" ); grunt.registerTask( "sizer", "concat:ui min:dist/jquery-ui.min.js compare_size" ); grunt.registerTask( "build", "concat min cssmin" ); diff --git a/package.json b/package.json index 30e2b4898..1d24c8ab8 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,9 @@ "devDependencies": { "grunt": "0.3.7", "grunt-css": "0.1.1", + "grunt-compare-size": "0.1.1", "request": "2.9.153", "rimraf": "2.0.1" }, "keywords": [] -} \ No newline at end of file +}