Skip to content

Commit 2014a9a

Browse files
authored
Merge pull request faceyspacey#1 from scottdj92/json-schema
Json schema
2 parents c8494f3 + 6ae4a5d commit 2014a9a

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var ExtractedModule = require("./ExtractedModule");
99
var Chunk = require("webpack/lib/Chunk");
1010
var OrderUndefinedError = require("./OrderUndefinedError");
1111
var loaderUtils = require("loader-utils");
12+
var schemaTester = require('./schema/valid');
1213

1314
var NS = fs.realpathSync(__dirname);
1415

@@ -104,6 +105,7 @@ function getOrder(a, b) {
104105
}
105106

106107
function ExtractTextPlugin(options) {
108+
schemaTester(options);
107109
if(arguments.length > 1) {
108110
throw new Error("Breaking change: ExtractTextPlugin now only takes a single argument. Either an options " +
109111
"object *or* the name of the result file.\n" +

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"webpack-sources": "^0.1.0"
1313
},
1414
"devDependencies": {
15+
"ajv": "^4.11.2",
1516
"codecov.io": "^0.1.2",
1617
"coveralls": "^2.11.2",
1718
"css-loader": "^0.21.0",

schema/schema.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"type": "object",
4+
"properties": {
5+
"allChunks": {
6+
"description": "",
7+
"type": "boolean"
8+
},
9+
"disable": {
10+
"description": "",
11+
"type": "boolean"
12+
},
13+
"fallbackLoader": {
14+
"description": "A loader that webpack can fall back to if the original one fails.",
15+
"type": "string"
16+
},
17+
"filename": {
18+
"description": "The filename and path that ExtractTextPlugin will extract to.",
19+
"type": "string"
20+
},
21+
"loader": {
22+
"description": "The loader that ExtractTextPlugin will attempt to load through.",
23+
"type": "string"
24+
},
25+
"publicPath": {
26+
"description": "",
27+
"type": "string"
28+
}
29+
},
30+
"required": ["loader"]
31+
}

schema/valid.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var Ajv = require('ajv');
2+
var ajv = new Ajv({allErrors: true});
3+
var json = require('./schema.json');
4+
5+
module.exports = function validate(data) {
6+
var validSchema = ajv.compile(json);
7+
var valid = validSchema(data);
8+
9+
if(!valid) {
10+
throw new Error("Your ExtractTextPlugin config is not correct. Please double check.");
11+
} else {
12+
console.log('your stuff works');
13+
}
14+
}

schema/valid.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"allChunks": { "type": "boolean"},
3+
"disable": { "type": "boolean" },
4+
"fallbackLoader": { "type": "string" },
5+
"filename": { "type": "string" },
6+
"loader": { "type": "string" },
7+
"publicPath": { "type": "string" }
8+
}

0 commit comments

Comments
 (0)