Skip to content

Commit

Permalink
misc(init-generator): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvdutt committed Mar 11, 2018
1 parent 2c2e968 commit b8c3145
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 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
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
Expand Down

0 comments on commit b8c3145

Please sign in to comment.