gulp-nice-package

1.1.0 • Public • Published

gulp-nice-package NPM version Build Status

Opinionated package.json validator. Uses package.json-validator under the covers

Install

npm install gulp-nice-package --save-dev

Usage

// gulpfile.js
var gulp = require('gulp');
var validate = require('gulp-nice-package');
 
gulp.task('validate-json', function () {
  return gulp.src('package.json')
    .pipe(validate());
});

Options

Any options defined are simply passed along to package.json-validator

// gulpfile.js
var gulp = require('gulp');
var validate = require('gulp-nice-package');
 
gulp.task('validate-json', function () {
  return gulp.src('package.json')
    .pipe(validate('npm', {
      warnings: false,
      recommendations: false
    }));
});

Failing your build

The below will both print errors to the console and exit the gulp process with an appropriate error code for properly failing builds.

var gulp = require('gulp'),
  validate = require('gulp-nice-package'),
  mapstream = require('map-stream');
 
process.on('exit', function () {
  process.nextTick(function () {
    process.exit(1);
  });
});
 
gulp.task('validate-json', function () {
  var isValid = true;
  return gulp.src('package.json')
    .pipe(validate())
    .pipe(mapstream(function (file, cb) {
      isValid = file.nicePackage.valid;
      cb(null, file);
    }))
    .on('end', function() {
      if (!isValid) {
        process.emit('exit');
      }
    });
});

I know, it seems a bit terse. The reasoning is, you may want to pipe other transforms onto the stream and, if an error is thrown, the pipe will cease and you have no way to continue. A valid use case may be to actually fix the the package.json file programmatically if it's invalid, e.g. with gulp-shrinkwrap.

License

MIT © Chris Montgomery

Package Sidebar

Install

npm i gulp-nice-package

Weekly Downloads

10

Version

1.1.0

License

MIT

Last publish

Collaborators

  • chmontgomery