diff --git a/lib/generators/add-generator.js b/lib/generators/add-generator.js index 4dddfba5f89..48b58922587 100644 --- a/lib/generators/add-generator.js +++ b/lib/generators/add-generator.js @@ -44,6 +44,7 @@ module.exports = class AddGenerator extends Generator { this.configuration.config.webpackOptions[ actionTypeAnswer.actionType ] = null; + action = actionTypeAnswer.actionType; }) .then(() => { @@ -82,87 +83,88 @@ module.exports = class AddGenerator extends Generator { `what do you want to add to ${action}?` ); } - this.prompt([manualOrListInput]).then(answerToAction => { - if (action === ("plugins" || "loader")) { - const pluginExist = glob - .sync([ - "node_modules/webpack/lib/*Plugin.js", - "node_modules/webpack/lib/**/*Plugin.js" - ]) - .map(p => - p - .split("/") - .pop() - .replace(".js", "") - ) - .find( - p => p.toLowerCase().indexOf(answerToAction.actionAnswer) >= 0 - ); - if (pluginExist) { - this.configuration.config.item = pluginExist; - this.configuration.config.webpackOptions[ - action - ] = `new webpack.${pluginExist}`; - done(); - } else { - npmExists(answerToAction.actionAnswer).then(p => { - if (p) { - this.dependencies.push(answerToAction.actionAnswer); - const normalizePluginName = answerToAction.actionAnswer.replace( - "-webpack-plugin", - "Plugin" - ); - const pluginName = replaceAt( - normalizePluginName, - 0, - normalizePluginName.charAt(0).toUpperCase() - ); - this.configuration.config.topScope.push( - `const ${pluginName} = require("${ - answerToAction.actionAnswer - }")` - ); - this.configuration.config.webpackOptions[ - action - ] = `new ${pluginName}`; - this.configuration.config.item = answerToAction.actionAnswer; - done(); - - this.runInstall(getPackageManager(), this.dependencies, { - "save-dev": true - }); - } else { - console.error( - answerToAction.actionAnswer, - "doesn't exist on NPM or is built in webpack, please check for any misspellings." - ); - process.exit(0); - } - }); - } + return this.prompt([manualOrListInput]); + }) + .then(answerToAction => { + if (action === "plugins" || action === "loader") { + const pluginExist = glob + .sync([ + "node_modules/webpack/lib/*Plugin.js", + "node_modules/webpack/lib/**/*Plugin.js" + ]) + .map(p => + p + .split("/") + .pop() + .replace(".js", "") + ) + .find( + p => p.toLowerCase().indexOf(answerToAction.actionAnswer) >= 0 + ); + if (pluginExist) { + this.configuration.config.item = pluginExist; + this.configuration.config.webpackOptions[ + action + ] = `new webpack.${pluginExist}`; + done(); } else { - if (isDeepProp[0]) { - isDeepProp[1] = answerToAction.actionAnswer; - this.prompt([ - Input( - "deepProp", - `what do you want the value of ${isDeepProp[1]} to be?` - ) - ]).then(deepPropAns => { - this.configuration.config.item = action + "." + isDeepProp[1]; - this.configuration.config.webpackOptions[action] = { - [isDeepProp[1]]: `'${deepPropAns.deepProp}'` - }; + npmExists(answerToAction.actionAnswer).then(p => { + if (p) { + this.dependencies.push(answerToAction.actionAnswer); + const normalizePluginName = answerToAction.actionAnswer.replace( + "-webpack-plugin", + "Plugin" + ); + const pluginName = replaceAt( + normalizePluginName, + 0, + normalizePluginName.charAt(0).toUpperCase() + ); + this.configuration.config.topScope.push( + `const ${pluginName} = require("${ + answerToAction.actionAnswer + }")` + ); + this.configuration.config.webpackOptions[ + action + ] = `new ${pluginName}`; + this.configuration.config.item = answerToAction.actionAnswer; done(); - }); - } else { - this.configuration.config.item = action; - this.configuration.config.webpackOptions[action] = - answerToAction.actionAnswer; + + this.runInstall(getPackageManager(), this.dependencies, { + "save-dev": true + }); + } else { + console.error( + answerToAction.actionAnswer, + "doesn't exist on NPM or is built in webpack, please check for any misspellings." + ); + process.exit(0); + } + }); + } + } else { + if (isDeepProp[0]) { + isDeepProp[1] = answerToAction.actionAnswer; + this.prompt([ + Input( + "deepProp", + `what do you want the value of ${isDeepProp[1]} to be?` + ) + ]).then(deepPropAns => { + this.configuration.config.item = action + "." + isDeepProp[1]; + this.configuration.config.webpackOptions[action] = { + [isDeepProp[1]]: `'${deepPropAns.deepProp}'` + }; done(); - } + }); + } else { + this.configuration.config.item = action; + this.configuration.config.webpackOptions[action] = + answerToAction.actionAnswer; + done(); } - }); + } }); } };