Skip to content

Instantly share code, notes, and snippets.

@ahomu
Created November 22, 2012 08:13
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ahomu/4129936 to your computer and use it in GitHub Desktop.
Save ahomu/4129936 to your computer and use it in GitHub Desktop.
WIP: HARを取得して、Yslowで評価するぞくん
module.exports = function(grunt) {
'use strict';
var TEMP_HAR_RESOURCE = '.har.tmp';
var exec = require('child_process').exec,
YSLOW = require('yslow').YSLOW,
doc = require('jsdom').jsdom(),
util = grunt.utils || grunt.util,
_ = util._,
async = util.async;
grunt.registerMultiTask('yslow', 'Performance ', function() {
var options = this.options ? this.options() : this.data.options, // for 0.4.0
srcFiles = options.http ? this.data.src : grunt.file.expandFiles(this.data.src),
done = this.async();
async.forEachSeries(srcFiles, function(src, next) {
exec('phantomjs netsniff.js '+src+' > '+TEMP_HAR_RESOURCE, function() {
var res = YSLOW.harImporter.run(doc, JSON.parse(grunt.file.read(TEMP_HAR_RESOURCE)), 'yslow1'),
content = YSLOW.util.getResults(res.context, 'grade');
// 結果のObjectがとれるので、あとはよしなに使いましょう
console.log(content);
next();
});
}, done);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment