Skip to content
Permalink
Browse files

Build: Fixing the sizer script to handle this many files

  • Loading branch information...
gnarf committed Oct 17, 2011
1 parent d2764d8 commit f6c12849f1018f928c933ce63e4aceea6290a191
Showing with 11 additions and 9 deletions.
  1. +11 −9 build/build/sizer.js
@@ -2,34 +2,36 @@ var fs = require( "fs" ),
stdin = process.openStdin(),
rsize = /(\d+).*?(jquery\S+)/g,
oldsizes = {},
sizes = {};
sizes = {},
input = "";

try {
oldsizes = JSON.parse( fs.readFileSync( __dirname + "/.sizecache.json", "utf8" ) );
} catch(e) {
oldsizes = {};
};

function lpad( str, len, chr ) {
return ( Array(len+1).join( chr || " ") + str ).substr( -len );
}

stdin.on( "data" , function( chunk ) {
input += chunk;
});
stdin.on( "end", function() {
var match;

while ( match = rsize.exec( chunk ) ) {
while ( match = rsize.exec( input ) ) {
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 );
console.log( "%s %s %s", lpad( sizes[ key ], 8 ), lpad( oldsizes[key] ? "(" + diff + ")" : "(-)", 8 ), key );
}
process.exit();
});

0 comments on commit f6c1284

Please sign in to comment.
You can’t perform that action at this time.