| 84 | * @returns {Flags} object of arguments |
| 85 | */ |
| 86 | const getArguments = (schema = webpackSchema) => { |
| 87 | /** @type {Flags} */ |
| 88 | const flags = {}; |
| 89 | |
| 90 | /** |
| 91 | * Path to argument name. |
| 92 | * @param {string} input input |
| 93 | * @returns {string} result |
| 94 | */ |
| 95 | const pathToArgumentName = (input) => |
| 96 | input |
| 97 | .replace(/\./g, "-") |
| 98 | .replace(/\[\]/g, "") |
| 99 | .replace( |
| 100 | /(\p{Uppercase_Letter}+|\p{Lowercase_Letter}|\d)(\p{Uppercase_Letter}+)/gu, |
| 101 | "$1-$2" |
| 102 | ) |
| 103 | .replace(/-?[^\p{Uppercase_Letter}\p{Lowercase_Letter}\d]+/gu, "-") |
| 104 | .toLowerCase(); |
| 105 | |
| 106 | /** |
| 107 | * Returns schema part. |
| 108 | * @param {string} path path |
| 109 | * @returns {Schema} schema part |
| 110 | */ |
| 111 | const getSchemaPart = (path) => { |
| 112 | const newPath = path.split("/"); |
| 113 | |
| 114 | let schemaPart = schema; |
| 115 | |
| 116 | for (let i = 1; i < newPath.length; i++) { |
| 117 | const inner = schemaPart[/** @type {keyof Schema} */ (newPath[i])]; |
| 118 | |
| 119 | if (!inner) { |
| 120 | break; |
| 121 | } |
| 122 | |
| 123 | schemaPart = inner; |
| 124 | } |
| 125 | |
| 126 | return schemaPart; |
| 127 | }; |
| 128 | |
| 129 | /** |
| 130 | * Returns description. |
| 131 | * @param {PathItem[]} path path in the schema |
| 132 | * @returns {string | undefined} description |
| 133 | */ |
| 134 | const getDescription = (path) => { |
| 135 | for (const { schema } of path) { |
| 136 | if (schema.cli) { |
| 137 | if (schema.cli.helper) continue; |
| 138 | if (schema.cli.description) return schema.cli.description; |
| 139 | } |
| 140 | if (schema.description) return schema.description; |
| 141 | } |
| 142 | }; |
| 143 | |