diff --git a/lib/generators/init-generator.js b/lib/generators/init-generator.js index e90997b18e5..590b8a6982a 100644 --- a/lib/generators/init-generator.js +++ b/lib/generators/init-generator.js @@ -22,7 +22,7 @@ const tooltip = require("./utils/tooltip"); * * Generator for initializing a webpack config * - * @class InitGenerator + * @class InitGenerator * @extends Generator * @returns {Void} After execution, transforms are triggered * @@ -39,9 +39,10 @@ module.exports = class InitGenerator extends Generator { } }; } + prompting() { - let done = this.async(); - let self = this; + const done = this.async(); + const self = this; let oneOrMoreEntries; let regExpForStyles; let ExtractUseProps; @@ -114,26 +115,20 @@ module.exports = class InitGenerator extends Generator { Confirm("prodConfirm", "Are you going to use this in production?") ]); }) - .then(prodAnswer => { - if (prodAnswer["prodConfirm"] === true) { - this.isProd = true; - } else { - this.isProd = false; - } - }) + .then(prodConfirmAnswer => this.isProd = prodConfirmAnswer["prodConfirm"]) .then(() => { return this.prompt([ Confirm("babelConfirm", "Will you be using ES2015?") ]); }) - .then(ans => { - if (ans["babelConfirm"] === true) { + .then(babelConfirmAnswer => { + if (babelConfirmAnswer["babelConfirm"] === true) { this.configuration.config.webpackOptions.module.rules.push( getBabelPlugin() ); this.dependencies.push( - "babel-loader", "babel-core", + "babel-loader", "babel-preset-env" ); } @@ -149,11 +144,11 @@ module.exports = class InitGenerator extends Generator { ]) ]); }) - .then(stylingAnswer => { + .then(stylingTypeAnswer => { if (!this.isProd) { ExtractUseProps = []; } - switch (stylingAnswer["stylingType"]) { + switch (stylingTypeAnswer["stylingType"]) { case "SASS": this.dependencies.push( "sass-loader", @@ -335,8 +330,8 @@ module.exports = class InitGenerator extends Generator { ) ]); }) - .then(extractAnswer => { - const cssBundleName = extractAnswer.extractPlugin; + .then(extractPluginAnswer => { + const cssBundleName = extractPluginAnswer["extractPlugin"]; if (regExpForStyles) { if (this.isProd) { this.configuration.config.topScope.push(tooltip.cssPlugin()); @@ -388,21 +383,19 @@ module.exports = class InitGenerator extends Generator { done(); }); } + installPlugins() { - let asyncNamePrompt = this.async(); - let defaultName = this.isProd ? "prod" : "config"; + const asyncNamePrompt = this.async(); + const defaultName = this.isProd ? "prod" : "config"; this.prompt([ Input( "nameType", `Name your 'webpack.[name].js?' [default: '${defaultName}']:` ) ]) - .then(nameAnswer => { - if (nameAnswer["nameType"].length) { - this.configuration.config.configName = nameAnswer["nameType"]; - } else { - this.configuration.config.configName = defaultName; - } + .then(nameTypeAnswer => { + this.configuration.config.configName = nameTypeAnswer["nameType"].length ? + nameTypeAnswer["nameType"] : defaultName; }) .then(() => { asyncNamePrompt(); @@ -411,6 +404,7 @@ module.exports = class InitGenerator extends Generator { }); }); } + writing() { this.config.set("configuration", this.configuration); }