Skip to content

Commit

Permalink
feat: validate global options too
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Mar 10, 2020
1 parent 034fd3f commit 97738d5
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 86 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -296,6 +296,8 @@ Default: `[]`

Globs to ignore files.

May also contain Minimatch setting objects (e.g. `{dot: true, matchBase: true}`).

**webpack.config.js**

```js
Expand Down Expand Up @@ -534,6 +536,8 @@ module.exports = {

Array of globs to ignore (applied to `from`).

Like per-pattern ignores, may also contain Minimatch setting objects.

**webpack.config.js**

```js
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Expand Up @@ -3,14 +3,16 @@ import path from 'path';
import validateOptions from 'schema-utils';
import log from 'webpack-log';

import schema from './options.json';
import patternsSchema from './patterns.json';
import optionsSchema from './options.json';
import preProcessPattern from './preProcessPattern';
import processPattern from './processPattern';
import postProcessPattern from './postProcessPattern';

class CopyPlugin {
constructor(patterns = [], options = {}) {
validateOptions(schema, patterns, this.constructor.name);
validateOptions(patternsSchema, patterns, this.constructor.name);
validateOptions(optionsSchema, options, this.constructor.name);

this.patterns = patterns;
this.options = options;
Expand Down
111 changes: 27 additions & 84 deletions src/options.json
@@ -1,90 +1,33 @@
{
"definitions": {
"ObjectPattern": {
"type": "object",
"properties": {
"from": {
"anyOf": [
{
"type": "string",
"minLength": 1
},
{
"type": "object"
}
]
},
"to": {
"type": "string"
},
"context": {
"type": "string"
},
"toType": {
"enum": ["dir", "file", "template"]
},
"test": {
"anyOf": [
{
"type": "string"
},
{
"instanceof": "RegExp"
}
]
},
"force": {
"type": "boolean"
},
"ignore": {
"type": "array",
"items": {
"anyOf": [
{
"type": "string"
},
{
"type": "object"
}
]
"type": "object",
"additionalProperties": false,
"properties": {
"logLevel": {
"description": "Level of messages that the module will log",
"enum": ["trace", "debug", "info", "warn", "error", "silent"]
},
"ignore": {
"description": "Array of globs to ignore (applied to `from`)",
"type": "array",
"items": {
"anyOf": [
{
"type": "string"
},
{
"type": "object"
}
},
"flatten": {
"type": "boolean"
},
"cache": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "object"
}
]
},
"transform": {
"instanceof": "Function"
},
"transformPath": {
"instanceof": "Function"
}
},
"required": ["from"]
]
}
},
"StringPattern": {
"type": "string",
"minLength": 1
"context": {
"description": "A path that determines how to interpret the `from` path, shared for all patterns",
"type": "string"
},
"copyUnmodified": {
"description": "Copies files, regardless of modification, when using watchers",
"type": "boolean"
}
},
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/definitions/StringPattern"
},
{
"$ref": "#/definitions/ObjectPattern"
}
]
}
"title": "Options"
}
90 changes: 90 additions & 0 deletions src/patterns.json
@@ -0,0 +1,90 @@
{
"definitions": {
"ObjectPattern": {
"type": "object",
"properties": {
"from": {
"anyOf": [
{
"type": "string",
"minLength": 1
},
{
"type": "object"
}
]
},
"to": {
"type": "string"
},
"context": {
"type": "string"
},
"toType": {
"enum": ["dir", "file", "template"]
},
"test": {
"anyOf": [
{
"type": "string"
},
{
"instanceof": "RegExp"
}
]
},
"force": {
"type": "boolean"
},
"ignore": {
"type": "array",
"items": {
"anyOf": [
{
"type": "string"
},
{
"type": "object"
}
]
}
},
"flatten": {
"type": "boolean"
},
"cache": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "object"
}
]
},
"transform": {
"instanceof": "Function"
},
"transformPath": {
"instanceof": "Function"
}
},
"required": ["from"]
},
"StringPattern": {
"type": "string",
"minLength": 1
}
},
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/definitions/StringPattern"
},
{
"$ref": "#/definitions/ObjectPattern"
}
]
}
}

0 comments on commit 97738d5

Please sign in to comment.