Skip to content

Commit

Permalink
chore(cli): move constants to a separate file
Browse files Browse the repository at this point in the history
moved all constants to a separate file for CLI scopre and imported from there.

ISSUES CLOSED: webpack#772
  • Loading branch information
anshumanv committed Mar 21, 2019
1 parent 473ff4a commit e5e8d9f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
14 changes: 4 additions & 10 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 3 additions & 8 deletions bin/config/config-yargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions bin/constants.js
Original file line number Diff line number Diff line change
@@ -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,
}
2 changes: 1 addition & 1 deletion bin/utils/errorHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
"use strict";

const webpackOptionsFlag = "WEBPACK_OPTIONS";
const { webpackOptionsFlag } = require('../constants')

exports.cutOffByFlag = (stack, flag) => {
stack = stack.split("\n");
Expand Down

0 comments on commit e5e8d9f

Please sign in to comment.