Skip to content

Commit

Permalink
chore(cli): move constants to a separate file (#798)
Browse files Browse the repository at this point in the history
* 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

* chore(cli): lint files, rm console.log

Format all code using prettier, remove console.log

ISSUES CLOSED: #772

* chore(cli): codacy fix

codacy fix

* chore(cli): split destructuring into multiple lines

split constants destructuring to multiple lines in config-yargs

* chore(cli): update var name, revert oc

update var name, revert oc

* chore(cli): moved constants to utils

moved constants to utils directory
  • Loading branch information
anshumanv authored and ematipico committed Mar 23, 2019
1 parent 473ff4a commit 0a2274e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 24 deletions.
16 changes: 3 additions & 13 deletions bin/cli.js
Expand Up @@ -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

Expand All @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 13 additions & 9 deletions 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 => {
Expand Down Expand Up @@ -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")
Expand Down
37 changes: 37 additions & 0 deletions 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
};
4 changes: 2 additions & 2 deletions bin/utils/errorHelpers.js
Expand Up @@ -4,15 +4,15 @@
*/
"use strict";

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

exports.cutOffByFlag = (stack, flag) => {
stack = stack.split("\n");
for (let i = 0; i < stack.length; i++) if (stack[i].indexOf(flag) >= 0) stack.length = i;
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");
Expand Down

0 comments on commit 0a2274e

Please sign in to comment.