Skip to content

Commit b8c3145

Browse files
committed
misc(init-generator): cleanup
1 parent 2c2e968 commit b8c3145

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

lib/generators/init-generator.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const tooltip = require("./utils/tooltip");
2222
*
2323
* Generator for initializing a webpack config
2424
*
25-
* @class InitGenerator
25+
* @class InitGenerator
2626
* @extends Generator
2727
* @returns {Void} After execution, transforms are triggered
2828
*
@@ -39,9 +39,10 @@ module.exports = class InitGenerator extends Generator {
3939
}
4040
};
4141
}
42+
4243
prompting() {
43-
let done = this.async();
44-
let self = this;
44+
const done = this.async();
45+
const self = this;
4546
let oneOrMoreEntries;
4647
let regExpForStyles;
4748
let ExtractUseProps;
@@ -114,26 +115,20 @@ module.exports = class InitGenerator extends Generator {
114115
Confirm("prodConfirm", "Are you going to use this in production?")
115116
]);
116117
})
117-
.then(prodAnswer => {
118-
if (prodAnswer["prodConfirm"] === true) {
119-
this.isProd = true;
120-
} else {
121-
this.isProd = false;
122-
}
123-
})
118+
.then(prodConfirmAnswer => this.isProd = prodConfirmAnswer["prodConfirm"])
124119
.then(() => {
125120
return this.prompt([
126121
Confirm("babelConfirm", "Will you be using ES2015?")
127122
]);
128123
})
129-
.then(ans => {
130-
if (ans["babelConfirm"] === true) {
124+
.then(babelConfirmAnswer => {
125+
if (babelConfirmAnswer["babelConfirm"] === true) {
131126
this.configuration.config.webpackOptions.module.rules.push(
132127
getBabelPlugin()
133128
);
134129
this.dependencies.push(
135-
"babel-loader",
136130
"babel-core",
131+
"babel-loader",
137132
"babel-preset-env"
138133
);
139134
}
@@ -149,11 +144,11 @@ module.exports = class InitGenerator extends Generator {
149144
])
150145
]);
151146
})
152-
.then(stylingAnswer => {
147+
.then(stylingTypeAnswer => {
153148
if (!this.isProd) {
154149
ExtractUseProps = [];
155150
}
156-
switch (stylingAnswer["stylingType"]) {
151+
switch (stylingTypeAnswer["stylingType"]) {
157152
case "SASS":
158153
this.dependencies.push(
159154
"sass-loader",
@@ -335,8 +330,8 @@ module.exports = class InitGenerator extends Generator {
335330
)
336331
]);
337332
})
338-
.then(extractAnswer => {
339-
const cssBundleName = extractAnswer.extractPlugin;
333+
.then(extractPluginAnswer => {
334+
const cssBundleName = extractPluginAnswer["extractPlugin"];
340335
if (regExpForStyles) {
341336
if (this.isProd) {
342337
this.configuration.config.topScope.push(tooltip.cssPlugin());
@@ -388,21 +383,19 @@ module.exports = class InitGenerator extends Generator {
388383
done();
389384
});
390385
}
386+
391387
installPlugins() {
392-
let asyncNamePrompt = this.async();
393-
let defaultName = this.isProd ? "prod" : "config";
388+
const asyncNamePrompt = this.async();
389+
const defaultName = this.isProd ? "prod" : "config";
394390
this.prompt([
395391
Input(
396392
"nameType",
397393
`Name your 'webpack.[name].js?' [default: '${defaultName}']:`
398394
)
399395
])
400-
.then(nameAnswer => {
401-
if (nameAnswer["nameType"].length) {
402-
this.configuration.config.configName = nameAnswer["nameType"];
403-
} else {
404-
this.configuration.config.configName = defaultName;
405-
}
396+
.then(nameTypeAnswer => {
397+
this.configuration.config.configName = nameTypeAnswer["nameType"].length ?
398+
nameTypeAnswer["nameType"] : defaultName;
406399
})
407400
.then(() => {
408401
asyncNamePrompt();
@@ -411,6 +404,7 @@ module.exports = class InitGenerator extends Generator {
411404
});
412405
});
413406
}
407+
414408
writing() {
415409
this.config.set("configuration", this.configuration);
416410
}

lib/init/transformations/top-scope/__snapshots__/top-scope.test.js.snap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
exports[`top-scope transforms correctly using "top-scope-0" data 1`] = `
44
"const test = 'me';
5-
module.exports = {}
6-
"
5+
module.exports = {}"
76
`;
87

98
exports[`top-scope transforms correctly using "top-scope-1" data 1`] = `

0 commit comments

Comments
 (0)