Skip to content

Commit

Permalink
Replace storybook with react-cosmos (#609)
Browse files Browse the repository at this point in the history
* Replace storybook with react-cosmos.  Mostly working.

* Replace storybook with react-cosmos.  Mostly working.

* yarn build: both serve and cosmos.  Remove broken stories.

* yarn build-cosmos: clean build before build.  Obey NODE_ENV production or development settings.

* cosmos.webpack.js: use root serving path for standalone local dev but under /sb for prod.

* cosmos.webpack.js: more testing to put output under /sb in prod.

* Remove debug logging

* Remove HtmlPlugin from React Cosmos webpack config per random advice on internet.

* Testing cosmos build locations.

* Testing cosmos build locations 2.
  • Loading branch information
pablo-mayrgundter committed Mar 23, 2023
1 parent 907b209 commit 77c71ab
Show file tree
Hide file tree
Showing 74 changed files with 1,745 additions and 10,749 deletions.
10 changes: 10 additions & 0 deletions .cosmos.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"hot": "true",
"watchDirs": ["src"],
"hostname": "0.0.0.0",
"port": "8080",
"publicUrl": "./",
"webpack": {
"configPath": ".cosmos.webpack.js"
}
}
43 changes: 43 additions & 0 deletions .cosmos.webpack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const HtmlWebpackPlugin = require('html-webpack-plugin')
const path = require('path')


module.exports = {
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
devServer: {
publicPath: '/cosmos/',
contentBase: path.join(__dirname, 'docs'),
compress: true,
port: 8000,
},
output: {
path: path.resolve(__dirname, 'docs'),
publicPath: '/cosmos/',
filename: 'index.html',
},
plugins: [new HtmlWebpackPlugin()],
module: {
rules: [
{
test: /\.jsx$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-react'],
},
},
},
{
test: /\.svg$/i,
use: ['@svgr/webpack'],
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.svg'],
},
optimization: {
minimize: false
},
}
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = {
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:jsx-a11y/recommended',
'plugin:storybook/recommended',
'plugin:jsdoc/recommended',
'plugin:cypress/recommended',
],
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

cypress/videos
cypress/screenshots

storybook-static
17 changes: 0 additions & 17 deletions .storybook/main.js

This file was deleted.

6 changes: 0 additions & 6 deletions .storybook/manager.js

This file was deleted.

24 changes: 0 additions & 24 deletions .storybook/preview.js

This file was deleted.

8 changes: 0 additions & 8 deletions .storybook/theme.js

This file was deleted.

2 changes: 1 addition & 1 deletion config/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const build = {
format: 'esm',
sourcemap: true,
platform: 'browser',
target: ['chrome58', 'firefox57', 'safari11', 'edge18'],
target: ['chrome58', 'firefox57', 'safari11', 'edge18', 'es2020'],
logLevel: 'info',
define: {
'process.env.OAUTH2_CLIENT_ID': JSON.stringify(process.env.OAUTH2_CLIENT_ID),
Expand Down
16 changes: 16 additions & 0 deletions cosmos.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<title>React Cosmos</title>
<link rel="icon" href="/sb/_cosmos.ico" />
</head>
<body>
<div id="root"></div>
<script src="/sb/_playground.js"></script>
</body>
</html>
29 changes: 10 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
{
"name": "bldrs",
"version": "1.0.0-r646",
"version": "1.0.0-r658",
"main": "src/index.jsx",
"license": "MIT",
"homepage": "https://github.com/bldrs-ai/Share",
"bugs": {
"url": "https://github.com/bldrs-ai/Share/issues"
},
"scripts": {
"build": "yarn build-share && yarn build-storybook",
"build-storybook": "shx mkdir -p docs && build-storybook -o docs/sb",
"build": "yarn clean && yarn build-share && yarn build-cosmos",
"build-cosmos": "shx rm -rf docs/cosmos; shx mkdir -p docs ; cosmos-export --config .cosmos.config.json && shx mv cosmos-export docs/cosmos",
"build-share": "yarn write-new-version && node config/build.js && yarn build-share-copy-web-asm",
"build-share-copy-web-asm": "shx cp node_modules/web-ifc/*.wasm docs/static/js",
"clean": "shx rm -rf docs",
"deps-graph": "npx dependency-cruiser src --include-only 'jsx?' --config --output-type dot | dot -T svg > deps.svg",
"husky-init": "husky install",
"lint": "yarn eslint src && tsc",
"precommit": "yarn lint && yarn test",
"serve": "yarn serve-share",
"serve-cosmos": "cosmos --config .cosmos.config.json",
"serve-share": "yarn build-share && node config/serve.js",
"serve-storybook": "start-storybook -p 6006",
"test": "jest",
"cypress": "cypress run",
"cypress-spec": "cypress run --spec",
Expand All @@ -33,8 +34,7 @@
"@emotion/react": "^11.10.0",
"@emotion/styled": "^11.10.0",
"@iconscout/react-unicons": "^1.1.6",
"@material-ui/core": "^4.12.4",
"@mui/icons-material": "^5.8.4",
"@mui/icons-material": "^5.11.9",
"@mui/lab": "^5.0.0-alpha.95",
"@mui/material": "^5.9.2",
"@mui/styled-engine": "^5.8.7",
Expand Down Expand Up @@ -72,16 +72,7 @@
"@bahmutov/cypress-esbuild-preprocessor": "^2.1.3",
"@mui/types": "^7.2.3",
"@pablo-mayrgundter/cookies.js": "^1.0.0",
"@storybook/addon-actions": "^6.5.10",
"@storybook/addon-essentials": "^6.5.10",
"@storybook/addon-interactions": "^6.5.10",
"@storybook/addon-links": "^6.5.10",
"@storybook/addons": "^6.5.10",
"@storybook/builder-webpack4": "^6.5.10",
"@storybook/manager-webpack4": "^6.5.10",
"@storybook/react": "^6.5.10",
"@storybook/testing-library": "^0.0.13",
"@storybook/theming": "^6.5.10",
"@svgr/webpack": "^6.5.1",
"@testing-library/cypress": "^9.0.0",
"@testing-library/dom": "^8.19.1",
"@testing-library/jest-dom": "^5.16.5",
Expand Down Expand Up @@ -109,17 +100,17 @@
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-storybook": "^0.6.4",
"eslint-plugin-testing-library": "^5.9.1",
"html-webpack-plugin": "^5.5.0",
"husky": "^8.0.1",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"jsdom": "^20.0.3",
"msw": "^0.47.4",
"react-cosmos": "^5.7.2",
"shx": "^0.3.4",
"storybook-addon-material-ui": "^0.9.0-alpha.24",
"storybook-addon-turbo-build": "^1.1.0"
"webpack": "^5.75.0"
},
"msw": {
"workerDirectory": "public"
Expand Down
2 changes: 1 addition & 1 deletion src/Components/About/AboutControl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {Helmet} from 'react-helmet-async'
/**
* Button to toggle About panel on and off
*
* @return {React.ReactElement}
* @return {React.Component}
*/
export default function AboutControl() {
const isAboutDialogSuppressed = useStore((state) => state.isAboutDialogSuppressed)
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Buttons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function TooltipIconButton({
title,
onClick,
icon,
placement = 'left',
placement = 'right',
selected = false,
size = 'medium',
dataTestId = '',
Expand Down
3 changes: 2 additions & 1 deletion src/Components/CutPlaneMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function removePlanes(viewer) {


/**
* helper method to get the location of cut plane from the center of the model
* Helper method to get the location of cut plane from the center of the model.
*
* @param {object} viewer
* @param {object} ifcModel
Expand Down Expand Up @@ -184,6 +184,7 @@ export function getPlanesOffset(viewer, ifcModel) {
})
return planesOffset
}
return undefined
}


Expand Down
9 changes: 3 additions & 6 deletions src/Components/Dialog.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import DialogActions from '@mui/material/DialogContent'
import DialogActions from '@mui/material/DialogActions'
import DialogContent from '@mui/material/DialogContent'
import MuiDialog from '@mui/material/Dialog'
import Typography from '@mui/material/Typography'
Expand All @@ -18,24 +18,22 @@ import {assertDefined} from '../utils/assert'
* @property {Function} actionCb Callback for action button
* @property {React.ReactElement} content Content of the dialog
* @property {React.ReactElement} actionIcon Optional icon for the action button
* @return {object} React component
* @return {React.Component}
*/
export default function Dialog({
icon,
headerText,
isDialogDisplayed,
setIsDialogDisplayed,
content,
actionTitle,
actionCb,
content,
actionIcon,
}) {
assertDefined(
icon, headerText, isDialogDisplayed, setIsDialogDisplayed, content,
actionTitle, actionCb)
const close = () => setIsDialogDisplayed(false)


return (
<MuiDialog
open={isDialogDisplayed}
Expand All @@ -46,7 +44,6 @@ export default function Dialog({
}}
PaperProps={{variant: 'control'}}
>

<DialogContent>
<div
style={{
Expand Down
7 changes: 7 additions & 0 deletions src/Components/Loader.fixture.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react'
import Loader from './Loader'


export default (
<Loader/>
)
2 changes: 1 addition & 1 deletion src/Components/Loader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import CircularProgress from '@mui/material/CircularProgress'
*/
export default function Loader({type = 'linear'}) {
return (
<Box sx={{width: '100%', alignItems: 'center'}}>
<Box sx={{width: '100%', alignItems: 'center'}} className={'progress-bar'}>
{type === 'linear' &&
<LinearProgress color="success" sx={{height: '8px', width: '100%', borderRadius: '5px'}}/>
}
Expand Down
11 changes: 11 additions & 0 deletions src/Components/Loader.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'
import {render} from '@testing-library/react'
import Loader from './Loader'


describe('Loader', () => {
it('renders', () => {
const {container} = render(<Loader/>)
expect(container.firstChild).toHaveClass('progress-bar')
})
})
30 changes: 0 additions & 30 deletions src/Components/Loader.text.jsx

This file was deleted.

8 changes: 8 additions & 0 deletions src/Components/TooltipIconButton.fixture.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import {TooltipIconButton} from './Buttons'
import ShareIcon from '../assets/icons/Share.svg'


export default (
<TooltipIconButton title={'Hello World'} icon={<ShareIcon/>} onClick={() => console.log('clicked')}/>
)

0 comments on commit 77c71ab

Please sign in to comment.