From b8c31453a9226d5f3efd2e0b40f85ab92a4a5eae Mon Sep 17 00:00:00 2001 From: dhruvdutt Date: Sun, 11 Mar 2018 07:08:48 +0530 Subject: [PATCH] misc(init-generator): cleanup --- lib/generators/init-generator.js | 44 ++++++++----------- .../__snapshots__/top-scope.test.js.snap | 3 +- 2 files changed, 20 insertions(+), 27 deletions(-) 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); } diff --git a/lib/init/transformations/top-scope/__snapshots__/top-scope.test.js.snap b/lib/init/transformations/top-scope/__snapshots__/top-scope.test.js.snap index dd59a02c372..44547acf802 100644 --- a/lib/init/transformations/top-scope/__snapshots__/top-scope.test.js.snap +++ b/lib/init/transformations/top-scope/__snapshots__/top-scope.test.js.snap @@ -2,8 +2,7 @@ exports[`top-scope transforms correctly using "top-scope-0" data 1`] = ` "const test = 'me'; -module.exports = {} -" +module.exports = {}" `; exports[`top-scope transforms correctly using "top-scope-1" data 1`] = `