gulp-nice-package

Opinionated package.json validator

MIT 4 个版本
安装
npm install gulp-nice-package
yarn add gulp-nice-package
pnpm add gulp-nice-package
bun add gulp-nice-package
README

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

版本列表
1.1.0 2015-12-07
1.0.0 2015-03-15
0.0.2 2014-08-07
0.0.1 2014-06-27