Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): move constants to a separate file #798

Merged
merged 6 commits into from Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 3 additions & 12 deletions bin/cli.js
Expand Up @@ -18,16 +18,7 @@

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");
anshumanv marked this conversation as resolved.
Show resolved Hide resolved

const NON_COMPILATION_CMD = process.argv.find(arg => {
if (arg === "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 All @@ -131,6 +121,7 @@ For more information, see https://webpack.js.org/api/cli/.`);
const statsPresetToOptions = require("webpack").Stats.presetToOptions;

let outputOptions = options.stats;
console.log(outputOptions);
anshumanv marked this conversation as resolved.
Show resolved Hide resolved
if (typeof outputOptions === "boolean" || typeof outputOptions === "string") {
outputOptions = statsPresetToOptions(outputOptions);
} else if (!outputOptions) {
Expand Down
20 changes: 12 additions & 8 deletions bin/config/config-yargs.js
Expand Up @@ -52,14 +52,18 @@ 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
37 changes: 37 additions & 0 deletions bin/constants.js
@@ -0,0 +1,37 @@
const NON_COMPILATION_ARGS = [
"init",
"migrate",
anshumanv marked this conversation as resolved.
Show resolved Hide resolved
"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";
anshumanv marked this conversation as resolved.
Show resolved Hide resolved

module.exports = {
NON_COMPILATION_ARGS,
GROUPS,
webpackOptionsFlag
};
6 changes: 5 additions & 1 deletion bin/opencollective.js
Expand Up @@ -26,7 +26,11 @@ function printBadge() {
print(`Please consider donating to our ${chalk.bold.blue("Open Collective")}`);
print("to help us maintain this package.");
console.log("\n\n");
print(`${emoji("👉")} ${chalk.bold.yellow(" Donate:")} ${chalk.reset.underline.yellow("https://opencollective.com/webpack/donate")}`);
print(
anshumanv marked this conversation as resolved.
Show resolved Hide resolved
`${emoji("👉")} ${chalk.bold.yellow(" Donate:")} ${chalk.reset.underline.yellow(
"https://opencollective.com/webpack/donate"
)}`
);
console.log("\n");
}

Expand Down
2 changes: 1 addition & 1 deletion bin/utils/errorHelpers.js
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