-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (30 loc) · 948 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"use strict";
var through = require('through2');
var HtmlValidate = require('html-validate').HtmlValidate;
var formatterFactory = require('html-validate').formatterFactory;
var text = formatterFactory("text");
var c = require("ansi-colors");
var log = require("fancy-log");
var PluginError = require("plugin-error");
var PLUGIN_NAME = 'gulp-html-validate';
function validate(file, encoding, callback) {
if (file.isNull()) {
return cb(null, file);
}
try {
var htmlvalidate = new HtmlValidate();
var report = htmlvalidate.validateFile(file.path);
if (!report.valid) {
log(c.red(`File is not valid => ${report.results[0].filePath}`));
log(c.white(`File\n${text(report.results)}`));
}
callback(null, file);
} catch (error) {
var err = new PluginError({
plugin: PLUGIN_NAME,
message: error
});
log.error(err);
}
}
module.exports = function () { return through.obj(validate) };