Skip to content

Commit

Permalink
refactor: migrate stats group (#1831)
Browse files Browse the repository at this point in the history
* refactor: migrate stats group

* refactor: migrate stats group

Co-authored-by: Rishabh Chawla <rishabh31121999@gmail.com>
  • Loading branch information
anshumanv and rishabh3112 committed Sep 25, 2020
1 parent b363e44 commit 5bae797
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 52 deletions.
15 changes: 0 additions & 15 deletions packages/webpack-cli/__tests__/StatsGroup.test.js

This file was deleted.

19 changes: 19 additions & 0 deletions packages/webpack-cli/__tests__/resolveStats.js
@@ -0,0 +1,19 @@
const resolveStats = require('../lib/groups/resolveStats');

describe('StatsGroup', function () {
it('should assign json correctly', () => {
const result = resolveStats({
json: true,
});
expect(result.options.stats).toBeFalsy();
expect(result.outputOptions.json).toBeTruthy();
});

it('should assign stats correctly', () => {
const result = resolveStats({
stats: 'warning',
});
expect(result.options.stats).toEqual('warning');
expect(result.outputOptions.json).toBeFalsy();
});
});
26 changes: 0 additions & 26 deletions packages/webpack-cli/lib/groups/StatsGroup.js

This file was deleted.

22 changes: 22 additions & 0 deletions packages/webpack-cli/lib/groups/resolveStats.js
@@ -0,0 +1,22 @@
/**
* Resolve flags which deal with compilation stats
* @param {args} args - Parsed args passed to CLI
*/
const resolveStats = (args) => {
const { stats, json } = args;

const finalOptions = {
options: {},
outputOptions: {},
};

if (stats !== undefined) {
finalOptions.options.stats = stats;
}
if (json) {
finalOptions.outputOptions.json = true;
}
return finalOptions;
};

module.exports = resolveStats;
5 changes: 0 additions & 5 deletions packages/webpack-cli/lib/utils/cli-flags.js
Expand Up @@ -5,7 +5,6 @@ const CONFIG_GROUP = 'config';
const BASIC_GROUP = 'basic';
const OUTPUT_GROUP = 'output';
const ADVANCED_GROUP = 'advanced';
const DISPLAY_GROUP = 'stats';
const ZERO_CONFIG_GROUP = 'zero-config';

const groups = {
Expand All @@ -14,7 +13,6 @@ const groups = {
BASIC_GROUP,
OUTPUT_GROUP,
ADVANCED_GROUP,
DISPLAY_GROUP,
ZERO_CONFIG_GROUP,
};

Expand Down Expand Up @@ -99,7 +97,6 @@ const core = [
name: 'color',
usage: '--color',
type: Boolean,
group: DISPLAY_GROUP,
negative: true,
defaultValue: true,
description: 'Enable/Disable colors on console',
Expand Down Expand Up @@ -189,7 +186,6 @@ const core = [
type: Boolean,
alias: 'j',
description: 'Prints result as JSON',
group: DISPLAY_GROUP,
},
{
name: 'mode',
Expand All @@ -210,7 +206,6 @@ const core = [
name: 'stats',
usage: '--stats <value>',
type: [String, Boolean],
group: DISPLAY_GROUP,
negative: true,
description: 'It instructs webpack on how to treat the stats e.g. verbose',
link: 'https://webpack.js.org/configuration/stats/#stats',
Expand Down
8 changes: 2 additions & 6 deletions packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -2,6 +2,7 @@ const { options } = require('colorette');
const GroupHelper = require('./utils/GroupHelper');
const handleConfigResolution = require('./groups/ConfigGroup');
const resolveMode = require('./groups/resolveMode');
const resolveStats = require('./groups/resolveStats');
const { Compiler } = require('./utils/Compiler');
const { groups, core } = require('./utils/cli-flags');
const webpackMerge = require('webpack-merge');
Expand Down Expand Up @@ -114,11 +115,6 @@ class WebpackCLI extends GroupHelper {
this.advancedGroup = new AdvancedGroup(value);
break;
}
case groups.DISPLAY_GROUP: {
const StatsGroup = require('./groups/StatsGroup');
this.statsGroup = new StatsGroup(value);
break;
}
case groups.HELP_GROUP: {
const HelpGroup = require('./groups/HelpGroup');
this.helpGroup = new HelpGroup();
Expand Down Expand Up @@ -251,7 +247,7 @@ class WebpackCLI extends GroupHelper {
.then(() => this._handleCoreFlags())
.then(() => this._handleGroupHelper(this.basicGroup))
.then(() => this._handleGroupHelper(this.advancedGroup))
.then(() => this._handleGroupHelper(this.statsGroup))
.then(() => this._baseResolver(resolveStats, parsedArgs))
.then(() => this._handleGroupHelper(this.helpGroup));
}

Expand Down

0 comments on commit 5bae797

Please sign in to comment.