https://github.com/unic/gulp-data-validate
Validate data files against their respective JSON schemas
https://github.com/unic/gulp-data-validate
Last synced: over 1 year ago
JSON representation
Validate data files against their respective JSON schemas
- Host: GitHub
- URL: https://github.com/unic/gulp-data-validate
- Owner: unic
- License: mit
- Created: 2020-02-28T08:03:28.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2023-01-07T21:30:02.000Z (over 3 years ago)
- Last Synced: 2025-02-25T17:11:25.560Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://npmjs.com/gulp-data-validate
- Size: 346 KB
- Stars: 0
- Watchers: 7
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# gulp-data-validate
[](https://www.npmjs.com/package/gulp-data-validate)
[](https://www.npmjs.com/package/gulp-data-validate)
[](https://github.com/nodejs/Release)
[](license)
> Validate data files against their respective JSON schemas
Uses [`ajv`](https://github.com/epoberezkin/ajv), [`json-schema-ref-parser`](https://github.com/APIDevTools/json-schema-ref-parser) and [`import-fresh`](https://github.com/sindresorhus/import-fresh) under the hood.
## How
Have a `*.data.js` and a `*.schema.json` file for your module on the same level. Pass in the data file to the plugin, and, boom: See whether it's valid. If it's not, it'll log what's to be done.
```bash
yarn add gulp-data-validate --dev
```
```
v modules
v my-module
> my-module.hbs
> my-module.scss
> my-module.js
> my-module.data.js
> my-module.schema.json
> my-other-module
> another-one
> best-module
```
```js
const { src } = require('gulp');
const validate = require('gulp-data-validate');
module.exports.schema = src('modules/**/*.data.js').pipe(validate());
```
## Options
You can pass in an object containing three keys: `schemaSuffix`, `failOnError` and `ignorePrefix`. With those three, you can adapt to your naming scheme and control whether the build should fail when the data files aren't valid.
```js
const defaultOptions = {
schemaSuffix: '.schema.json',
failOnError: false,
ignorePrefix: '_'
};
```
If your schemas are just named `*.json`, you want to skip schema validation for files beginning with `_` and you want the build to fail on error (nice for CI-purposes), your folder structure and config would look like this:
```
v modules
v my-module
> my-module.hbs
> my-module.scss
> my-module.js
> my-module.data.js
> my-module.json
v partials
_my-partial.hbs
_my-partial.scss
_my-partial.data.js
> my-other-module
> another-one
> best-module
```
```js
const { src } = require('gulp');
const validate = require('gulp-data-validate');
module.exports.schema = src('modules/**/*.data.js').pipe(validate({
schemaSuffix: '.json',
failOnError: true,
ignorePrefix: '_'
}));
```
## License
MIT