diff --git a/generators/app/index.js b/generators/app/index.js index 0bcf2cb..d45cb4d 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -104,6 +104,14 @@ class AppGenerator extends Generators.Base { } } + // Add cssmodules if enabled + const cssmoduleConfig = utils.config.getChoiceByKey('cssmodules', 'cssmodules'); + if(this.cssmodules && cssmoduleConfig && cssmoduleConfig.packages) { + for(let dependency of cssmoduleConfig.packages) { + packageSettings.dependencies[dependency.name] = dependency.version; + } + } + this.fs.writeJSON(this.destinationPath('package.json'), packageSettings); } diff --git a/test/generators/app/indexTest.js b/test/generators/app/indexTest.js index 7cc4782..6408781 100644 --- a/test/generators/app/indexTest.js +++ b/test/generators/app/indexTest.js @@ -23,8 +23,7 @@ const beforeLoad = (prompts) => { 'skip-welcome-message': true, 'skip-install': true }) - .withPrompts - (prompts) + .withPrompts(prompts) .on('ready', function(instance) { generator = instance; }) @@ -61,6 +60,12 @@ describe('react-webpack:app', () => { }); }); + describe('configuring', () => { + it('should add css module support', () => { + assert.fileContent('package.json', 'react-css-modules'); + }); + }); + describe('#createFiles', () => { it('should generate dot files', () => { @@ -120,6 +125,44 @@ describe('react-webpack:app', () => { }); }); +describe('react-webpack:app without cssmodules support', () => { + + let prompts = {}; + for(let p of defaultPrompts) { + prompts[p.name] = p.default; + } + prompts.cssmodules = false; + + before(() => { + return beforeLoad(prompts); + }); + + describe('#config', () => { + + it('should set the generatedWith key to the current generator major version', () => { + expect(generator.config.get('generatedWithVersion')).to.equal(4); + }); + + it('should use "css" as default style language', () => { + expect(generator.config.get('style')).to.equal('css'); + }); + + it('should not use "css modules"', () => { + expect(generator.config.get('cssmodules')).to.be.false; + }); + + it('should not enable "PostCSS" by default', () => { + expect(generator.config.get('postcss')).to.be.false; + }); + }); + + describe('configuring', () => { + it('should add no cssmodule support', () => { + assert.noFileContent('package.json', 'react-css-modules'); + }); + }); +}); + describe('react-webpack:app with PostCSS support', () => { let prompts = {}; diff --git a/utils/configopts.json b/utils/configopts.json index 67c9b64..0c7e26b 100644 --- a/utils/configopts.json +++ b/utils/configopts.json @@ -51,6 +51,17 @@ } ] }, + "cssmodules": { + "options": [ + { + "name": "cssmodules", + "value": "cssmodules", + "packages": [ + { "name": "react-css-modules", "version": "^3.7.10" } + ] + } + ] + }, "style": { "options": [ {