Skip to content
This repository has been archived by the owner on Apr 5, 2021. It is now read-only.

Commit

Permalink
Move config schema to separate file for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
mmiller42 committed Jul 17, 2017
1 parent ba54b60 commit 30ce0d4
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
root = true

[{src/**.js,*.{js,json},.babelrc,*.md}]
[{src/**.{js,json},*.json,.babelrc,*.md}]
indent_style = space
indent_size = 2
end_of_line = lf
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"lint-staged": {
"*.js": [
"prettier --write --no-semi --single-quote --trailing-comma es5 '{src/**/*.js,*.json}'",
"prettier --write --no-semi --single-quote --trailing-comma es5 '{src/**/*.{js,json},*.json}'",
"git add"
]
},
Expand Down
52 changes: 2 additions & 50 deletions src/HtmlWebpackExternalsPlugin.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,12 @@
import CopyWebpackPlugin from 'copy-webpack-plugin'
import HtmlWebpackIncludeAssetsPlugin from 'html-webpack-include-assets-plugin'
import Ajv from 'ajv'
import configSchema from './configSchema.json'

export default class HtmlWebpackExternalsPlugin {
static validateArguments = (() => {
const ajv = new Ajv({ useDefaults: true })
const validateConfig = ajv.compile({
type: 'object',
properties: {
externals: {
type: 'array',
items: {
type: 'object',
properties: {
module: { type: 'string' },
entry: {
type: ['string', 'array', 'object'],
items: {
type: ['string', 'object'],
properties: {
path: { type: 'string' },
type: { type: 'string', enum: ['js', 'css'] },
},
required: ['path', 'type'],
},
minItems: 1,
properties: {
path: { type: 'string' },
type: { type: 'string', enum: ['js', 'css'] },
},
required: ['path', 'type'],
},
global: { type: ['string', 'null'], default: null },
supplements: {
type: 'array',
items: { type: 'string' },
default: [],
},
append: { type: 'boolean', default: false },
},
required: ['module', 'entry'],
},
minItems: 1,
},
hash: { type: 'boolean', default: false },
outputPath: { type: 'string', default: 'vendor' },
publicPath: { type: ['string', 'null'], default: null },
files: {
type: ['string', 'array', 'null'],
items: { type: 'string' },
minItems: 1,
default: null,
},
},
required: ['externals'],
})
const validateConfig = ajv.compile(configSchema)

return config => {
if (!validateConfig(config)) {
Expand Down
81 changes: 81 additions & 0 deletions src/configSchema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"type": "object",
"properties": {
"externals": {
"type": "array",
"items": {
"type": "object",
"properties": {
"module": {
"type": "string"
},
"entry": {
"type": ["string", "array", "object"],
"items": {
"type": ["string", "object"],
"properties": {
"path": {
"type": "string"
},
"type": {
"type": "string",
"enum": ["js", "css"]
}
},
"required": ["path", "type"]
},
"minItems": 1,
"properties": {
"path": {
"type": "string"
},
"type": {
"type": "string",
"enum": ["js", "css"]
}
},
"required": ["path", "type"]
},
"global": {
"type": ["string", "null"],
"default": null
},
"supplements": {
"type": "array",
"items": {
"type": "string"
},
"default": []
},
"append": {
"type": "boolean",
"default": false
}
},
"required": ["module", "entry"]
},
"minItems": 1
},
"hash": {
"type": "boolean",
"default": false
},
"outputPath": {
"type": "string",
"default": "vendor"
},
"publicPath": {
"type": ["string", "null"],
"default": null
},
"files": {
"type": ["string", "array", "null"],
"items": {
"type": "string"
},
"minItems": 1,
"default": null
}
},
"required": ["externals"]
}

0 comments on commit 30ce0d4

Please sign in to comment.