UNPKG

1.82 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 chalk = require('chalk');
12const decamelize = require('decamelize');
13const objectPath = require('object-path');
14
15const custom = ['clientAddress', 'clientRetry', 'clientSilent'];
16const allowed = ['_', 'all', 'config', 'help', 'silent', 'version'];
17const plugin = [
18 'compress',
19 'historyFallback',
20 'hmr',
21 'host',
22 'http2',
23 'liveReload',
24 'open',
25 'port',
26 'progress',
27 'static',
28 'status',
29 'waitForBuild'
30];
31
32module.exports = {
33 check(flags) {
34 const validFlags = [].concat(allowed, custom, plugin);
35 // eslint-disable-next-line no-bitwise
36 const userFlags = Object.keys(flags).filter((flag) => flag.indexOf('-') === -1);
37 const deprecated = userFlags
38 .filter((flag) => !validFlags.includes(flag))
39 .map((flag) => decamelize(flag, '-'));
40
41 if (deprecated.length) {
42 const { error: stderr } = console;
43
44 stderr(chalk`{yellow ˢᵉʳᵛᵉ} Some options were passed which are unsupported:
45
46 {blue --${deprecated.join('\n --')}}
47
48 {dim Please run {reset webpack-serve --help} for a list of supported flags.}
49`);
50 }
51 },
52
53 prepare(flags) {
54 const result = {};
55
56 for (const flag of Object.keys(flags)) {
57 const value = flags[flag];
58 if (plugin.includes(flag)) {
59 result[flag] = value;
60 }
61
62 if (custom.includes(flag)) {
63 const path = decamelize(flag, '.');
64 objectPath.set(result, path, value);
65 }
66 }
67
68 return result;
69 }
70};