1
1
/*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Gajus Kuizinas @gajus
4
- */
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Gajus Kuizinas @gajus
4
+ */
5
5
import Ajv = require( 'ajv' ) ;
6
- const webpackOptionsSchema = require ( '../schemas/webpackOptionsSchema.json' ) ;
6
+ import defineKeywords = require( 'ajv-keywords' )
7
7
8
8
const ajv = new Ajv ( {
9
9
errorDataPath : 'configuration' ,
10
10
allErrors : true ,
11
11
verbose : true
12
12
} ) ;
13
13
14
- const validate = ajv . compile ( webpackOptionsSchema ) ;
14
+ defineKeywords ( ajv ) ;
15
15
16
- function validateWebpackOptions ( options ) {
16
+ function validateSchema ( schema , options ) {
17
+ const validate = ajv . compile ( schema ) ;
17
18
if ( Array . isArray ( options ) ) {
18
19
const errors = options . map ( validateObject ) ;
19
- errors . forEach ( ( list , idx ) => {
20
+
21
+ errors . forEach ( function ( list , idx ) {
20
22
list . forEach ( function applyPrefix ( err ) {
21
- err . dataPath = `[ ${ idx } ] ${ err . dataPath } ` ;
23
+ err . dataPath = "[" + idx + "]" + err . dataPath ;
22
24
if ( err . children ) {
23
25
err . children . forEach ( applyPrefix ) ;
24
26
}
@@ -29,11 +31,11 @@ function validateWebpackOptions(options) {
29
31
else {
30
32
return validateObject ( options ) ;
31
33
}
32
- }
33
34
34
- function validateObject ( options ) {
35
- const valid = validate ( options ) ;
36
- return valid ? [ ] : filterErrors ( validate . errors ) ;
35
+ function validateObject ( options ) {
36
+ const valid = validate ( options ) ;
37
+ return valid ? [ ] : filterErrors ( validate . errors ) ;
38
+ }
37
39
}
38
40
39
41
function filterErrors ( errors ) {
@@ -62,4 +64,4 @@ function filterErrors(errors) {
62
64
return newErrors ;
63
65
}
64
66
65
- export = validateWebpackOptions ;
67
+ export = validateSchema ;
0 commit comments