MCPcopy Create free account
hub / github.com/webpack/webpack-cli / makeOption

Method makeOption

packages/webpack-cli/src/webpack-cli.ts:1027–1260  ·  view source on GitHub ↗
(command: Command, option: CommandOption)

Source from the content-addressed store, hash-verified

1025 }
1026
1027 makeOption(command: Command, option: CommandOption) {
1028 type MainOption = Pick<
1029 CommandOption,
1030 "valueName" | "description" | "defaultValue" | "multiple" | "configs"
1031 > & {
1032 flags: string;
1033 type: Set<BooleanConstructor | StringConstructor | NumberConstructor>;
1034 };
1035 type NegativeOption = Pick<
1036 CommandOption,
1037 "valueName" | "description" | "defaultValue" | "multiple"
1038 > & {
1039 flags: string;
1040 };
1041 let mainOption: MainOption;
1042 let negativeOption: NegativeOption | undefined;
1043
1044 if (FLAGS_WITH_ALIAS.has(option.name)) {
1045 [option.alias] = option.name;
1046 }
1047
1048 if (option.configs) {
1049 let needNegativeOption = false;
1050 let negatedDescription;
1051 const mainOptionType: MainOption["type"] = new Set();
1052
1053 for (const config of option.configs) {
1054 switch (config.type) {
1055 case "reset":
1056 mainOptionType.add(Boolean);
1057 break;
1058 case "boolean":
1059 if (!needNegativeOption) {
1060 needNegativeOption = true;
1061 negatedDescription = config.negatedDescription;
1062 }
1063
1064 mainOptionType.add(Boolean);
1065 break;
1066 case "number":
1067 mainOptionType.add(Number);
1068 break;
1069 case "string":
1070 case "path":
1071 case "RegExp":
1072 mainOptionType.add(String);
1073 break;
1074 case "enum": {
1075 let hasFalseEnum = false;
1076
1077 for (const value of config.values || []) {
1078 switch (typeof value) {
1079 case "string":
1080 mainOptionType.add(String);
1081 break;
1082 case "number":
1083 mainOptionType.add(Number);
1084 break;

Callers 1

makeCommandMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected