gulp-amphtml-validator
Advanced tools
Comparing version 1.0.2 to 1.0.3
54
index.js
@@ -20,8 +20,9 @@ /** | ||
const amphtmlValidator = require('amphtml-validator'); | ||
const colors = require('ansi-colors'); | ||
const log = require('fancy-log'); | ||
const through = require('through2'); | ||
const gutil = require('gulp-util'); | ||
const amphtmlValidator = require('amphtml-validator'); | ||
const PLUGIN_NAME = 'gulp-amphtml-validator'; | ||
const PluginError = gutil.PluginError; | ||
const PluginError = require('plugin-error'); | ||
@@ -50,12 +51,13 @@ const STATUS_FAIL = 'FAIL'; | ||
this.emit('error', new PluginError(PLUGIN_NAME, | ||
'Streams not supported!')); | ||
'Streams not supported!')); | ||
} | ||
if (file.isBuffer()) { | ||
validator.getInstance() | ||
.then(function(validatorInstance) { | ||
const inputString = file.contents.toString(); | ||
file.ampValidationResult = validatorInstance.validateString(inputString); | ||
return callback(null, file); | ||
}) | ||
.catch(function(err) { | ||
.then(function(validatorInstance) { | ||
const inputString = file.contents.toString(); | ||
file.ampValidationResult = | ||
validatorInstance.validateString(inputString); | ||
return callback(null, file); | ||
}) | ||
.catch(function(err) { | ||
// This happens if the validator download failed. We don't fail the | ||
@@ -65,8 +67,8 @@ // build, but map the exception to an validation error instead. This | ||
// should fail the build or not. | ||
gutil.log(gutil.colors.red(err.message)); | ||
file.ampValidationResult = { | ||
status: STATUS_UNKNOWN, | ||
}; | ||
return callback(null, file); | ||
}); | ||
log(colors.red(err.message)); | ||
file.ampValidationResult = { | ||
status: STATUS_UNKNOWN, | ||
}; | ||
return callback(null, file); | ||
}); | ||
} | ||
@@ -87,3 +89,3 @@ } | ||
if (!logger) { | ||
logger = gutil; | ||
logger = log; | ||
} | ||
@@ -99,3 +101,4 @@ | ||
function formatResults(callback) { | ||
logger.log('AMP Validation results:\n\n' + results.map(printResult).join('\n')); | ||
logger.log('AMP Validation results:\n\n' + | ||
results.map(printResult).join('\n')); | ||
return callback(); | ||
@@ -108,11 +111,14 @@ } | ||
if (validationResult.status === STATUS_PASS) { | ||
report += gutil.colors.green(validationResult.status); | ||
report += colors.green(validationResult.status); | ||
report += '\nReview our \'publishing checklist\' to ensure ' | ||
+ 'successful AMP document distribution. ' | ||
+ 'See https://go.amp.dev/publishing-checklist'; | ||
} else if (validationResult.status === STATUS_UNKNOWN) { | ||
report += gutil.colors.red(validationResult.status); | ||
report += colors.red(validationResult.status); | ||
} else { | ||
report += gutil.colors.red(validationResult.status); | ||
report += colors.red(validationResult.status); | ||
for (let ii = 0; ii < validationResult.errors.length; ii++) { | ||
const error = validationResult.errors[ii]; | ||
let msg = file.relative + ':' + error.line + ':' + error.col + ' ' + | ||
gutil.colors.red(error.message); | ||
colors.red(error.message); | ||
if (error.specUrl) { | ||
@@ -134,3 +140,3 @@ msg += ' (see ' + error.specUrl + ')'; | ||
* | ||
* @param {!function(amphtmlValidator.ValidationResult): boolean} isFailure | ||
* @param {function(amphtmlValidator.ValidationResult): boolean} isFailure | ||
* @return {!stream} gulp file stream | ||
@@ -154,3 +160,3 @@ */ | ||
this.emit('error', new PluginError(PLUGIN_NAME, | ||
'\nAMPHTML Validation failed for ' + failedFiles + ' files.')); | ||
'\nAMPHTML Validation failed for ' + failedFiles + ' files.')); | ||
} | ||
@@ -157,0 +163,0 @@ callback(); |
{ | ||
"name": "gulp-amphtml-validator", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Gulp plugin for the official AMP HTML validator (www.ampproject.org)", | ||
@@ -13,5 +13,2 @@ "keywords": [ | ||
], | ||
"engines": { | ||
"node": ">=0.10.25" | ||
}, | ||
"author": "The AMP HTML Authors", | ||
@@ -24,4 +21,3 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"amphtml-validator": "1.0.21", | ||
"gulp-util": "^3.0.7", | ||
"amphtml-validator": "1.0.23", | ||
"through2": "^2.0.1" | ||
@@ -28,0 +24,0 @@ }, |
@@ -9,3 +9,3 @@ # Gulp AMPHTML Validator | ||
``` | ||
```sh | ||
npm install --save-dev gulp-amphtml-validator | ||
@@ -20,11 +20,14 @@ ``` | ||
gulp.task('amphtml:validate', () => { | ||
return gulp.src('*.html') | ||
// Validate the input and attach the validation result to the "amp" property | ||
// of the file object. | ||
.pipe(gulpAmpValidator.validate()) | ||
// Print the validation results to the console. | ||
.pipe(gulpAmpValidator.format()) | ||
// Exit the process with error code (1) if an AMP validation error | ||
// occurred. | ||
.pipe(gulpAmpValidator.failAfterError()); | ||
return ( | ||
gulp | ||
.src('*.html') | ||
// Validate the input and attach the validation result to the "amp" property | ||
// of the file object. | ||
.pipe(gulpAmpValidator.validate()) | ||
// Print the validation results to the console. | ||
.pipe(gulpAmpValidator.format()) | ||
// Exit the process with error code (1) if an AMP validation error | ||
// occurred. | ||
.pipe(gulpAmpValidator.failAfterError()) | ||
); | ||
}); | ||
@@ -39,3 +42,2 @@ ``` | ||
.pipe(gulpAmpValidator.failAfterWarningOrError()); | ||
``` | ||
@@ -45,13 +47,17 @@ | ||
### 1.0.3 | ||
- Remove engine section from pacakge.json to allow any version of gulpjs. | ||
### 1.0.2 | ||
* Add failAfterWarningOrError option | ||
* Upgrade amphtml-validator version to 1.0.21 | ||
- Add failAfterWarningOrError option | ||
- Upgrade amphtml-validator version to 1.0.21 | ||
### 1.0.1 | ||
* Upgrade amphtml-validator version to 1.0.18 | ||
- Upgrade amphtml-validator version to 1.0.18 | ||
### 1.0.0 | ||
* initial release | ||
- initial release |
@@ -23,14 +23,14 @@ /** | ||
return gulp.src('../../testdata/feature_tests/*.html') | ||
// Valide the input and attach the validation result to the "amp" property | ||
// of the file object. | ||
.pipe(gulpAmpHtmlValidator.validate()) | ||
// Print the validation results to the console. | ||
.pipe(gulpAmpHtmlValidator.format()) | ||
// Exit the process with error code (1) if an AMP validation error | ||
// occurred. | ||
.pipe(gulpAmpHtmlValidator.failAfterError()); | ||
// Valide the input and attach the validation result to the "amp" property | ||
// of the file object. | ||
.pipe(gulpAmpHtmlValidator.validate()) | ||
// Print the validation results to the console. | ||
.pipe(gulpAmpHtmlValidator.format()) | ||
// Exit the process with error code (1) if an AMP validation error | ||
// occurred. | ||
.pipe(gulpAmpHtmlValidator.failAfterError()); | ||
}); | ||
gulp.task('default', ['amphtml:validate'], function () { | ||
gulp.task('default', ['amphtml:validate'], function() { | ||
// This will only run if the validation task is successful... | ||
}); |
@@ -22,3 +22,2 @@ /** | ||
const es = require('event-stream'); | ||
const gutil = require('gulp-util'); | ||
const File = require('vinyl'); | ||
@@ -124,3 +123,3 @@ const fs = require('fs'); | ||
assert.equal(logger.logged, 'AMP Validation results:\n\n' + | ||
INVALID_FILE + ': \u001b[31mFAIL\u001b[39m\n' + INVALID_FILE + | ||
INVALID_FILE + ': \u001b[31mFAIL\u001b[39m\n' + INVALID_FILE + | ||
':24:4 ' + '\u001b[31merrorMessage\u001b[39m (see specUrl)'); | ||
@@ -127,0 +126,0 @@ done(); |
14760
2
381
60
6
+ Addedamphtml-validator@1.0.23(transitive)
- Removedgulp-util@^3.0.7
- Removedamphtml-validator@1.0.21(transitive)
- Removedansi-gray@0.1.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedansi-wrap@0.1.0(transitive)
- Removedarray-differ@1.0.0(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedbeeper@1.1.1(transitive)
- Removedchalk@1.1.3(transitive)
- Removedclone@1.0.4(transitive)
- Removedclone-stats@0.0.1(transitive)
- Removedcolor-support@1.1.3(transitive)
- Removeddateformat@2.2.0(transitive)
- Removedduplexer2@0.0.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfancy-log@1.3.3(transitive)
- Removedglogg@1.0.2(transitive)
- Removedgulp-util@3.0.8(transitive)
- Removedgulplog@1.0.0(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-gulplog@0.1.0(transitive)
- Removedisarray@0.0.1(transitive)
- Removedlodash._basecopy@3.0.1(transitive)
- Removedlodash._basetostring@3.0.1(transitive)
- Removedlodash._basevalues@3.0.0(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash._isiterateecall@3.0.9(transitive)
- Removedlodash._reescape@3.0.0(transitive)
- Removedlodash._reevaluate@3.0.0(transitive)
- Removedlodash._reinterpolate@3.0.0(transitive)
- Removedlodash._root@3.0.1(transitive)
- Removedlodash.escape@3.2.0(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedlodash.restparam@3.6.1(transitive)
- Removedlodash.template@3.6.2(transitive)
- Removedlodash.templatesettings@3.1.1(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmultipipe@0.1.2(transitive)
- Removedobject-assign@3.0.0(transitive)
- Removedparse-node-version@1.0.1(transitive)
- Removedreadable-stream@1.1.14(transitive)
- Removedreplace-ext@0.0.1(transitive)
- Removedsparkles@1.0.1(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedtime-stamp@1.1.0(transitive)
- Removedvinyl@0.5.3(transitive)
Updatedamphtml-validator@1.0.23