Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

config-yargs.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. const optionsSchema = require("../config/optionsSchema.json");
  2. const { GROUPS } = require("../utils/constants");
  3. const {
  4. CONFIG_GROUP,
  5. BASIC_GROUP,
  6. MODULE_GROUP,
  7. OUTPUT_GROUP,
  8. ADVANCED_GROUP,
  9. RESOLVE_GROUP,
  10. OPTIMIZE_GROUP,
  11. DISPLAY_GROUP
  12. } = GROUPS;
  13. const nestedProperties = ["anyOf", "oneOf", "allOf"];
  14. const resolveSchema = schema => {
  15. let current = schema;
  16. if (schema && typeof schema === "object" && "$ref" in schema) {
  17. const path = schema.$ref.split("/");
  18. for (const element of path) {
  19. if (element === "#") {
  20. current = optionsSchema;
  21. } else {
  22. current = current[element];
  23. }
  24. }
  25. }
  26. return current;
  27. };
  28. const findPropertyInSchema = (schema, property, subProperty) => {
  29. if (!schema) return null;
  30. if (subProperty) {
  31. if (schema[property] && typeof schema[property] === "object" && subProperty in schema[property]) {
  32. return resolveSchema(schema[property][subProperty]);
  33. }
  34. } else {
  35. if (property in schema) return resolveSchema(schema[property]);
  36. }
  37. for (const name of nestedProperties) {
  38. if (schema[name]) {
  39. for (const item of schema[name]) {
  40. const resolvedItem = resolveSchema(item);
  41. const result = findPropertyInSchema(resolvedItem, property, subProperty);
  42. if (result) return result;
  43. }
  44. }
  45. }
  46. return undefined;
  47. };
  48. const getSchemaInfo = (path, property, subProperty) => {
  49. const pathSegments = path.split(".");
  50. let current = optionsSchema;
  51. for (const segment of pathSegments) {
  52. if (segment === "*") {
  53. current = findPropertyInSchema(current, "additionalProperties") || findPropertyInSchema(current, "items");
  54. } else {
  55. current = findPropertyInSchema(current, "properties", segment);
  56. }
  57. if (!current) return undefined;
  58. }
  59. return findPropertyInSchema(current, property, subProperty);
  60. };
  61. module.exports = function(yargs) {
  62. yargs
  63. .help("help")
  64. .alias("help", "h")
  65. .version()
  66. .alias("version", "v")
  67. .options({
  68. config: {
  69. type: "string",
  70. describe: "Path to the config file",
  71. group: CONFIG_GROUP,
  72. defaultDescription: "webpack.config.js or webpackfile.js",
  73. requiresArg: true
  74. },
  75. "config-register": {
  76. type: "array",
  77. alias: "r",
  78. describe: "Preload one or more modules before loading the webpack configuration",
  79. group: CONFIG_GROUP,
  80. defaultDescription: "module id or path",
  81. requiresArg: true
  82. },
  83. "config-name": {
  84. type: "string",
  85. describe: "Name of the config to use",
  86. group: CONFIG_GROUP,
  87. requiresArg: true
  88. },
  89. env: {
  90. describe: "Environment passed to the config, when it is a function",
  91. group: CONFIG_GROUP
  92. },
  93. mode: {
  94. type: getSchemaInfo("mode", "type"),
  95. choices: getSchemaInfo("mode", "enum"),
  96. describe: getSchemaInfo("mode", "description"),
  97. group: CONFIG_GROUP,
  98. requiresArg: true
  99. },
  100. context: {
  101. type: getSchemaInfo("context", "type"),
  102. describe: getSchemaInfo("context", "description"),
  103. group: BASIC_GROUP,
  104. defaultDescription: "The current directory",
  105. requiresArg: true
  106. },
  107. entry: {
  108. type: "string",
  109. describe: getSchemaInfo("entry", "description"),
  110. group: BASIC_GROUP,
  111. requiresArg: true
  112. },
  113. "module-bind": {
  114. type: "string",
  115. describe: "Bind an extension to a loader",
  116. group: MODULE_GROUP,
  117. requiresArg: true
  118. },
  119. "module-bind-post": {
  120. type: "string",
  121. describe: "Bind an extension to a post loader",
  122. group: MODULE_GROUP,
  123. requiresArg: true
  124. },
  125. "module-bind-pre": {
  126. type: "string",
  127. describe: "Bind an extension to a pre loader",
  128. group: MODULE_GROUP,
  129. requiresArg: true
  130. },
  131. output: {
  132. alias: "o",
  133. describe: "The output path and file for compilation assets",
  134. group: OUTPUT_GROUP,
  135. requiresArg: true
  136. },
  137. "output-path": {
  138. type: "string",
  139. describe: getSchemaInfo("output.path", "description"),
  140. group: OUTPUT_GROUP,
  141. defaultDescription: "The current directory",
  142. requiresArg: true
  143. },
  144. "output-filename": {
  145. type: "string",
  146. describe: getSchemaInfo("output.filename", "description"),
  147. group: OUTPUT_GROUP,
  148. defaultDescription: "[name].js",
  149. requiresArg: true
  150. },
  151. "output-chunk-filename": {
  152. type: "string",
  153. describe: getSchemaInfo("output.chunkFilename", "description"),
  154. group: OUTPUT_GROUP,
  155. defaultDescription: "filename with [id] instead of [name] or [id] prefixed",
  156. requiresArg: true
  157. },
  158. "output-source-map-filename": {
  159. type: "string",
  160. describe: getSchemaInfo("output.sourceMapFilename", "description"),
  161. group: OUTPUT_GROUP,
  162. requiresArg: true
  163. },
  164. "output-public-path": {
  165. type: "string",
  166. describe: getSchemaInfo("output.publicPath", "description"),
  167. group: OUTPUT_GROUP,
  168. requiresArg: true
  169. },
  170. "output-jsonp-function": {
  171. type: "string",
  172. describe: getSchemaInfo("output.jsonpFunction", "description"),
  173. group: OUTPUT_GROUP,
  174. requiresArg: true
  175. },
  176. "output-pathinfo": {
  177. type: "boolean",
  178. describe: getSchemaInfo("output.pathinfo", "description"),
  179. group: OUTPUT_GROUP
  180. },
  181. "output-library": {
  182. type: "array",
  183. describe: "Expose the exports of the entry point as library",
  184. group: OUTPUT_GROUP,
  185. requiresArg: true
  186. },
  187. "output-library-target": {
  188. type: "string",
  189. describe: getSchemaInfo("output.libraryTarget", "description"),
  190. choices: getSchemaInfo("output.libraryTarget", "enum"),
  191. group: OUTPUT_GROUP,
  192. requiresArg: true
  193. },
  194. "records-input-path": {
  195. type: "string",
  196. describe: getSchemaInfo("recordsInputPath", "description"),
  197. group: ADVANCED_GROUP,
  198. requiresArg: true
  199. },
  200. "records-output-path": {
  201. type: "string",
  202. describe: getSchemaInfo("recordsOutputPath", "description"),
  203. group: ADVANCED_GROUP,
  204. requiresArg: true
  205. },
  206. "records-path": {
  207. type: "string",
  208. describe: getSchemaInfo("recordsPath", "description"),
  209. group: ADVANCED_GROUP,
  210. requiresArg: true
  211. },
  212. define: {
  213. type: "string",
  214. describe: "Define any free var in the bundle",
  215. group: ADVANCED_GROUP,
  216. requiresArg: true
  217. },
  218. target: {
  219. type: "string",
  220. describe: getSchemaInfo("target", "description"),
  221. group: ADVANCED_GROUP,
  222. requiresArg: true
  223. },
  224. cache: {
  225. type: "boolean",
  226. describe: getSchemaInfo("cache", "description"),
  227. default: null,
  228. group: ADVANCED_GROUP,
  229. defaultDescription: "It's enabled by default when watching"
  230. },
  231. watch: {
  232. type: "boolean",
  233. alias: "w",
  234. describe: getSchemaInfo("watch", "description"),
  235. group: BASIC_GROUP
  236. },
  237. "watch-stdin": {
  238. type: "boolean",
  239. alias: "stdin",
  240. describe: getSchemaInfo("watchOptions.stdin", "description"),
  241. group: ADVANCED_GROUP
  242. },
  243. "watch-aggregate-timeout": {
  244. describe: getSchemaInfo("watchOptions.aggregateTimeout", "description"),
  245. type: getSchemaInfo("watchOptions.aggregateTimeout", "type"),
  246. group: ADVANCED_GROUP,
  247. requiresArg: true
  248. },
  249. "watch-poll": {
  250. type: "string",
  251. describe: getSchemaInfo("watchOptions.poll", "description"),
  252. group: ADVANCED_GROUP
  253. },
  254. hot: {
  255. type: "boolean",
  256. describe: "Enables Hot Module Replacement",
  257. group: ADVANCED_GROUP
  258. },
  259. debug: {
  260. type: "boolean",
  261. describe: "Switch loaders to debug mode",
  262. group: BASIC_GROUP
  263. },
  264. devtool: {
  265. type: "string",
  266. describe: getSchemaInfo("devtool", "description"),
  267. group: BASIC_GROUP,
  268. requiresArg: true
  269. },
  270. "resolve-alias": {
  271. type: "string",
  272. describe: getSchemaInfo("resolve.alias", "description"),
  273. group: RESOLVE_GROUP,
  274. requiresArg: true
  275. },
  276. "resolve-extensions": {
  277. type: "array",
  278. describe: getSchemaInfo("resolve.alias", "description"),
  279. group: RESOLVE_GROUP,
  280. requiresArg: true
  281. },
  282. "resolve-loader-alias": {
  283. type: "string",
  284. describe: "Setup a loader alias for resolving",
  285. group: RESOLVE_GROUP,
  286. requiresArg: true
  287. },
  288. "optimize-max-chunks": {
  289. describe: "Try to keep the chunk count below a limit",
  290. group: OPTIMIZE_GROUP,
  291. requiresArg: true
  292. },
  293. "optimize-min-chunk-size": {
  294. describe: getSchemaInfo("optimization.splitChunks.minSize", "description"),
  295. group: OPTIMIZE_GROUP,
  296. requiresArg: true
  297. },
  298. "optimize-minimize": {
  299. type: "boolean",
  300. describe: getSchemaInfo("optimization.minimize", "description"),
  301. group: OPTIMIZE_GROUP
  302. },
  303. prefetch: {
  304. type: "string",
  305. describe: "Prefetch this request (Example: --prefetch ./file.js)",
  306. group: ADVANCED_GROUP,
  307. requiresArg: true
  308. },
  309. provide: {
  310. type: "string",
  311. describe: "Provide these modules as free vars in all modules (Example: --provide jQuery=jquery)",
  312. group: ADVANCED_GROUP,
  313. requiresArg: true
  314. },
  315. "labeled-modules": {
  316. type: "boolean",
  317. describe: "Enables labeled modules",
  318. group: ADVANCED_GROUP
  319. },
  320. plugin: {
  321. type: "string",
  322. describe: "Load this plugin",
  323. group: ADVANCED_GROUP,
  324. requiresArg: true
  325. },
  326. bail: {
  327. type: getSchemaInfo("bail", "type"),
  328. describe: getSchemaInfo("bail", "description"),
  329. group: ADVANCED_GROUP,
  330. default: null
  331. },
  332. profile: {
  333. type: "boolean",
  334. describe: getSchemaInfo("profile", "description"),
  335. group: ADVANCED_GROUP,
  336. default: null
  337. },
  338. d: {
  339. type: "boolean",
  340. describe: "shortcut for --debug --devtool eval-cheap-module-source-map --output-pathinfo",
  341. group: BASIC_GROUP
  342. },
  343. p: {
  344. type: "boolean",
  345. // eslint-disable-next-line quotes
  346. describe: 'shortcut for --optimize-minimize --define process.env.NODE_ENV="production"',
  347. group: BASIC_GROUP
  348. },
  349. silent: {
  350. type: "boolean",
  351. describe: "Prevent output from being displayed in stdout"
  352. },
  353. json: {
  354. type: "boolean",
  355. alias: "j",
  356. describe: "Prints the result as JSON."
  357. },
  358. progress: {
  359. type: "boolean",
  360. describe: "Print compilation progress in percentage",
  361. group: BASIC_GROUP
  362. },
  363. color: {
  364. type: "boolean",
  365. alias: "colors",
  366. default: function supportsColor() {
  367. return require("supports-color").stdout;
  368. },
  369. group: DISPLAY_GROUP,
  370. describe: "Force colors on the console"
  371. },
  372. "no-color": {
  373. type: "boolean",
  374. alias: "no-colors",
  375. group: DISPLAY_GROUP,
  376. describe: "Force no colors on the console"
  377. },
  378. "sort-modules-by": {
  379. type: "string",
  380. group: DISPLAY_GROUP,
  381. describe: "Sorts the modules list by property in module"
  382. },
  383. "sort-chunks-by": {
  384. type: "string",
  385. group: DISPLAY_GROUP,
  386. describe: "Sorts the chunks list by property in chunk"
  387. },
  388. "sort-assets-by": {
  389. type: "string",
  390. group: DISPLAY_GROUP,
  391. describe: "Sorts the assets list by property in asset"
  392. },
  393. "hide-modules": {
  394. type: "boolean",
  395. group: DISPLAY_GROUP,
  396. describe: "Hides info about modules"
  397. },
  398. "display-exclude": {
  399. type: "string",
  400. group: DISPLAY_GROUP,
  401. describe: "Exclude modules in the output"
  402. },
  403. "display-modules": {
  404. type: "boolean",
  405. group: DISPLAY_GROUP,
  406. describe: "Display even excluded modules in the output"
  407. },
  408. "display-max-modules": {
  409. type: "number",
  410. group: DISPLAY_GROUP,
  411. describe: "Sets the maximum number of visible modules in output"
  412. },
  413. "display-chunks": {
  414. type: "boolean",
  415. group: DISPLAY_GROUP,
  416. describe: "Display chunks in the output"
  417. },
  418. "display-entrypoints": {
  419. type: "boolean",
  420. group: DISPLAY_GROUP,
  421. describe: "Display entry points in the output"
  422. },
  423. "display-origins": {
  424. type: "boolean",
  425. group: DISPLAY_GROUP,
  426. describe: "Display origins of chunks in the output"
  427. },
  428. "display-cached": {
  429. type: "boolean",
  430. group: DISPLAY_GROUP,
  431. describe: "Display also cached modules in the output"
  432. },
  433. "display-cached-assets": {
  434. type: "boolean",
  435. group: DISPLAY_GROUP,
  436. describe: "Display also cached assets in the output"
  437. },
  438. "display-reasons": {
  439. type: "boolean",
  440. group: DISPLAY_GROUP,
  441. describe: "Display reasons about module inclusion in the output"
  442. },
  443. "display-depth": {
  444. type: "boolean",
  445. group: DISPLAY_GROUP,
  446. describe: "Display distance from entry point for each module"
  447. },
  448. "display-used-exports": {
  449. type: "boolean",
  450. group: DISPLAY_GROUP,
  451. describe: "Display information about used exports in modules (Tree Shaking)"
  452. },
  453. "display-provided-exports": {
  454. type: "boolean",
  455. group: DISPLAY_GROUP,
  456. describe: "Display information about exports provided from modules"
  457. },
  458. "display-optimization-bailout": {
  459. type: "boolean",
  460. group: DISPLAY_GROUP,
  461. describe: "Display information about why optimization bailed out for modules"
  462. },
  463. "display-error-details": {
  464. type: "boolean",
  465. group: DISPLAY_GROUP,
  466. describe: "Display details about errors"
  467. },
  468. display: {
  469. type: "string",
  470. choices: ["", "verbose", "detailed", "normal", "minimal", "errors-only", "none"],
  471. group: DISPLAY_GROUP,
  472. describe: "Select display preset"
  473. },
  474. verbose: {
  475. type: "boolean",
  476. group: DISPLAY_GROUP,
  477. describe: "Show more details"
  478. },
  479. "info-verbosity": {
  480. type: "string",
  481. default: "info",
  482. choices: ["none", "info", "verbose"],
  483. group: DISPLAY_GROUP,
  484. describe: "Controls the output of lifecycle messaging e.g. Started watching files..."
  485. },
  486. "build-delimiter": {
  487. type: "string",
  488. group: DISPLAY_GROUP,
  489. describe: "Display custom text after build output"
  490. }
  491. });
  492. };