Skip to content

Commit 641064a

Browse files
committed
chore: wip
chore: make the code more consise
1 parent e233ed6 commit 641064a

File tree

2 files changed

+8
-33
lines changed

2 files changed

+8
-33
lines changed

lib/groups/basic.js

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,23 @@ class BasicGroup extends GroupHelper {
44
constructor(options) {
55
super(options);
66
this.WEBPACK_OPTION_FLAGS = ['prod', 'dev', 'watch', 'w', 'prod', 'p', 'interactive', 'i'];
7-
this.resolveFlags();
87
}
98
resolveFlags() {
109
const { args } = this;
1110

12-
const old_args = Object.keys(args);
13-
const newArgs = old_args
14-
.map(arg => {
15-
if (arg === 'entry') {
16-
const isCJS = args[arg] === null;
17-
if (isCJS) {
18-
args['dev'] = true;
19-
args['prod'] = false;
20-
} else {
21-
args['prod'] = true;
22-
args['dev'] = false;
23-
}
24-
}
25-
if (arg === 'interactive') {
26-
args['interactive'] = true;
27-
}
28-
return arg;
29-
})
30-
.filter(e => e);
31-
32-
newArgs.forEach(arg => {
11+
Object.keys(args).forEach(arg => {
3312
if (this.WEBPACK_OPTION_FLAGS.includes(arg)) {
34-
this.opts.outputOptions[arg] = this.resolveWebpackOptions(arg, args[arg]);
13+
this.opts.outputOptions[arg] = args[arg];
3514
}
3615
if (arg == 'analyze') {
3716
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
3817
this.opts.options.plugins = [new BundleAnalyzerPlugin()];
3918
}
4019
if (arg == 'sourcemap') {
41-
this.opts.options.devtool = args[arg] || 'eval';
20+
this.opts.options.devtool = args[arg];
4221
}
4322
if (arg == 'entry') {
44-
if (args[arg] === 'help') {
45-
return;
46-
}
23+
args[arg] = args[arg] || '';
4724
this.opts.options[arg] = this.resolveFilePath(args[arg], 'index');
4825
}
4926
});
@@ -52,10 +29,8 @@ class BasicGroup extends GroupHelper {
5229
}
5330
}
5431

55-
resolveWebpackOptions(key, val) {
56-
return val;
57-
}
5832
run() {
33+
this.resolveFlags();
5934
return this.opts;
6035
}
6136
}

lib/utils/group-helper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class GroupHelper {
111111
options.plugins.unshift(plugin);
112112
}
113113

114-
resolveFilePath(filename = null, defaultValue) {
114+
resolveFilePath(filename='', defaultValue) {
115115
if (filename && Array.isArray(filename)) {
116116
return filename.map(fp => this.resolveFilePath(fp, defaultValue)).filter(e => e);
117117
}
@@ -122,8 +122,8 @@ class GroupHelper {
122122
defaultValue = defaultValue + '.js';
123123
}
124124
let configPath;
125-
const predefinedConfigPath = filename ? resolve(process.cwd(), filename) : null;
126-
const configPathExists = predefinedConfigPath ? existsSync(predefinedConfigPath) : false;
125+
const predefinedConfigPath = filename ? resolve(process.cwd(), filename) : undefined;
126+
const configPathExists = predefinedConfigPath ? existsSync(predefinedConfigPath) : undefined;
127127

128128
if (!configPathExists) {
129129
let LOOKUP_PATHS = [`${filename}`, `src/${filename}`, defaultValue, `src/${defaultValue}`];

0 commit comments

Comments
 (0)