Skip to content

Commit b581e5b

Browse files
committed
Added support for cssmodules when setting up projects. closes #265
1 parent 90f516c commit b581e5b

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

generators/app/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ class AppGenerator extends Generators.Base {
104104
}
105105
}
106106

107+
// Add cssmodules if enabled
108+
const cssmoduleConfig = utils.config.getChoiceByKey('cssmodules', 'cssmodules');
109+
if(this.cssmodules && cssmoduleConfig && cssmoduleConfig.packages) {
110+
for(let dependency of cssmoduleConfig.packages) {
111+
packageSettings.dependencies[dependency.name] = dependency.version;
112+
}
113+
}
114+
107115
this.fs.writeJSON(this.destinationPath('package.json'), packageSettings);
108116
}
109117

test/generators/app/indexTest.js

+45-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ const beforeLoad = (prompts) => {
2323
'skip-welcome-message': true,
2424
'skip-install': true
2525
})
26-
.withPrompts
27-
(prompts)
26+
.withPrompts(prompts)
2827
.on('ready', function(instance) {
2928
generator = instance;
3029
})
@@ -61,6 +60,12 @@ describe('react-webpack:app', () => {
6160
});
6261
});
6362

63+
describe('configuring', () => {
64+
it('should add css module support', () => {
65+
assert.fileContent('package.json', 'react-css-modules');
66+
});
67+
});
68+
6469
describe('#createFiles', () => {
6570

6671
it('should generate dot files', () => {
@@ -120,6 +125,44 @@ describe('react-webpack:app', () => {
120125
});
121126
});
122127

128+
describe('react-webpack:app without cssmodules support', () => {
129+
130+
let prompts = {};
131+
for(let p of defaultPrompts) {
132+
prompts[p.name] = p.default;
133+
}
134+
prompts.cssmodules = false;
135+
136+
before(() => {
137+
return beforeLoad(prompts);
138+
});
139+
140+
describe('#config', () => {
141+
142+
it('should set the generatedWith key to the current generator major version', () => {
143+
expect(generator.config.get('generatedWithVersion')).to.equal(4);
144+
});
145+
146+
it('should use "css" as default style language', () => {
147+
expect(generator.config.get('style')).to.equal('css');
148+
});
149+
150+
it('should not use "css modules"', () => {
151+
expect(generator.config.get('cssmodules')).to.be.false;
152+
});
153+
154+
it('should not enable "PostCSS" by default', () => {
155+
expect(generator.config.get('postcss')).to.be.false;
156+
});
157+
});
158+
159+
describe('configuring', () => {
160+
it('should add no cssmodule support', () => {
161+
assert.noFileContent('package.json', 'react-css-modules');
162+
});
163+
});
164+
});
165+
123166
describe('react-webpack:app with PostCSS support', () => {
124167

125168
let prompts = {};

utils/configopts.json

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@
5151
}
5252
]
5353
},
54+
"cssmodules": {
55+
"options": [
56+
{
57+
"name": "cssmodules",
58+
"value": "cssmodules",
59+
"packages": [
60+
{ "name": "react-css-modules", "version": "^3.7.10" }
61+
]
62+
}
63+
]
64+
},
5465
"style": {
5566
"options": [
5667
{

0 commit comments

Comments
 (0)