UNPKG

1.92 kBJavaScriptView Raw
1/*
2 Copyright © 2018 Andrew Powell
3
4 This Source Code Form is subject to the terms of the Mozilla Public
5 License, v. 2.0. If a copy of the MPL was not distributed with this
6 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8 The above copyright notice and this permission notice shall be
9 included in all copies or substantial portions of this Source Code Form.
10*/
11const {
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');
28const isPromise = require('is-promise');
29
30const promise = refine(any(), 'promise-like', (value) => isPromise(value));
31
32module.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};