Skip to content

Commit 78e93e7

Browse files
authored
Episode06 golive (#7)
* Episode 06: Adds storybook installation * Episode 06: Adds more storybook stories * Episode 06: Adds more complex examples for storybook * Episode 06: Removes MUI and adds storybook-static to gitignore * Episode 06: Adds config.js injection * Episode 06: Adds source-map-explorer and removes some unused dependencies * Episode 06: Makes port in jsonServer configurable * Episode 06: Fixes config script to create config folder if it does not exist * Episode 06: Adds Sentry monitoring * Episode 06: Fixes script to not create an additional folder * Episode 06: Renamed config to AppConfigs to enable ejecting * Episode 06: Moved scripts to appConfigs to enable ejcting
1 parent bdb64d7 commit 78e93e7

30 files changed

+31275
-17826
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
},
1616
"rules": {
1717
"styled-components-a11y/no-onchange": 0
18-
}
18+
},
19+
"ignorePatterns": ["!**/*", ".storybook/*", "./src/stories/**"]
1920
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
.env.test.local
1919
.env.production.local
2020

21+
public/config/config.js
22+
2123
npm-debug.log*
2224
yarn-debug.log*
2325
yarn-error.log*
26+
27+
storybook-static

.storybook/main.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
"stories": [
3+
"../src/**/*.stories.mdx",
4+
"../src/**/*.stories.@(js|jsx|ts|tsx)"
5+
],
6+
"addons": [
7+
"@storybook/addon-links",
8+
"@storybook/addon-essentials",
9+
"@storybook/preset-create-react-app",
10+
"storybook-addon-styled-component-theme/dist/preset"
11+
],
12+
webpackFinal: (config) => {
13+
return {
14+
...config,
15+
module: {
16+
rules: config.module.rules.filter(rule => {
17+
if (!rule.use) return true;
18+
return !rule.use.find(
19+
useItem => typeof useItem.loader === 'string' && useItem.loader.includes('eslint-loader'),
20+
);
21+
}),
22+
}
23+
}
24+
}
25+
}

.storybook/preview.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { addDecorator } from "@storybook/react";
2+
import { MemoryRouter } from 'react-router-dom';
3+
import { Provider } from 'react-redux';
4+
import { createAppStore } from '../src/app/redux/store';
5+
import { withThemesProvider } from "storybook-addon-styled-component-theme";
6+
import { ThemeProvider } from "styled-components";
7+
import { Theme } from '../src/layout/Theme';
8+
import '../src/app/i18n/i18nService';
9+
10+
const themes = [Theme];
11+
addDecorator(withThemesProvider(themes), ThemeProvider);
12+
13+
export const parameters = {
14+
actions: { argTypesRegex: "^on[A-Z].*" },
15+
controls: {
16+
matchers: {
17+
color: /(background|color)$/i,
18+
date: /Date$/,
19+
},
20+
},
21+
}
22+
23+
export const decorators = [
24+
(Story) => (
25+
<Provider store={createAppStore()}>
26+
<MemoryRouter>
27+
<Story />
28+
</MemoryRouter>
29+
</Provider>
30+
),
31+
]

appConfigs/config.dev.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
window.hppConfig = {
4+
apiHost: 'http://localhost:3001'
5+
};

appConfigs/config.prod.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
window.hppConfig = {
4+
apiHost: 'http://localhost:3004'
5+
};

appConfigs/prepareConfig.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* eslint-disable no-console */
2+
'use strict';
3+
4+
const path = require('path');
5+
const fs = require('fs');
6+
7+
// eslint-disable-next-line no-process-env
8+
const env = process.env.CONFIG_ENV ?? 'dev';
9+
10+
const targetConfigJSBasePath = path.join(__dirname, '..', 'public', 'config');
11+
const targetConfigJSPath = path.join(targetConfigJSBasePath, 'config.js');
12+
13+
const prepareConfig = async () => {
14+
const sourcePath = path.join(__dirname, `config.${env}.js`);
15+
16+
// Ensure the config directory exists
17+
await fs.promises.mkdir(targetConfigJSBasePath, {
18+
recursive: true
19+
});
20+
await fs.promises.copyFile(sourcePath, targetConfigJSPath);
21+
};
22+
23+
prepareConfig().
24+
then(() => {
25+
console.log(`[prepareConfig.js] Succesfully injected config for ${env}.`);
26+
}).catch(ex => {
27+
console.error(`[prepareConfig.js] Error while preparing config.js for env ${env}:`, ex);
28+
});
29+
30+
/* eslint-enable no-console */

mockBackend/jsonServer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import jsonServer from 'json-server';
22
import { mockParties } from './mockParties';
33

4+
// eslint-disable-next-line no-process-env
5+
const port = process.env.PORT ?? 3_001;
6+
47
const server = jsonServer.create();
58
const router = jsonServer.router({ parties: mockParties });
69
const middlewares = jsonServer.defaults();
@@ -25,7 +28,7 @@ server.use((req, res, next): void => {
2528

2629
// Use default router
2730
server.use(router);
28-
server.listen(3_001, (): void => {
31+
server.listen(port, (): void => {
2932
// eslint-disable-next-line no-console
30-
console.log('JSON Server is running on Port 3001');
33+
console.log(`JSON Server is running on Port ${port}`);
3134
});

0 commit comments

Comments
 (0)