diff --git a/bin/cli.js b/bin/cli.js index 9a34f7e6f7f..aa7df4c2d9c 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -5,6 +5,8 @@ Author Tobias Koppers @sokra */ +const { NON_COMPILATION_ARGS } = require("./utils/constants"); + (function() { // wrap in IIFE to be able to use return @@ -18,17 +20,6 @@ const ErrorHelpers = require("./utils/errorHelpers"); - const NON_COMPILATION_ARGS = [ - "init", - "migrate", - "add", - "remove", - "serve", - "generate-loader", - "generate-plugin", - "info" - ]; - const NON_COMPILATION_CMD = process.argv.find(arg => { if (arg === "serve") { global.process.argv = global.process.argv.filter(a => a !== "serve"); @@ -52,7 +43,6 @@ For more information, see https://webpack.js.org/api/cli/.`); require("./config/config-yargs")(yargs); - // yargs will terminate the process early when the user uses help or version. // This causes large help outputs to be cut short (https://github.com/nodejs/node/wiki/API-changes-between-v0.10-and-v4#process). // To prevent this we use the yargs.parse API and exit the process normally @@ -104,7 +94,7 @@ For more information, see https://webpack.js.org/api/cli/.`); const stdout = argv.silent ? { write: () => {} - } // eslint-disable-line + } // eslint-disable-line : process.stdout; function ifArg(name, fn, init) { diff --git a/bin/config/config-yargs.js b/bin/config/config-yargs.js index 19a3c489e68..105358875a7 100644 --- a/bin/config/config-yargs.js +++ b/bin/config/config-yargs.js @@ -1,5 +1,18 @@ const optionsSchema = require("../config/optionsSchema.json"); +const { GROUPS } = require("../utils/constants"); + +const { + CONFIG_GROUP, + BASIC_GROUP, + MODULE_GROUP, + OUTPUT_GROUP, + ADVANCED_GROUP, + RESOLVE_GROUP, + OPTIMIZE_GROUP, + DISPLAY_GROUP +} = GROUPS; + const nestedProperties = ["anyOf", "oneOf", "allOf"]; const resolveSchema = schema => { @@ -52,15 +65,6 @@ const getSchemaInfo = (path, property, subProperty) => { return findPropertyInSchema(current, property, subProperty); }; -const CONFIG_GROUP = "Config options:"; -const BASIC_GROUP = "Basic options:"; -const MODULE_GROUP = "Module options:"; -const OUTPUT_GROUP = "Output options:"; -const ADVANCED_GROUP = "Advanced options:"; -const RESOLVE_GROUP = "Resolving options:"; -const OPTIMIZE_GROUP = "Optimizing options:"; -const DISPLAY_GROUP = "Stats options:"; - module.exports = function(yargs) { yargs .help("help") diff --git a/bin/utils/constants.js b/bin/utils/constants.js new file mode 100644 index 00000000000..28a36c88a74 --- /dev/null +++ b/bin/utils/constants.js @@ -0,0 +1,37 @@ +const NON_COMPILATION_ARGS = [ + "init", + "migrate", + "add", + "remove", + "serve", + "generate-loader", + "generate-plugin", + "info" +]; + +const CONFIG_GROUP = "Config options:"; +const BASIC_GROUP = "Basic options:"; +const MODULE_GROUP = "Module options:"; +const OUTPUT_GROUP = "Output options:"; +const ADVANCED_GROUP = "Advanced options:"; +const RESOLVE_GROUP = "Resolving options:"; +const OPTIMIZE_GROUP = "Optimizing options:"; +const DISPLAY_GROUP = "Stats options:"; +const GROUPS = { + CONFIG_GROUP, + BASIC_GROUP, + MODULE_GROUP, + OUTPUT_GROUP, + ADVANCED_GROUP, + RESOLVE_GROUP, + OPTIMIZE_GROUP, + DISPLAY_GROUP +}; + +const WEBPACK_OPTIONS_FLAG = "WEBPACK_OPTIONS"; + +module.exports = { + NON_COMPILATION_ARGS, + GROUPS, + WEBPACK_OPTIONS_FLAG +}; diff --git a/bin/utils/errorHelpers.js b/bin/utils/errorHelpers.js index 5098f4ca14d..96fe950f34d 100644 --- a/bin/utils/errorHelpers.js +++ b/bin/utils/errorHelpers.js @@ -4,7 +4,7 @@ */ "use strict"; -const webpackOptionsFlag = "WEBPACK_OPTIONS"; +const { WEBPACK_OPTIONS_FLAG } = require("./constants"); exports.cutOffByFlag = (stack, flag) => { stack = stack.split("\n"); @@ -12,7 +12,7 @@ exports.cutOffByFlag = (stack, flag) => { return stack.join("\n"); }; -exports.cutOffWebpackOptions = stack => exports.cutOffByFlag(stack, webpackOptionsFlag); +exports.cutOffWebpackOptions = stack => exports.cutOffByFlag(stack, WEBPACK_OPTIONS_FLAG); exports.cutOffMultilineMessage = (stack, message) => { stack = stack.split("\n");