|
1 | 1 | import type yargs from "yargs"; |
| 2 | + |
| 3 | +/** |
| 4 | + * Apply common options for all commands |
| 5 | + */ |
2 | 6 | export const commonOptions = (yargs: yargs.Argv) => { |
| 7 | + return yargs.options({ |
| 8 | + config: { |
| 9 | + g: true, |
| 10 | + type: "string", |
| 11 | + describe: "config file", |
| 12 | + alias: "c" |
| 13 | + }, |
| 14 | + configName: { |
| 15 | + type: "array", |
| 16 | + string: true, |
| 17 | + describe: "Name of the configuration to use." |
| 18 | + }, |
| 19 | + configLoader: { |
| 20 | + type: "string", |
| 21 | + default: "register", |
| 22 | + describe: |
| 23 | + "Specify the loader to load the config file, can be `native` or `register`." |
| 24 | + } |
| 25 | + }); |
| 26 | +}; |
| 27 | + |
| 28 | +/** |
| 29 | + * Apply common options for `build` and `serve` commands |
| 30 | + */ |
| 31 | +export const commonOptionsForBuildAndServe = (yargs: yargs.Argv) => { |
3 | 32 | return yargs |
4 | 33 | .options({ |
5 | | - config: { |
6 | | - g: true, |
7 | | - type: "string", |
8 | | - describe: "config file", |
9 | | - alias: "c" |
10 | | - }, |
11 | 34 | entry: { |
12 | 35 | type: "array", |
13 | 36 | string: true, |
@@ -39,64 +62,11 @@ export const commonOptions = (yargs: yargs.Argv) => { |
39 | 62 | default: false, |
40 | 63 | describe: "devtool", |
41 | 64 | alias: "d" |
42 | | - }, |
43 | | - configName: { |
44 | | - type: "array", |
45 | | - string: true, |
46 | | - describe: "Name of the configuration to use." |
47 | | - }, |
48 | | - configLoader: { |
49 | | - type: "string", |
50 | | - default: "register", |
51 | | - describe: |
52 | | - "Specify the loader to load the config file, can be `native` or `register`." |
53 | 65 | } |
54 | 66 | }) |
55 | 67 | .alias({ v: "version", h: "help" }); |
56 | 68 | }; |
57 | 69 |
|
58 | | -export const previewOptions = (yargs: yargs.Argv) => { |
59 | | - return yargs |
60 | | - .positional("dir", { |
61 | | - type: "string", |
62 | | - describe: "directory want to preview" |
63 | | - }) |
64 | | - .options({ |
65 | | - publicPath: { |
66 | | - type: "string", |
67 | | - describe: "static resource server path" |
68 | | - }, |
69 | | - config: { |
70 | | - g: true, |
71 | | - type: "string", |
72 | | - describe: "config file", |
73 | | - alias: "c" |
74 | | - }, |
75 | | - port: { |
76 | | - type: "number", |
77 | | - describe: "preview server port" |
78 | | - }, |
79 | | - host: { |
80 | | - type: "string", |
81 | | - describe: "preview server host" |
82 | | - }, |
83 | | - open: { |
84 | | - type: "boolean", |
85 | | - describe: "open browser" |
86 | | - }, |
87 | | - // same as devServer.server |
88 | | - server: { |
89 | | - type: "string", |
90 | | - describe: "Configuration items for the server." |
91 | | - }, |
92 | | - configName: { |
93 | | - type: "array", |
94 | | - string: true, |
95 | | - describe: "Name of the configuration to use." |
96 | | - } |
97 | | - }); |
98 | | -}; |
99 | | - |
100 | 70 | export function normalizeEnv(argv: yargs.Arguments) { |
101 | 71 | function parseValue(previous: Record<string, unknown>, value: string) { |
102 | 72 | const [allKeys, val] = value.split(/=(.+)/, 2); |
|
0 commit comments