Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc(init-generator): cleanup #333

Merged
merged 2 commits into from
Mar 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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