Skip to content

Commit ff43094

Browse files
authored
Merge pull request #37 from fs-webdev/eslint
added eslint-config-frontier:recommended to the templates, as well as…
2 parents c471f42 + 91a29e7 commit ff43094

File tree

10 files changed

+53
-75
lines changed

10 files changed

+53
-75
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
},
4646
"lint-staged": {
4747
"*.{js,md,css,html}": [
48-
"prettier --trailing-comma es5 --single-quote --write",
48+
"prettier --print-width 100 es5 --single-quote --write",
4949
"git add"
5050
],
5151
"yarn.lock": [

packages/react-scripts/config/webpack.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,13 @@ module.exports = function(webpackEnv) {
313313
eslintPath: require.resolve('eslint'),
314314
// @remove-on-eject-begin
315315
baseConfig: {
316-
extends: [require.resolve('eslint-config-react-app')],
316+
extends: [
317+
//in order to keep backwards compatability for people currently using eslint-config-frontier
318+
//with their old polymer projects, we have to point to the recommended file instead of index.js
319+
require
320+
.resolve('eslint-config-frontier')
321+
.replace('index.js', 'recommended.js'),
322+
],
317323
settings: { react: { version: '999.999.999' } },
318324
},
319325
ignore: false,

packages/react-scripts/gitTagForkedStyle.js

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

packages/react-scripts/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
"engines": {
99
"node": ">=6"
1010
},
11-
"scripts": {
12-
"postversion": "node gitTagForkedStyle.js"
13-
},
1411
"bugs": {
1512
"url": "https://github.com/fs-webdev/create-react-app/issues"
1613
},

packages/react-scripts/scripts/utils/frontierInit.js

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ function installFrontierDependencies(appPath, answers, useYarn, ownPath) {
4545
if (additionalFeatures.includes('polymer')) {
4646
configurePolymer(appPath, useYarn);
4747
}
48-
if (additionalFeatures.includes('redux')) {
49-
configureRedux(appPath, useYarn, ownPath);
50-
}
5148
if (additionalFeatures.includes('electric-flow')) {
5249
configureEF(appPath, useYarn, ownPath);
5350
}
@@ -60,59 +57,59 @@ function installFrontierDependencies(appPath, answers, useYarn, ownPath) {
6057
];
6158

6259
const defaultDevModules = [
60+
'eslint@5.6.0',
61+
'fs-webdev/eslint-config-frontier#settingUpRecommendedReactConfig',
6362
'react-styleguidist@9.0.0-beta4',
6463
'webpack@4.19.1',
6564
];
6665

6766
installModulesSync(defaultModules, useYarn);
6867
installModulesSync(defaultDevModules, useYarn, true);
69-
addStyleguidistScriptsToPackageJson(appPath);
70-
}
7168

72-
function addStyleguidistScriptsToPackageJson(appPath) {
73-
//we read the package.json using fs instead of require() because require() uses the
74-
//cached result from earlier, even though the package.json has been updated previously.
75-
const appPackage = JSON.parse(
69+
alterPackageJsonFile(appPath, appPackage => {
70+
const packageJson = { ...appPackage };
71+
const additionalScripts = {
72+
styleguide: 'styleguidist server --open',
73+
'styleguide:build': 'styleguidist build',
74+
lint: 'eslint src/',
75+
'lint:fix': 'eslint src/ --fix',
76+
};
77+
packageJson.scripts = { ...packageJson.scripts, ...additionalScripts };
78+
packageJson.eslintConfig = {
79+
extends: ['frontier/recommended'],
80+
};
81+
return packageJson;
82+
});
83+
}
84+
function alterPackageJsonFile(appPath, extendFunction) {
85+
let appPackage = JSON.parse(
7686
fs.readFileSync(path.join(appPath, 'package.json'), 'UTF8')
7787
);
78-
79-
appPackage.scripts.styleguide = 'styleguidist server --open';
80-
appPackage.scripts['styleguide:build'] = 'styleguidist build';
81-
88+
appPackage = extendFunction(appPackage);
8289
fs.writeFileSync(
8390
path.join(appPath, 'package.json'),
8491
JSON.stringify(appPackage, null, 2) + os.EOL
8592
);
8693
}
8794

8895
function configurePolymer(appPath, useYarn) {
89-
//we read the package.json using fs instead of require() because require() uses the
90-
//cached result from earlier, even though the package.json has been updated previously.
91-
const appPackage = JSON.parse(
92-
fs.readFileSync(path.join(appPath, 'package.json'), 'UTF8')
93-
);
94-
appPackage.vendorCopy = [
95-
{
96-
from:
97-
'node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js',
98-
to: 'public/vendor/custom-elements-es5-adapter.js',
99-
},
100-
{
101-
from:
102-
'node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js',
103-
to: 'public/vendor/webcomponents-bundle.js',
104-
},
105-
];
106-
107-
const { postinstall } = appPackage.scripts;
108-
appPackage.scripts.postinstall = postinstall
109-
? `${postinstall} && `
110-
: '' + 'vendor-copy';
111-
112-
fs.writeFileSync(
113-
path.join(appPath, 'package.json'),
114-
JSON.stringify(appPackage, null, 2) + os.EOL
115-
);
96+
alterPackageJsonFile(appPath, appPackage => {
97+
const packageJson = { ...appPackage };
98+
packageJson.vendorCopy = [
99+
{
100+
from:
101+
'node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js',
102+
to: 'public/vendor/custom-elements-es5-adapter.js',
103+
},
104+
{
105+
from:
106+
'node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js',
107+
to: 'public/vendor/webcomponents-bundle.js',
108+
},
109+
];
110+
packageJson.scripts.postinstall = 'vendor-copy';
111+
return packageJson;
112+
});
116113

117114
const polymerModules = [
118115
'vendor-copy@2.0.0',
@@ -137,19 +134,6 @@ function injectPolymerCode(appPath) {
137134
fs.writeFileSync(indexPath, indexHtml);
138135
}
139136

140-
function configureRedux(appPath, useYarn, ownPath) {
141-
const reduxModules = [
142-
'redux@4.0.0',
143-
'react-redux@5.0.7',
144-
'redux-logger@3.0.6',
145-
'redux-thunk@2.3.0',
146-
];
147-
installModulesSync(reduxModules, useYarn);
148-
149-
const templatePath = path.join(ownPath, 'template-redux');
150-
fs.copySync(templatePath, appPath, { overwrite: true });
151-
}
152-
153137
function configureEF(appPath, useYarn, ownPath) {
154138
// TODO - modify package.json to make sure name is correct for blueprint
155139
// TODO - use blueprint.yml as a template
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#dont worry about using newer versions of libraries than react-scripts
2+
SKIP_PREFLIGHT_CHECK=true

packages/react-scripts/template/src/components/App.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import React, { Component } from 'react';
1+
import React from 'react';
22
import logo from './logo.svg';
33
import styles from './App.module.css';
44

5-
class App extends Component {
6-
render() {
5+
function App() {
76
return (
87
<div className={styles.app}>
98
<header className={styles.appHeader}>
@@ -22,7 +21,6 @@ class App extends Component {
2221
</header>
2322
</div>
2423
);
25-
}
2624
}
2725

2826
export default App;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import App from './App';
22

3-
export { App };
3+
export default App;

packages/react-scripts/template/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import './index.css';
44
import App from './components/App';
55
import * as serviceWorker from './serviceWorker';
66

7+
// eslint-disable-next-line react/jsx-filename-extension
78
ReactDOM.render(<App />, document.getElementById('root'));
89

910
// If you want your app to work offline and load faster, you can change

packages/react-scripts/template/src/serviceWorker.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ const isLocalhost = Boolean(
1515
// [::1] is the IPv6 localhost address.
1616
window.location.hostname === '[::1]' ||
1717
// 127.0.0.1/8 is considered localhost for IPv4.
18-
window.location.hostname.match(
19-
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20-
)
18+
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
2119
);
2220

2321
export function register(config) {
@@ -120,9 +118,7 @@ function checkValidServiceWorker(swUrl, config) {
120118
}
121119
})
122120
.catch(() => {
123-
console.log(
124-
'No internet connection found. App is running in offline mode.'
125-
);
121+
console.log('No internet connection found. App is running in offline mode.');
126122
});
127123
}
128124

0 commit comments

Comments
 (0)