grunt-filesize-report
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "grunt-filesize-report", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "(Very) simple filesize reporter for grunt. Primary use was to generate a very simple xml format for use by Jenkins plot plugin.", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -20,3 +20,6 @@ # grunt-filesize-report | ||
json: false, //default is false | ||
filename: 'myoutput' // defaults to 'filesize-[target].[ext]' | ||
filename: 'myoutput' // defaults to 'filesize-[target].[ext]', | ||
thresholds: [102400,204800] // [warning, error] thresholds for individual files | ||
totalThresholds: [524288,1048576] // [warning, error] for totals of all files | ||
failOnerror: false // fail task when error threshold crossed | ||
} | ||
@@ -23,0 +26,0 @@ }, |
@@ -6,2 +6,8 @@ var fs = require('fs'); | ||
var defaults = { | ||
failOnError: false, | ||
thresholds: [102400,204800], | ||
totalThresholds: [524288,1048576] | ||
}; | ||
function formatSize(num) { | ||
@@ -13,2 +19,6 @@ return num.toFixed(2).toString(); | ||
var options = this.options(defaults); | ||
var errors = 0; | ||
var total = 0; | ||
var files = this.filesSrc.filter(function (file) { | ||
@@ -18,2 +28,6 @@ return grunt.file.exists(file); | ||
var stat = fs.statSync(file); | ||
if(stat.size > options.thresholds[1]) { | ||
errors += 1; | ||
} | ||
total += stat.size; | ||
return { | ||
@@ -29,13 +43,20 @@ fullpath: path.resolve(file), | ||
var options = this.options(); | ||
console.log(options) | ||
if(total > options.totalThresholds[1]) { | ||
errors += 1; | ||
} | ||
function getColor(size, thresholds) { | ||
thresholds = thresholds || options.thresholds; | ||
if(size > thresholds[1]) { | ||
return 'red'; | ||
} else if(size > thresholds[0]) { | ||
return 'yellow'; | ||
} | ||
return 'green'; | ||
} | ||
if (options.console !== false) { | ||
var widths = [75,10,10,10]; | ||
var sep = ' '; | ||
var total = files.map(function(file) { | ||
return file.size; | ||
}).reduce(function(a,b) { | ||
return a + b; | ||
}); | ||
grunt.log.writeln('=========================='); | ||
@@ -49,3 +70,3 @@ grunt.log.writeln('Filesize analysis: '+this.target); | ||
files.forEach(function (file) { | ||
grunt.log.writeln(grunt.log.table(widths, [file.filename, sep + file.size.toString(), sep + formatSize(file.kb), sep + formatSize(file.mb)])); | ||
grunt.log.writeln(grunt.log.table(widths, [file.filename, sep + file.size.toString(), sep + formatSize(file.kb), sep + formatSize(file.mb)]) [getColor(file.size)]); | ||
}); | ||
@@ -55,3 +76,3 @@ grunt.log.writeln(); | ||
grunt.log.writeln(grunt.log.table(widths,['Total',sep+total.toString(),sep+formatSize(total / 1024),sep+formatSize(total / 1024 / 1024)])); | ||
grunt.log.writeln(grunt.log.table(widths,['Total',sep+total.toString(),sep+formatSize(total / 1024),sep+formatSize(total / 1024 / 1024)]) [getColor(total,options.totalThresholds)]); | ||
} | ||
@@ -80,4 +101,8 @@ | ||
if(options.failOnError) { | ||
grunt.fail.warn('Error threshold broken'); | ||
} | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33041
79
52