Skip to content
This repository was archived by the owner on Oct 16, 2021. It is now read-only.

Commit 68f31d8

Browse files
committed
feat(baumeister): Move tooling configs to package.json
This way we can get rid of the following files: ``` /.babelrc /.eslintrc.json /.prettierrc /.stylelintrc.json /baumeister.json ``` It’s a trend that tools make it possible to store their settings in a field in the `package.json`. I recently enabled Baumeister to handle his configuration this way. See [#270 – feat: enable to define baumeister config in package.json](micromata/Baumeister#270). I’d like the approach, because the project root is less cluttered with dotfiles and you can see all the configs in one place.
1 parent fcfdc6c commit 68f31d8

File tree

8 files changed

+217
-209
lines changed

8 files changed

+217
-209
lines changed

__tests__/test-app.js

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,28 @@ describe('Baumeister with default options', () => {
8484
]);
8585
});
8686

87-
it('should have `useHandlebars` set to `true` in baumeister.json', () => {
88-
assert.fileContent('baumeister.json', /"useHandlebars": true,/);
87+
it('should have `useHandlebars` set to `true` in Baumeister settings', () => {
88+
const packageJson = JSON.parse(fs.readFileSync('package.json'));
89+
packageJson.should.have
90+
.propertyByPath('baumeister', 'useHandlebars')
91+
.eql(true);
8992
});
9093

91-
it('should have `generateBanners` set to `false` in baumeister.json', () => {
92-
assert.fileContent('baumeister.json', /"generateBanners": false,/);
94+
it('should have `generateBanners` set to `false` in Baumeister settings', () => {
95+
const packageJson = JSON.parse(fs.readFileSync('package.json'));
96+
packageJson.should.have
97+
.propertyByPath('baumeister', 'generateBanners')
98+
.eql(false);
9399
});
94100

95-
it('should have the default ProvidePlugin settings in baumeister.json', () => {
96-
assert.fileContent([
97-
['baumeister.json', /"ProvidePlugin": {\n/],
98-
['baumeister.json', /"\$": "jquery",/],
99-
['baumeister.json', /"jQuery": "jquery"/]
100-
]);
101+
it('should have the default ProvidePlugin settings in Baumeister settings', () => {
102+
const packageJson = JSON.parse(fs.readFileSync('package.json'));
103+
packageJson.should.have
104+
.propertyByPath('baumeister', 'webpack', 'ProvidePlugin')
105+
.eql({
106+
$: 'jquery',
107+
jQuery: 'jquery'
108+
});
101109
});
102110

103111
it('should create package manager files', () => {
@@ -113,26 +121,22 @@ describe('Baumeister with default options', () => {
113121
'.editorconfig',
114122
'.gitattributes',
115123
'.gitignore',
116-
'.babelrc',
117-
'src/app/.babelrc',
118-
'.travis.yml',
119-
'.eslintrc.json',
120-
'.stylelintrc.json'
124+
'.travis.yml'
121125
]);
122126
});
123127

124-
it('should not have React related plugins in .babelrc', () => {
128+
it('should not have React related plugins in Babel settings', () => {
125129
assert.noFileContent([
126-
['src/app/.babelrc', /plugin-proposal-class-properties/],
127-
['src/app/.babelrc', /plugin-transform-react-jsx/]
130+
['package.json', /plugin-proposal-class-properties/],
131+
['package.json', /plugin-transform-react-jsx/]
128132
]);
129133
});
130134

131-
it('should not have React related settings in .eslintrc', () => {
135+
it('should not have React related settings in ESLint config', () => {
132136
assert.noFileContent([
133-
['.eslintrc.json', /"plugin:react\/recommended"/],
134-
['.eslintrc.json', /"plugins": \["react"],/],
135-
['.eslintrc.json', /"ecmaFeatures": {"jsx": true}/]
137+
['package.json', /"plugin:react\/recommended"/],
138+
['package.json', /"plugins": \["react"],/],
139+
['package.json', /"ecmaFeatures": {"jsx": true}/]
136140
]);
137141
});
138142

@@ -163,7 +167,6 @@ describe('Baumeister with default options', () => {
163167
it('should create other project files', () => {
164168
assert.file([
165169
'README.md',
166-
'baumeister.json',
167170
'postcss.config.js',
168171
'humans.txt',
169172
'LICENSE',
@@ -257,11 +260,10 @@ describe('Baumeister with default options', () => {
257260
});
258261

259262
it('should not have React and related dependencies', () => {
260-
assert.noFileContent([
261-
['package.json', /react/],
262-
['package.json', /react-dom/],
263-
['package.json', /prop-types/]
264-
]);
263+
const packageJson = JSON.parse(fs.readFileSync('package.json'));
264+
packageJson.should.not.have.propertyByPath('dependencies', 'react');
265+
packageJson.should.not.have.propertyByPath('dependencies', 'react-dom');
266+
packageJson.should.not.have.propertyByPath('dependencies', 'prop-types');
265267
});
266268

267269
it('should not have React related dev dependencies', () => {
@@ -331,7 +333,7 @@ describe('Baumeister with default options', () => {
331333

332334
it('should have the current year within the LICENSE', () => {
333335
const regex = new RegExp(
334-
escapeStringRegexp(new Date().getFullYear() + ''),
336+
escapeStringRegexp(String(new Date().getFullYear())),
335337
''
336338
); // eslint-disable-line no-implicit-coercion
337339
assert.fileContent('LICENSE', regex);
@@ -417,11 +419,14 @@ describe('Baumeister generating a single page app', () => {
417419
);
418420
});
419421

420-
it('should have adapted settings in baumeister.json', () => {
421-
assert.fileContent([
422-
['baumeister.json', /"useHandlebars": false,/],
423-
['baumeister.json', /"ProvidePlugin": {}/]
424-
]);
422+
it('should have adapted settings in Baumeister settings', () => {
423+
const packageJson = JSON.parse(fs.readFileSync('package.json'));
424+
packageJson.should.have
425+
.propertyByPath('baumeister', 'useHandlebars')
426+
.eql(false);
427+
packageJson.should.have
428+
.propertyByPath('baumeister', 'webpack', 'ProvidePlugin')
429+
.eql({});
425430
});
426431

427432
it('should create no Handlebars related files', () => {
@@ -470,18 +475,18 @@ describe('Baumeister generating a single page app', () => {
470475
});
471476
});
472477

473-
it('should have React related plugins in .babelrc', () => {
478+
it('should have React related plugins in Babel settings', () => {
474479
assert.fileContent([
475-
['src/app/.babelrc', /plugin-proposal-class-properties/],
476-
['src/app/.babelrc', /plugin-transform-react-jsx/]
480+
['package.json', /plugin-proposal-class-properties/],
481+
['package.json', /plugin-transform-react-jsx/]
477482
]);
478483
});
479484

480-
it('should have React related settings in .eslintrc', () => {
485+
it('should have React related settings in ESLint config', () => {
481486
assert.fileContent([
482-
['.eslintrc.json', /"plugin:react\/recommended"/],
483-
['.eslintrc.json', /"plugins": \["react"],/],
484-
['.eslintrc.json', /"ecmaFeatures": {"jsx": true}/]
487+
['package.json', /"plugin:react\/recommended"/],
488+
['package.json', /"plugins": \["react"],/],
489+
['package.json', /"ecmaFeatures": { "jsx": true }/]
485490
]);
486491
});
487492

@@ -541,8 +546,11 @@ describe('Baumeister with banner', () => {
541546
);
542547
});
543548

544-
it('should have `generateBanners` set to `true` in baumeister.json', () => {
545-
assert.fileContent('baumeister.json', /"generateBanners": true,/);
549+
it('should have `generateBanners` set to `true` in Baumeister settings', () => {
550+
const packageJson = JSON.parse(fs.readFileSync('package.json'));
551+
packageJson.should.have
552+
.propertyByPath('baumeister', 'generateBanners')
553+
.eql(true);
546554
});
547555
});
548556

@@ -598,7 +606,7 @@ describe('Baumeister without an open source license', () => {
598606

599607
it('should have the current year within the LICENSE', () => {
600608
const regex = new RegExp(
601-
escapeStringRegexp(new Date().getFullYear() + ''),
609+
escapeStringRegexp(String(new Date().getFullYear())),
602610
''
603611
); // eslint-disable-line no-implicit-coercion
604612
assert.fileContent('LICENSE', regex);
@@ -674,7 +682,7 @@ describe('Baumeister with Apache License, Version 2.0', () => {
674682

675683
it('should have the current year within the LICENSE', () => {
676684
const regex = new RegExp(
677-
escapeStringRegexp(new Date().getFullYear() + ''),
685+
escapeStringRegexp(String(new Date().getFullYear())),
678686
''
679687
); // eslint-disable-line no-implicit-coercion
680688
assert.fileContent('LICENSE', regex);
@@ -747,7 +755,7 @@ describe('Baumeister with GNU General Public License', () => {
747755

748756
it('should have the current year within the LICENSE', () => {
749757
const regex = new RegExp(
750-
escapeStringRegexp(new Date().getFullYear() + ''),
758+
escapeStringRegexp(String(new Date().getFullYear())),
751759
''
752760
); // eslint-disable-line no-implicit-coercion
753761
assert.fileContent('LICENSE', regex);
@@ -1013,12 +1021,7 @@ describe('Baumeister using --yo-rc flag', () => {
10131021
});
10141022

10151023
it('should create dot files', () => {
1016-
assert.file([
1017-
'.editorconfig',
1018-
'.gitattributes',
1019-
'.gitignore',
1020-
'.eslintrc.json'
1021-
]);
1024+
assert.file(['.editorconfig', '.gitattributes', '.gitignore']);
10221025
});
10231026

10241027
it('should have `/dist` directory in .gitignore', () => {
@@ -1183,7 +1186,7 @@ describe('Baumeister using --yo-rc flag', () => {
11831186

11841187
it('should have the current year within the LICENSE', () => {
11851188
const regex = new RegExp(
1186-
escapeStringRegexp(new Date().getFullYear() + ''),
1189+
escapeStringRegexp(String(new Date().getFullYear())),
11871190
''
11881191
); // eslint-disable-line no-implicit-coercion
11891192
assert.fileContent('LICENSE', regex);

app/index.js

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,6 @@ module.exports = class extends Generator {
334334
);
335335

336336
// Dotfiles
337-
this.fs.copyTpl(
338-
this.templatePath('babelrc'),
339-
this.destinationPath('.babelrc')
340-
);
341-
this.fs.copyTpl(
342-
this.templatePath('src/app/_babelrc'),
343-
this.destinationPath('src/app/.babelrc'),
344-
{
345-
templateProps: this.templateProps
346-
}
347-
);
348337
this.fs.copyTpl(
349338
this.templatePath('travis.yml'),
350339
this.destinationPath('.travis.yml')
@@ -353,17 +342,6 @@ module.exports = class extends Generator {
353342
this.templatePath('editorconfig'),
354343
this.destinationPath('.editorconfig')
355344
);
356-
this.fs.copyTpl(
357-
this.templatePath('_eslintrc.json'),
358-
this.destinationPath('.eslintrc.json'),
359-
{
360-
templateProps: this.templateProps
361-
}
362-
);
363-
this.fs.copyTpl(
364-
this.templatePath('stylelintrc.json'),
365-
this.destinationPath('.stylelintrc.json')
366-
);
367345
this.fs.copyTpl(
368346
this.templatePath('gitattributes'),
369347
this.destinationPath('.gitattributes')
@@ -490,13 +468,6 @@ module.exports = class extends Generator {
490468
}
491469

492470
// Config files
493-
this.fs.copyTpl(
494-
this.templatePath('_baumeister.json'),
495-
this.destinationPath('baumeister.json'),
496-
{
497-
templateProps: this.templateProps
498-
}
499-
);
500471
this.fs.copyTpl(
501472
this.templatePath('postcss.config.js'),
502473
this.destinationPath('postcss.config.js')

app/templates/_baumeister.json

Lines changed: 0 additions & 38 deletions
This file was deleted.

app/templates/_eslintrc.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)