Skip to content

Commit

Permalink
cli(init): mode support to config (#364)
Browse files Browse the repository at this point in the history
* cli(init): mode support to config
  • Loading branch information
dhruvdutt authored and ematipico committed Apr 9, 2018
1 parent cc217cb commit c487032
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/generators/init-generator.js
Expand Up @@ -115,9 +115,11 @@ module.exports = class InitGenerator extends Generator {
Confirm("prodConfirm", "Are you going to use this in production?")
]);
})
.then(
prodConfirmAnswer => (this.isProd = prodConfirmAnswer["prodConfirm"])
)
.then(prodConfirmAnswer => {
this.isProd = prodConfirmAnswer["prodConfirm"];
this.configuration.config.webpackOptions.mode =
this.isProd ? `"${"production"}"` : `"${"development"}"`;
})
.then(() => {
return this.prompt([
Confirm("babelConfirm", "Will you be using ES2015?")
Expand Down
14 changes: 14 additions & 0 deletions lib/init/transformations/mode/__snapshots__/mode.test.js.snap
Expand Up @@ -8,6 +8,13 @@ exports[`mode transforms correctly using "mode-1" data 1`] = `
`;

exports[`mode transforms correctly using "mode-1" data 2`] = `
"module.exports = {
mode: 'development'
};
"
`;

exports[`mode transforms correctly using "mode-1" data 3`] = `
"module.exports = {
mode: modeVariable
};
Expand All @@ -27,3 +34,10 @@ exports[`mode transforms correctly using "mode-2" data 2`] = `
}
"
`;

exports[`mode transforms correctly using "mode-2" data 3`] = `
"module.exports = {
mode: 'development'
}
"
`;
2 changes: 2 additions & 0 deletions lib/init/transformations/mode/mode.test.js
Expand Up @@ -3,7 +3,9 @@
const defineTest = require("../../../utils/defineTest");

defineTest(__dirname, "mode", "mode-1", "'production'", "init");
defineTest(__dirname, "mode", "mode-1", "'development'", "init");
defineTest(__dirname, "mode", "mode-1", "modeVariable", "init");

defineTest(__dirname, "mode", "mode-2", "none", "add");
defineTest(__dirname, "mode", "mode-2", "'production'", "add");
defineTest(__dirname, "mode", "mode-2", "'development'", "add");

0 comments on commit c487032

Please sign in to comment.