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

Retrieve information for CLI option from webpack schema options file #392

Merged
merged 2 commits into from
Apr 15, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bin/config-yargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const RESOLVE_GROUP = "Resolving options:";
const OPTIMIZE_GROUP = "Optimizing options:";
const INIT_GROUP = "Initialization:";

const availableModes = () => {
const webpackOptionsSchema = require("webpack/schemas/WebpackOptions.json");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this statement on top of the file rather than doing inline require?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we move the require to the top of the file, perhaps with a less-redundant name like optionsSchema, why not just reference optionsSchema.properties.mode.enum directly in the mode object below? It would save the unnecessary indirection of creating a function that's only called in one place:

const optionsSchema = require("webpack/schemas/WebpackOptions.json");

// ...

mode: {
	choices: optionsSchema.properties.mode.enum,
	// ...
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bitpshr i'm actually doing that now. I refactored all that file to get all the informations from webpack schema. I will be updating it ASAP.

return webpackOptionsSchema.properties.mode.enum;
};

module.exports = function(yargs) {
yargs
.help("help")
Expand Down Expand Up @@ -88,7 +93,7 @@ module.exports = function(yargs) {
},
mode: {
type: "string",
choices: ["development", "production", "none"],
choices: availableModes(),
describe: "Mode to use",
group: CONFIG_GROUP,
requiresArg: true
Expand Down