Created
November 22, 2012 08:13
-
-
Save ahomu/4129936 to your computer and use it in GitHub Desktop.
WIP: HARを取得して、Yslowで評価するぞくん
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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