mjmlio / gulp-mjml

Add Gulp to your MJML workflow!
MIT License
161 stars 37 forks source link

Emitting validation warnings #30

Closed tolusonaike closed 5 years ago

tolusonaike commented 6 years ago

How do you emit validation warnings with the gulp-mjml that is similar to what you get when you run

mjml -w file.mjml

nulee commented 6 years ago

Hi @tolusonaike.

If I understand this correctly, it should be easily solvable by introducing an error handler into your gulp pipeline, e. g.:

var gulp = require('gulp')

var mjml = require('gulp-mjml')
var mjmlEngine = require('mjml')

function handleError (err) {
  console.log(err.toString());
  this.emit('end');
}

gulp.task('default', function () {
  return gulp.src('./test.mjml')
    .pipe(mjml(mjmlEngine, {validationLevel: 'strict'}))
    .on('error', handleError)
    .pipe(gulp.dest('./html'))
})

Important: This particular example works only with validationLevel set to strict, as this setting raises a MJMLValidationError exception.