1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const {
|
12 | refine,
|
13 | any,
|
14 | nullable,
|
15 | type,
|
16 | partial,
|
17 | array,
|
18 | union,
|
19 | integer,
|
20 | max,
|
21 | boolean,
|
22 | string,
|
23 | func,
|
24 | literal,
|
25 | never,
|
26 | validate
|
27 | } = require('superstruct');
|
28 | const isPromise = require('is-promise');
|
29 |
|
30 | const promise = refine(any(), 'promise-like', (value) => isPromise(value));
|
31 |
|
32 | module.exports = {
|
33 | validate(options) {
|
34 | const schema = partial({
|
35 | allowMany: boolean(),
|
36 | client: partial({
|
37 | address: string(),
|
38 | protocol: union([literal('ws'), literal('wss')]),
|
39 | retry: boolean(),
|
40 | silent: boolean()
|
41 | }),
|
42 | compress: nullable(boolean()),
|
43 | headers: nullable(type({})),
|
44 | historyFallback: union([boolean(), type({})]),
|
45 | hmr: union([boolean(), literal('refresh-on-failure')]),
|
46 | host: nullable(union([promise, string()])),
|
47 | http2: union([boolean(), type({})]),
|
48 | https: nullable(type({})),
|
49 | liveReload: boolean(),
|
50 | log: partial({ level: string(), timestamp: boolean() }),
|
51 | middleware: func(),
|
52 | open: union([boolean(), type({})]),
|
53 | port: union([max(integer(), 65535), promise]),
|
54 | progress: union([boolean(), literal('minimal')]),
|
55 | publicPath: nullable(string()),
|
56 | ramdisk: union([boolean(), type({})]),
|
57 | secure: never(),
|
58 | static: nullable(
|
59 | union([string(), array(string()), partial({ glob: array(string()), options: type({}) })])
|
60 | ),
|
61 | status: boolean(),
|
62 | waitForBuild: boolean()
|
63 | });
|
64 | const [error, value] = validate(options, schema);
|
65 |
|
66 | return { error, value };
|
67 | }
|
68 | };
|