Skip to content
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
156 changes: 79 additions & 77 deletions lib/generators/add-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = class AddGenerator extends Generator {
this.configuration.config.webpackOptions[
actionTypeAnswer.actionType
] = null;

action = actionTypeAnswer.actionType;
})
.then(() => {
Expand Down Expand Up @@ -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();
}
});
}
});
}
};
Expand Down