Skip to content

Commit

Permalink
Merge pull request #333 from dhruvdutt/minor-fixes
Browse files Browse the repository at this point in the history
misc(init-generator): cleanup
  • Loading branch information
ematipico authored Mar 11, 2018
2 parents 2c2e968 + bd8ccda commit 815b5dd
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions lib/generators/init-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;
Expand Down Expand Up @@ -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"
);
}
Expand All @@ -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",
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand All @@ -411,6 +404,7 @@ module.exports = class InitGenerator extends Generator {
});
});
}

writing() {
this.config.set("configuration", this.configuration);
}
Expand Down

0 comments on commit 815b5dd

Please sign in to comment.