From b09eebea7203fc605c073430128f00e9a64e3ada Mon Sep 17 00:00:00 2001 From: Corey Frang Date: Mon, 17 Oct 2011 14:47:20 -0500 Subject: [PATCH] Build: `ant size` will now give you a report detailing differences in size since the last time you ran the report (cherry picked from commit 264139b22584eef1de672d0a7f1c52d14318eb56) Conflicts: build/build.xml --- .gitignore | 2 + build/build.xml | 268 +++++++++++++++++++++++++------------------ build/build/sizer.js | 35 ++++++ 3 files changed, 192 insertions(+), 113 deletions(-) create mode 100644 build/build/sizer.js diff --git a/.gitignore b/.gitignore index e39040f5b4a..43da29d564c 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 568cc9c923f..b663408f0a8 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 @@ - + - + - + @@ -249,61 +254,67 @@ - + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + ${relativepath} @@ -384,6 +426,6 @@ - + diff --git a/build/build/sizer.js b/build/build/sizer.js new file mode 100644 index 00000000000..3c3e4c42806 --- /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