Skip to content

Commit

Permalink
feat: updated app to use both CRA default build and instructions on u…
Browse files Browse the repository at this point in the history
…sing storybook for a shared ui
  • Loading branch information
czaas-mb committed Mar 5, 2020
1 parent 64e825e commit 134b451
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 35 deletions.
Empty file added .env
Empty file.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ yarn create react-app app-name --template cra-mb-shared-ui

## Configuring conventional commits

Run `yarn add husky` then add the following to your `package.json`
Run `yarn add husky`. The `.huskyrc.json` is what triggers the conventional commits git hook to run.

## Workflow

By default CRA is used for building single page applications (SPA's). This template was made for the use of consuming a package as a bundle in existing applications. This means the default `yarn start` will not be used for building shared UI's.
You have two options of how you want to build your UI

### Viewing your work

Using storybook you can work locally with different views by running `yarn storybook`. Included is a basic app to get you started.
- Using CRA default `yarn start` which will load your application as you would expect CRA to do.
- Using storybook by adding a `*.stories.tsx` and viewing your application in storybook allowing for multiple instances and setups along with individual components.

### Testing

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cra-template-mb-shared-ui",
"name": "cra-template-mb-ui",
"version": "1.4.1",
"description": "Create react app template for building shared UI's",
"description": "Create react app template for building UI's",
"main": "template.json",
"scripts": {
"version:bump": "standard-version",
Expand Down
2 changes: 1 addition & 1 deletion template.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"scripts": {
"version:bump": "standard-version",
"build:shared-ui": "yarn prep-shared-ui && react-scripts build && yarn finalize-shared-ui",
"build:ui": "yarn prep-shared-ui && react-scripts build && yarn finalize-shared-ui",
"test:ci": "cross-env CI=true react-scripts test --transformIgnorePatterns \"node_modules/(?!(@mbkit/*)/)\" --env=jsdom",
"test:watch": "react-scripts test --transformIgnorePatterns \"node_modules/(?!(@mbkit/*)/)\" --env=jsdom",
"storybook": "start-storybook -p 9009 -s public",
Expand Down
2 changes: 1 addition & 1 deletion template/build.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN yarn install --pure-lockfile
FROM prep as build

# Build packages
RUN yarn build:shared-ui
RUN yarn build:ui

FROM base as artifact
COPY --from=build /prepping-ui/build /ui/arcusOutput
2 changes: 1 addition & 1 deletion template/gated.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ RUN yarn install --pure-lockfile
RUN yarn test:ci

# Build packages
RUN yarn build:shared-ui
RUN yarn build:ui
Binary file added template/public/favicon.ico
Binary file not shown.
52 changes: 42 additions & 10 deletions template/public/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Do not use "yarn start"</h1>
<p>For shared UI's, use storybook to build and test locally then inject your script into the consuming application</p>
</body>
</html>
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>MB UI</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file added template/public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added template/public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions template/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions template/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
26 changes: 11 additions & 15 deletions template/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import React, { lazy, Suspense } from 'react';
import React from 'react';
import ReactDOM from 'react-dom';
const App = lazy(() => import('./App'));
import App from './App';

declare global {
interface Window {
loadSharedUi: (mount: HTMLElement | null) => void;
}
}
/**
* If you are loading the UI from within the consuming application and need special attention or to pass specific data,
* replace the mount below with a unique function that you can call from the consuming application e.g.
*
* window.loadMyApplicationName = (mount = document.getElementById('root'), { ...your arguments needed }) => {
* ReactDOM.render(<App {...pass arguments along} />, mount);
* }
*/

window.loadSharedUi = (mount = document.getElementById('root')) => {
ReactDOM.render(
<Suspense fallback={'Loading...'}>
<App />
</Suspense>,
mount,
);
};
ReactDOM.render(<App />, document.getElementById('root'));

0 comments on commit 134b451

Please sign in to comment.