Skip to content

Commit 221b587

Browse files
author
Turbo
committed
Refactor application
1 parent 4681ed9 commit 221b587

38 files changed

+436
-123
lines changed

.eslintrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ module.exports = {
55
"node": true, //# Node.js global variables and Node.js scoping.
66
},
77

8+
// Specifying global variables
9+
"globals": {
10+
"logInfo": true,
11+
"logWarning": true,
12+
"logError": true,
13+
"logDebug": true,
14+
},
15+
816
"parser": "babel-eslint", // By default, ESLint expects ECMAScript 5 syntax, specify ES6 instead
917

1018
"parserOptions": {

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
"repository": "",
66
"license": "UNLICENSED",
77
"scripts": {
8+
"license-check": "license-checker --exclude 'MIT, MIT OR X11, BSD, ISC, Public Domain'",
89
"lint": "eslint .",
910
"lint-fix": "eslint . --fix",
10-
"clean-babel-cache": "rimraf -rf ./node_modules/.cache/babel-loader/*",
11+
"clean": "rimraf -rf ./node_modules/.cache/babel-loader/*",
1112
"prod": "NODE_ENV=production node src/server/index.js",
1213
"dev": "NODE_ENV=development nodemon --watch src/server --watch config --inspect src/server/index.js"
1314
},
@@ -34,7 +35,6 @@
3435
"babel-plugin-module-resolver": "^3.1.1",
3536
"babel-plugin-universal-import": "^3.1.2",
3637
"brotli-webpack-plugin": "^1.0.0",
37-
"chalk": "^2.4.1",
3838
"compression-webpack-plugin": "^2.0.0",
3939
"cookie-parser": "^1.4.3",
4040
"express": "^4.16.4",
@@ -43,7 +43,6 @@
4343
"graphql": "^14.0.2",
4444
"graphql-tag": "^2.10.0",
4545
"import": "0.0.6",
46-
"isomorphic-fetch": "^2.2.1",
4746
"isomorphic-unfetch": "^3.0.0",
4847
"markdown-with-front-matter-loader": "^0.1.0",
4948
"node-noop": "^1.0.0",
@@ -67,7 +66,9 @@
6766
"webpack-dev-middleware": "3.4.0",
6867
"webpack-flush-chunks": "^2.0.3",
6968
"webpack-hot-middleware": "2.24.3",
70-
"webpack-hot-server-middleware": "^0.5.0"
69+
"webpack-hot-server-middleware": "^0.5.0",
70+
"winston": "^3.1.0",
71+
"winston-daily-rotate-file": "^3.6.0"
7172
},
7273
"devDependencies": {
7374
"babel-eslint": "^10.0.1",
@@ -80,6 +81,7 @@
8081
"eslint-plugin-jsx-a11y": "^6.1.2",
8182
"eslint-plugin-react": "^7.11.1",
8283
"husky": "^1.2.1",
84+
"license-checker": "^25.0.1",
8385
"lint-staged": "^8.1.0",
8486
"nodemon": "^1.18.9"
8587
},

src/App/AppWrapper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import { ApolloProvider } from 'react-apollo';
66

77
import theme from 'src/styles/theme';
88
import GlobalizeStyle from 'src/styles/global-styles';
9-
import App from 'src/App';
10-
import apolloClient from 'src/data';
9+
import RouteComponents from 'src/App/RouteComponents';
10+
import apolloClient from 'src/data/ApolloClient';
1111

1212
const AppWrapper = ({ lang }) => (
1313
<ApolloProvider client={apolloClient}>
1414
<ThemeProvider theme={theme}>
1515
<React.Fragment>
1616
<GlobalizeStyle />
17-
<App lang={lang} />
17+
<RouteComponents lang={lang} />
1818
</React.Fragment>
1919
</ThemeProvider>
2020
</ApolloProvider>

src/App/Client.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,14 @@ import React from 'react';
33
import { BrowserRouter as Router } from 'react-router-dom';
44
import AppWrapper from 'src/App/AppWrapper';
55
import ScrollToTop from 'src/Components/ScrollToTop';
6-
import { getLocaleOnClient } from 'src/i18n/helpers';
6+
import { getLocaleOnClient } from 'src/i18n/utils';
77

8-
/* eslint-disable no-restricted-globals */
9-
export default class extends React.Component {
10-
constructor(props) {
11-
super(props);
12-
this.state = {};
13-
}
8+
const ClientApp = () => (
9+
<Router>
10+
<ScrollToTop>
11+
<AppWrapper lang={getLocaleOnClient(window.location)} />
12+
</ScrollToTop>
13+
</Router>
14+
);
1415

15-
render() {
16-
// Determine current language by name
17-
const currentLang = getLocaleOnClient(location);
18-
19-
return (
20-
<Router>
21-
<ScrollToTop>
22-
<AppWrapper lang={currentLang} />
23-
</ScrollToTop>
24-
</Router>
25-
);
26-
}
27-
}
16+
export default ClientApp;

src/App/index.js renamed to src/App/RouteComponents.js

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import Footer from 'src/Components/Footer';
66
import Loading from 'src/Components/Loading';
77
import { RedirectWithStatus } from 'src/Components/SSR';
88

9+
/*
10+
* Create a Universal Component template, allowing SSR a component + Code Splitting
11+
*/
912
const UniversalComponent = universal(props => import(`../Pages/${props.page}`), {
1013
loading: () => <Loading />,
1114
ignoreBabelRename: true,
@@ -16,43 +19,21 @@ export default ({ lang }) => (
1619
<Header lang={lang} />
1720

1821
<Switch>
19-
<Route
20-
exact
21-
path="/:lang"
22-
render={routeProps => <UniversalComponent page="Home" {...routeProps} />}
23-
/>
24-
25-
<Route
26-
exact
27-
path="/:lang/login"
28-
render={routeProps => <UniversalComponent page="Login" {...routeProps} />}
29-
/>
30-
31-
<Route
32-
exact
33-
path="/:lang/books"
34-
render={routeProps => <UniversalComponent page="Books" {...routeProps} />}
35-
/>
36-
37-
<Route
38-
exact
39-
path="/:lang/posts"
40-
render={routeProps => <UniversalComponent page="Posts" {...routeProps} />}
41-
/>
42-
43-
<Route
44-
exact
45-
path="/:lang/posts/:slug"
46-
render={routeProps => <UniversalComponent page="Post" {...routeProps} />}
47-
/>
22+
<Route exact path="/:lang" render={props => <UniversalComponent page="Home" {...props} />} />
23+
<Route exact path="/:lang/login" render={props => <UniversalComponent page="Login" {...props} />} />
24+
25+
<Route exact path="/:lang/books" render={props => <UniversalComponent page="Books" {...props} />} />
26+
27+
<Route exact path="/:lang/posts" render={props => <UniversalComponent page="Posts" {...props} />} />
28+
<Route exact path="/:lang/posts/:slug" render={props => <UniversalComponent page="Post" {...props} />} />
4829

4930
{/* Define Redirect logic if any */}
5031
<RedirectWithStatus httpStatus={301} from="/:lang" to={`/${lang}`} />
5132
<RedirectWithStatus httpStatus={301} from="/:lang/users" to="/" />
5233
<RedirectWithStatus httpStatus={302} from="/:lang/courses" to="/:lang/404" />
5334

5435
{/* If url is not defined, go 404 */}
55-
<Route render={routeProps => <UniversalComponent page="404" {...routeProps} />} />
36+
<Route render={props => <UniversalComponent page="404" {...props} />} />
5637
</Switch>
5738

5839
<Footer />

src/Components/Footer/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Image, Box } from 'rebass';
44
import FlexBox from 'src/Components/FlexBox';
55
import { TextBlock } from 'src/Components/Typo';
66

7-
const imagePath = require('src/assets/images/full-logo.svg');
7+
const imagePath = require('src/static/images/full-logo.svg');
88

99
const BoxWithFooter = Box.withComponent('footer');
1010

src/Components/Head/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { Helmet } from 'react-helmet';
33
import PropTypes from 'prop-types';
4-
import favicon from 'src/assets/images/favicon.png';
4+
import favicon from 'src/static/images/favicon.png';
55

66
const isProd = process.env.NODE_ENV === 'production';
77

src/Components/Header/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { Anchor, NavLink } from 'src/Components/Navigation';
33
import PropTypes from 'prop-types';
44

5-
import logo from 'src/assets/images/full-logo.svg';
5+
import logo from 'src/static/images/full-logo.svg';
66

77
import Head from 'src/Components/Head';
88
import FlexBox from 'src/Components/FlexBox';

src/Components/Logger/index.js

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

src/Components/Welcome/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
// import icon from 'assets/images/react-icon.png';
3+
// import icon from 'static/images/react-icon.png';
44
import styled from 'styled-components';
55

66
const Component = ({ message, appName }) => (

0 commit comments

Comments
 (0)