From e5e8d9f540026f22bccc64cee971e8448802186b Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Thu, 21 Mar 2019 15:00:30 +0530 Subject: [PATCH] chore(cli): move constants to a separate file moved all constants to a separate file for CLI scopre and imported from there. ISSUES CLOSED: #772 --- bin/cli.js | 14 ++++---------- bin/config/config-yargs.js | 11 +++-------- bin/constants.js | 28 ++++++++++++++++++++++++++++ bin/utils/errorHelpers.js | 2 +- 4 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 bin/constants.js diff --git a/bin/cli.js b/bin/cli.js index 9a34f7e6f7f..47bf3f39029 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -18,17 +18,10 @@ const ErrorHelpers = require("./utils/errorHelpers"); - const NON_COMPILATION_ARGS = [ - "init", - "migrate", - "add", - "remove", - "serve", - "generate-loader", - "generate-plugin", - "info" - ]; + const { NON_COMPILATION_ARGS } = require("./constants") + + console.log(NON_COMPILATION_ARGS) const NON_COMPILATION_CMD = process.argv.find(arg => { if (arg === "serve") { global.process.argv = global.process.argv.filter(a => a !== "serve"); @@ -131,6 +124,7 @@ For more information, see https://webpack.js.org/api/cli/.`); const statsPresetToOptions = require("webpack").Stats.presetToOptions; let outputOptions = options.stats; + console.log(outputOptions) if (typeof outputOptions === "boolean" || typeof outputOptions === "string") { outputOptions = statsPresetToOptions(outputOptions); } else if (!outputOptions) { diff --git a/bin/config/config-yargs.js b/bin/config/config-yargs.js index 19a3c489e68..0487e93795c 100644 --- a/bin/config/config-yargs.js +++ b/bin/config/config-yargs.js @@ -52,14 +52,9 @@ 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:"; +const { GROUPS } = require("../constants"); + +const { CONFIG_GROUP, BASIC_GROUP, MODULE_GROUP, OUTPUT_GROUP, ADVANCED_GROUP, RESOLVE_GROUP, OPTIMIZE_GROUP, DISPLAY_GROUP } = GROUPS; module.exports = function(yargs) { yargs diff --git a/bin/constants.js b/bin/constants.js new file mode 100644 index 00000000000..7ccb96d78a3 --- /dev/null +++ b/bin/constants.js @@ -0,0 +1,28 @@ +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 webpackOptionsFlag = "WEBPACK_OPTIONS"; + +module.exports = { + NON_COMPILATION_ARGS, + GROUPS, + webpackOptionsFlag, +} \ No newline at end of file diff --git a/bin/utils/errorHelpers.js b/bin/utils/errorHelpers.js index 5098f4ca14d..f3f7e5df228 100644 --- a/bin/utils/errorHelpers.js +++ b/bin/utils/errorHelpers.js @@ -4,7 +4,7 @@ */ "use strict"; -const webpackOptionsFlag = "WEBPACK_OPTIONS"; +const { webpackOptionsFlag } = require('../constants') exports.cutOffByFlag = (stack, flag) => { stack = stack.split("\n");