1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const chalk = require('chalk');
|
12 | const decamelize = require('decamelize');
|
13 | const objectPath = require('object-path');
|
14 |
|
15 | const custom = ['clientAddress', 'clientRetry', 'clientSilent'];
|
16 | const allowed = ['_', 'all', 'config', 'help', 'silent', 'version'];
|
17 | const 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 |
|
32 | module.exports = {
|
33 | check(flags) {
|
34 | const validFlags = [].concat(allowed, custom, plugin);
|
35 |
|
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 | };
|