This module provides a grunt multi-task for converts the JSON report generated by the grunt-html task to the HTML format. It uses grunt-html-html-reporter to format the validation results.
You need node >= 4, and grunt >= 0.4.5 installed and your project build managed by a Gruntfile with the necessary modules listed in package.json; including grunt-html. If you haven't used Grunt before, be sure to check out the [Getting Started] guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with you favourite package manager:
npm i -D grunt-html-html-report-converter
pnpm i -D grunt-html-html-report-converter
yarn add -D grunt-html-html-report-converterAdd the htmllint-html-report-converter entry with the task configuration to the options of the grunt.initConfig method:
grunt.initConfig({
'htmllint-html-report-converter': {
all: {
src: 'results/report.json',
dest: 'results/report.html'
}
}
});Default options support the most usual usage scenario:
'html-html-report-converter': {
options: {
targetExtension: '.html',
ignoreMissing: false,
showFileNameOnly: false,
showCommonPathOnly: true,
force: false
},
all: {
src: 'results/report.json',
dest: 'results/report.html'
}
}Type: Boolean
Default value: false
If set to true, it suppresses failures, which happened during the report conversion. Instead of making the Grunt fail, the errors will be written only to the console.
Type: Boolean
Default: false
If the src property does not point to any files, or if it is missing,
the task will make the Grunt run fail. If you set the ignoreMissing
option to true, Grunt will continue executing other tasks.
Type: Boolean
Default: false
If the src property does not point to any files, or if it is missing,
the task will assume, that no messages existed for the input files, which
which were above the configured severity. It will create the report
nevertheless and include all input files there.
Type: String
Default: ".html:
If the dest property specified only the target directory, the converted report file will be stored there with the file extension replaced to ".html" or to the extesion specified by this property.
Type: Boolean
Default value: false
Cuts the directory from tested HTML files, when creating page titles from in the report. If you use unique names for files alone, you will not get too long page titles, if you flip this flag tp true.
The configuration consists of src and dest property pairs. The src
property has to point to an existing source path. The dest property has
to point to the path, where the converted report should be written.
If you do not end the dest path by the path separator (slash, for example), the dest path will be considered as if it includes the converted report file name too.
If you end the dest path by a path separator (slash, for example), the
converted report will be created using the source report name with the HTML expension.
If you specify more source files or directories, or use wildcards, the target path should be a directory - ended by the path separator (slash, for example).
If you set includeUnreported to true and you expect all input files reported with zero messages, include the input property. Set it to the files, which were input of the htmllint task. For example:
'html-html-report-converter': {
options: {
includeUnreported: true
},
all: {
input: 'snapshots/*.html',
src: 'results/report.json',
dest: 'results/report.html'
}
}Type: String or Array
Path to the file with the JSON report generated by the htmllint task, or a path pattern identifying these file, or an array of these.
Type: String
Path to the file, which will be the HTML report written to. Or only the path to the directory, where it should be written, if the source report name with the HTML expension shoudl be used.
Type: String|Array|Object
Files, which were input of the htmllint task. The format is the same as for the src parameter - the Grunt source file specification.
Load the plugin in Gruntfile.js:
grunt.loadNpmTasks('grunt-html-html-report-converter');Call the htmllint-html-report-converter task:
$ grunt htmllint-html-report-converteror integrate it to your build sequence in Gruntfile.js:
grunt.registerTask('default', ['htmllint-html-report-converter', ...]);This task will be usually executed right after the htmllint task. For example:
grunt.initConfig({
htmllint: {
options: {
errorlevels: ['error', 'warning', 'info'],
reporter: 'json',
reporterOutput: 'output/report.json',
},
all: {
src: ['input/*.html']
}
},
'htmllint-html-report-converter': {
all: {
src: 'output/report.json',
dest: 'output/'
}
}
});
grunt.loadNpmTasks('grunt-html');
grunt.loadNpmTasks('grunt-html-html-report-converter');
grunt.registerTask('default', [
'htmllint', 'html-html-report-converter']);The installation of the necessary Grunt tasks, again, one of the package managers:
npm i -D grunt-html grunt-html-html-report-converter
pnpm i -D grunt-html grunt-html-html-report-converter
yarn add -D grunt-html grunt-html-html-report-converterIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Copyright (c) 2017-2022 Ferdinand Prantl
Licensed under the MIT license.