From 30ce0d4360e67890208dcf1db55062aaa5295d5c Mon Sep 17 00:00:00 2001 From: mmiller Date: Mon, 17 Jul 2017 15:45:15 -0600 Subject: [PATCH] Move config schema to separate file for readability --- .editorconfig | 2 +- package.json | 2 +- src/HtmlWebpackExternalsPlugin.js | 52 +------------------- src/configSchema.json | 81 +++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 52 deletions(-) create mode 100644 src/configSchema.json diff --git a/.editorconfig b/.editorconfig index 7b2bf76..28109a1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/package.json b/package.json index 6d65519..4ec1d42 100644 --- a/package.json +++ b/package.json @@ -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" ] }, diff --git a/src/HtmlWebpackExternalsPlugin.js b/src/HtmlWebpackExternalsPlugin.js index 882c749..8c401fa 100644 --- a/src/HtmlWebpackExternalsPlugin.js +++ b/src/HtmlWebpackExternalsPlugin.js @@ -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)) { diff --git a/src/configSchema.json b/src/configSchema.json new file mode 100644 index 0000000..5746ca9 --- /dev/null +++ b/src/configSchema.json @@ -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"] +}