Socket
Socket
Sign inDemoInstall

gulp-amphtml-validator

Package Overview
Dependencies
16
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

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();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc