From 264139b22584eef1de672d0a7f1c52d14318eb56 Mon Sep 17 00:00:00 2001 From: Corey Frang Date: Mon, 17 Oct 2011 14:36:22 -0500 Subject: [PATCH] Build: `ant size` will now give you a report detailing differences in size since the last time you ran the report --- .gitignore | 2 + build/build.xml | 254 ++++++++++++++++++++++++------------------- build/build/sizer.js | 35 ++++++ 3 files changed, 180 insertions(+), 111 deletions(-) create mode 100644 build/build/sizer.js diff --git a/.gitignore b/.gitignore index e5d3578f1..70f7a9c79 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ build/dist +build/size +build/build/.sizecache.json docs .project *~ diff --git a/build/build.xml b/build/build.xml index 154e7f60c..664982565 100644 --- a/build/build.xml +++ b/build/build.xml @@ -9,13 +9,13 @@ --> - + - + @@ -32,6 +32,7 @@ + @@ -41,25 +42,25 @@ - + - + - + - + - + @@ -74,12 +75,12 @@ - + - + @@ -94,14 +95,14 @@ - + - + - + @@ -253,67 +254,67 @@ - + - - - + + + - + - - - - - + + + + + - - - - - - - - - - - + + + + + + + + + + + - + - - - - - - - - - + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + - + + ${relativepath} @@ -394,6 +426,6 @@ - + diff --git a/build/build/sizer.js b/build/build/sizer.js new file mode 100644 index 000000000..3c3e4c428 --- /dev/null +++ b/build/build/sizer.js @@ -0,0 +1,35 @@ +var fs = require( "fs" ), + stdin = process.openStdin(), + rsize = /(\d+).*?(jquery\S+)/g, + oldsizes = {}, + sizes = {}; + +try { + oldsizes = JSON.parse( fs.readFileSync( __dirname + "/.sizecache.json", "utf8" ) ); +} catch(e) { + oldsizes = {}; +}; + +stdin.on( "data" , function( chunk ) { + var match; + + while ( match = rsize.exec( chunk ) ) { + sizes[ match[2] ] = parseInt( match[1], 10 ); + } +}); + +function lpad( str, len, chr ) { + return ( Array(len+1).join( chr || " ") + str ).substr( -len ); +} + +stdin.on( "end", function() { + fs.writeFileSync( __dirname + "/.sizecache.json", JSON.stringify( sizes, true ), "utf8" ); + for ( var key in sizes ) { + var diff = oldsizes[ key ] && ( sizes[ key ] - oldsizes[ key ] ); + if ( diff > 0 ) { + diff = "+" + diff; + } + console.log( "%s %s %s", lpad( sizes[ key ], 8 ), lpad( diff ? "(" + diff + ")" : "(-)", 8 ), key ); + } + process.exit(); +}); \ No newline at end of file