{"action":"opened","issue":{"url":"https://api.github.com/repos/k-maru/grunt-filesize/issues/4","labels_url":"https://api.github.com/repos/k-maru/grunt-filesize/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/k-maru/grunt-filesize/issues/4/comments","events_url":"https://api.github.com/repos/k-maru/grunt-filesize/issues/4/events","html_url":"https://github.com/k-maru/grunt-filesize/issues/4","id":53773293,"number":4,"title":"Changes to format of results","user":{"login":"justjames","id":1851740,"avatar_url":"https://avatars.githubusercontent.com/u/1851740?v=3","gravatar_id":"","url":"https://api.github.com/users/justjames","html_url":"https://github.com/justjames","followers_url":"https://api.github.com/users/justjames/followers","following_url":"https://api.github.com/users/justjames/following{/other_user}","gists_url":"https://api.github.com/users/justjames/gists{/gist_id}","starred_url":"https://api.github.com/users/justjames/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justjames/subscriptions","organizations_url":"https://api.github.com/users/justjames/orgs","repos_url":"https://api.github.com/users/justjames/repos","events_url":"https://api.github.com/users/justjames/events{/privacy}","received_events_url":"https://api.github.com/users/justjames/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-08T16:56:34Z","updated_at":"2015-01-08T16:56:34Z","closed_at":null,"body":"Hello,\r\n\r\nI needed to have all the filesize results in one CSV file so that Jenkins, the job app we use, could plot the results. I also thought it would be helpful to have a csv for each day when filesize runs, so that we could backtrack if there was a sudden rise in the size of a file. I don't have access to create a branch, so the code of the changes to filesize.js and readme.MD is appended below. \r\n\r\nThanks,\r\n\r\nJames Mittelmark\r\n\r\nfilesize.js\r\n\r\n/*\r\n * grunt-filesize\r\n * https://github.com/k-maru/grunt-filesize\r\n *\r\n * Copyright (c) 2013 kazuhide maruyama\r\n * Licensed under the MIT license.\r\n */\r\n\r\n'use strict';\r\n\r\nmodule.exports = function(grunt) {\r\n\r\n  var fs = require('fs');\r\n\r\n  grunt.registerMultiTask('filesize', 'A Grunt plugin for logging filesize.', function() {\r\n    var options = this.options({\r\n    });\r\n    var results = '\"file\",\"size\"\\n';\r\n    // Iterate over all specified file groups.\r\n    this.files.forEach(function(f) {\r\n      var path = f.src.join('');\r\n\r\n      if (!fs.existsSync(path)){\r\n        grunt.log.writeln(path + \": not found.\");\r\n      } else {\r\n        var stat = fs.statSync(path),\r\n          size = (stat.size / 1024).toFixed(2);\r\n\r\n        grunt.log.writeln(path + \": \" + String(size).green + \" kb (\" + String(stat.size).green + \" bytes)\");\r\n        if (options.reporting) {\r\n          grunt.file.write(options.reporting(f.dest), 'YVALUE=' + size + '\\n');\r\n        }\r\n        \r\n        if (options.gangResults || options.trackResults) {\r\n        \tresults = results + '\"' + f.dest + '\",\"'+ size +'\"\\n';\r\n        }\r\n      }\r\n\r\n    });\r\n    if (options.gangResults) {\r\n    \tgrunt.file.write(options.gangResults, results);\r\n    }\r\n    \r\n    if (options.trackResults) {\r\n    \tvar d= new Date();\r\n    \tvar months = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'];\r\n    \tvar month = months[d.getMonth()];\r\n    \tvar day = d.getDate();\r\n    \tif (day < 10) {day = '0' + day;}\r\n    \tgrunt.file.write(options.gangResults + day + month + d.getFullYear() + '.csv', results);\r\n    }\r\n  });\r\n\r\n};\r\n\r\n\r\nreadme.MD\r\n\r\n# grunt-filesize\r\n\r\n> A Grunt plugin for logging filesize.\r\n\r\n## Documentation\r\nmodify your `grunt.js` file by adding the following line:\r\n\r\ngrunt.loadNpmTasks('grunt-filesize');\r\n\r\nThen add some configuration for the plugin like so:\r\n\r\ngrunt.initConfig({\r\n...\r\nfilesize: {\r\noptions: {\r\nreporting: function (filePath) {\r\nreturn 'target/grunt/filesize/' + filePath + '.txt';\r\n}\r\ngangResults: \"reports/filesize/filesize.csv\",\r\ntrackResults: \"reports/filesize/filesize\"\r\n\r\n},\r\nbase: {\r\nfiles: [\r\n{expand: true, cwd: 'build', src: ['*.css', '*.js']}\r\n]\r\n}\r\n},\r\n...\r\n});\r\n\r\nSetting the 'reporting' option will generate a properties file on the given path for each file measured, you can use those in the Jenkins Plot plugin or other ways.\r\nSetting the 'gangResults' option outputs the sizes of all targeted files into one csv file with file name and size.\r\nSetting the 'trackResults' option creates a new csv file every day with the names and sizes of all files. It appends the date (DDMonYYYY) and '.csv' to the end of the specified path and file name.\r\n "}}