Created
April 17, 2013 06:00
-
-
Save outsideris/5402097 to your computer and use it in GitHub Desktop.
jslint-report_in_grunt.js
This file contains 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
var jshintCli = require('./node_modules/grunt-contrib-jshint/node_modules/jshint/src/cli/cli'); | |
// ... | |
grunt.initConfig({ | |
"jshint-report": { | |
options: { | |
outDir: 'build-reports' | |
}, | |
all: { | |
files: { | |
src: ['<%= jshint.all.files.src %>'] | |
} | |
} | |
} | |
}); | |
// ... | |
grunt.registerMultiTask('jshint-report', function () { | |
// make output directory | |
var destDir = path.join(__dirname, this.options().outDir); | |
var isExist = fs.existsSync(path.join(__dirname, this.options().outDir)); | |
if (!isExist) { fs.mkdirSync(destDir); } | |
var destFile = path.join(destDir, this.target + '-jshint.xml'); | |
// save stdout.write for later | |
var oldStdoutWrite = process.stdout.write, | |
tempOutput = []; | |
// hook stdout | |
process.stdout.write = function (str, encoding, fg) { | |
fs.writeFileSync(destFile, str); | |
tempOutput.push(str); | |
}; | |
// lint | |
jshintCli.run({ args: this.filesSrc, | |
config: undefined, | |
reporter: require('./node_modules/grunt-contrib-jshint/node_modules/jshint/src/reporters/jslint_xml.js').reporter, | |
ignores: undefined, | |
extensions: '', | |
verbose: null | |
}); | |
// restore stdout | |
process.stdout.write = oldStdoutWrite; | |
console.log(tempOutput.join('')); | |
}); | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment