Skip to content

Commit

Permalink
No ticket: Configurable size cache location
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Mar 19, 2013
1 parent 0f9294b commit 0e5adb5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Gruntfile.js
Expand Up @@ -8,7 +8,10 @@ module.exports = function(grunt) {
files: [
"dist/source.js",
"dist/source.min.js"
]
],
options: {
cache: "dist/.sizecache.json"
}
},
nodeunit: {
tests: [ "test/**/*.js" ]
Expand Down
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -26,7 +26,11 @@ Add an entry to your Gruntfile.js's `initConfig` object, which will define the f
files: [
"library.js",
"library.min.js"
]
],
options: {
// Location of stored size data
"cache": ".sizecache.json"
}
}

...
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "grunt-compare-size",
"description": "Compare file sizes on this branch to master",
"version": "0.4.0-alpha.2",
"version": "0.4.0-alpha.3",
"homepage": "https://github.com/rwldrn/grunt-compare-size",
"author": {
"name": "Rick Waldron <waldron.rick@gmail.com>",
Expand Down
13 changes: 9 additions & 4 deletions tasks/compare-size.js
Expand Up @@ -16,13 +16,13 @@ var fs = require("fs"),

module.exports = function(grunt) {
// Grunt utilities & task-wide assignments
var file, utils, log, verbose, sizecache, lastrun, helpers;
var file, utils, log, verbose, defaultCache, lastrun, helpers;

file = grunt.file;
utils = grunt.util;
log = grunt.log;
verbose = grunt.verbose;
sizecache = "dist/.sizecache.json";
defaultCache = ".sizecache.json";
lastrun = " last run";
helpers = {

Expand Down Expand Up @@ -134,6 +134,7 @@ module.exports = function(grunt) {
grunt.registerMultiTask( "compare_size", "Compare working size to saved sizes", function() {
var done = this.async(),
newsizes = helpers.sizes( this ),
sizecache = grunt.config("compare_size.options.cache") || defaultCache,
cache = helpers.get_cache( sizecache ),
tips = cache[""].tips,
labels = helpers.sorted_labels( cache );
Expand Down Expand Up @@ -220,7 +221,8 @@ module.exports = function(grunt) {

// List saved sizes
grunt.registerTask( "compare_size:list", "List saved sizes", function() {
var cache = helpers.get_cache( sizecache ),
var sizecache = grunt.config("compare_size.options.cache") || defaultCache,
cache = helpers.get_cache( sizecache ),
tips = cache[""].tips;

helpers.sorted_labels( cache ).forEach(function( label ) {
Expand All @@ -238,6 +240,7 @@ module.exports = function(grunt) {
// Add custom label
grunt.registerTask( "compare_size:add", "Add to saved sizes", function() {
var label,
sizecache = grunt.config("compare_size.options.cache") || defaultCache,
cache = helpers.get_cache( sizecache );

if ( !cache[ lastrun ] ) {
Expand All @@ -261,6 +264,7 @@ module.exports = function(grunt) {
// Remove custom label
grunt.registerTask( "compare_size:remove", "Remove from saved sizes", function() {
var label,
sizecache = grunt.config("compare_size.options.cache") || defaultCache,
cache = helpers.get_cache( sizecache );

for ( label in this.flags ) {
Expand All @@ -274,7 +278,8 @@ module.exports = function(grunt) {

// Empty size cache
grunt.registerTask( "compare_size:prune", "Clear all saved sizes except those specified", function() {
var cache = helpers.get_cache( sizecache ),
var sizecache = grunt.config("compare_size.options.cache") || defaultCache,
cache = helpers.get_cache( sizecache ),
saved = Object.keys( cache ),
keep = Object.keys( this.flags );

Expand Down

0 comments on commit 0e5adb5

Please sign in to comment.