Skip to content

Commit 7799a1a

Browse files
maoxiaokeClarkXia
andauthored
feat: 🎸 support user config & cli option check (#51)
* chore: format (#43) * feat: 🎸 support user config & cli optiojn check * chore: 🤖 changelog * refactor: 💡 refact function usage * refactor: 💡 changelog * chore: 🤖 changlog Co-authored-by: ClarkXia <xiawenwu41@gmail.com>
1 parent 4fc32ae commit 7799a1a

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ $ build-scripts start --help
3838
Usage: build-scripts start [options]
3939

4040
Options:
41-
--port <port> 服务端口号
42-
--host <host> 服务主机名
43-
--config <config> 自定义配置文件路径(支持 json 或者 js,推荐命名 build.config.js/build.json)
41+
--port <port> 服务端口号
42+
--host <host> 服务主机名
43+
--config <config> 自定义配置文件路径(支持 json 或者 js,推荐命名 build.config.js/build.json)
4444
```
4545

4646
build 命令:
@@ -51,7 +51,7 @@ $ build-scripts build --help
5151
Usage: build-scripts build [options]
5252

5353
Options:
54-
--config <config> 同 start
54+
--config <config> 同 start
5555
```
5656

5757
test 命令:
@@ -337,6 +337,21 @@ module.exports = ({ registerUserConfig }) => {
337337
};
338338
```
339339

340+
#### hasRegistration
341+
342+
判断 build.json 中的顶层配置字段或者 cli 参数是否已经注册:
343+
344+
```js
345+
module.exports = ({ hasRegistration }) => {
346+
// 判断 build.json 顶层配置字段 entry 是否已配置
347+
const hasEntryRegistered = hasRegistration('entry');
348+
349+
// 判断 cli --https 参数是否已被注册
350+
const hasHttpsRegistered = hasRegistration('https''cliOption');
351+
...
352+
}
353+
```
354+
340355
#### modifyConfigRegistration
341356

342357
用于修改已注册用户配置的行为:

packages/build-scripts/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [feat] support deep merge of modifyUserConfig by options
99
- [feat] enhance registerMethod API, make it possible to get plugin name when applyMethod
1010
- [feat] add `originalUserConfig` to plugin API
11+
- [feat] support `hasRegistration` api
1112
- [fix] move webpack-dev-server to peerDependencies and migrate webpack-dev-server to 4.0.0
1213

1314
## 1.0.1

packages/build-scripts/src/core/Context.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,11 @@ class Context {
717717
this.registerConfig('userConfig', args);
718718
};
719719

720+
public hasRegistration = (name: string, type: 'cliOption' | 'userConfig' = 'userConfig' ): boolean => {
721+
const mappedType = type === 'cliOption' ? 'cliOptionRegistration' : 'userConfigRegistration';
722+
return Object.keys(this[mappedType] || {}).includes(name);
723+
};
724+
720725
public registerCliOption = (args: MaybeArray<ICliOptionArgs>): void => {
721726
this.registerConfig('cliOption', args, name => {
722727
return camelCase(name, { pascalCase: false });
@@ -766,6 +771,7 @@ class Context {
766771
setValue: this.setValue,
767772
getValue: this.getValue,
768773
registerUserConfig: this.registerUserConfig,
774+
hasRegistration: this.hasRegistration,
769775
registerCliOption: this.registerCliOption,
770776
registerMethod: this.registerMethod,
771777
applyMethod,

0 commit comments

Comments
 (0)