forked from maasglobal/maas-schemas
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
57 lines (46 loc) · 1.52 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const AJV = require('ajv');
const eslint = require('gulp-eslint');
const gulp = require('gulp');
const jsonclint = require('gulp-json-lint');
const jsonlint = require('gulp-jsonlint');
const jest = require('gulp-jest').default;
const fg = require('fast-glob');
const jsoncFiles = ['.eslintrc']; // json with comments
const jsonFiles = ['schemas/**/*.json'];
const jsFiles = ['*.js', 'test/**/*.js'];
const ajv = new AJV();
gulp.task('ajv-validate', () => {
const schemas = fg.sync(['schemas/**/*.json'], { absolute: true });
// Add to cache first
schemas.forEach(schema => ajv.addSchema(require(schema)));
// Validate that all schemas work properly with refs
schemas.forEach(schema => ajv.compile(require(schema)));
});
gulp.task('jsonclint', () => {
// Unfortunately does not support failOnError at the moment
// See https://github.com/panuhorsmalahti/gulp-json-lint/issues/2
return gulp
.src(jsoncFiles)
.pipe(jsonclint({ comments: true }))
.pipe(jsonclint.report('verbose'));
});
gulp.task('jsonlint', () => {
return gulp
.src(jsonFiles)
.pipe(jsonlint())
.pipe(jsonlint.reporter())
.pipe(jsonlint.failOnError());
});
gulp.task('eslint', () => {
return gulp
.src(jsFiles)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('validate', ['jsonclint', 'jsonlint', 'eslint', 'ajv-validate']);
gulp.task('test', () => {
return gulp.src('./test').pipe(jest(require('./jest.config')));
});
gulp.task('default', ['validate', 'test']);