Skip to content

Upgrade storybook to 6 #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

![Join us on Slack](https://img.shields.io/badge/Slack-React--Workpaces-EBB424?style=for-the-badge&logo=slack)

> 💥 Now supports TypeScript and React-App-Rewired!
> 💥 Now supports TypeScript and React-App-Rewired!

## Features

- ⚛️ Create React App 3 (React 16.8)
- 📖 Storybook 5
- 📖 Storybook 6
- 🐈 Yarn Workspaces
- 🐉 Lerna 3
- ✨ Host Multiple CRA Apps, Component Libraries & Storybooks in one Monorepo
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/app-ant-design/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"@project/components": "1.0.0",
"@react-workspaces/react-scripts": "^3.3.0-alpha-08",
"@react-workspaces/react-scripts": "3.4.0-alpha-01",
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/app-multi-comps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"@project/components": "1.0.0",
"@react-workspaces/react-scripts": "^3.3.0-alpha-08",
"@react-workspaces/react-scripts": "3.4.0-alpha-01",
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/app-single-comp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"@project/components": "1.0.0",
"@react-workspaces/react-scripts": "^3.3.0-alpha-08",
"@react-workspaces/react-scripts": "3.4.0-alpha-01",
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/app-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@project/components-typescript": "1.0.0",
"@react-workspaces/react-scripts": "^3.3.0-alpha-08",
"@react-workspaces/react-scripts": "3.4.0-alpha-01",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.4.0",
"@testing-library/user-event": "^8.0.3",
Expand Down
6 changes: 6 additions & 0 deletions packages/apps/app-typescript/src/assets/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module '*.svg' {
import React = require('react')
export const ReactComponent: React.SFC<React.SVGProps<SVGSVGElement>>
const src: string
export default src
}
78 changes: 39 additions & 39 deletions packages/apps/app-typescript/src/serviceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,17 @@

const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/),
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/),
);

type Config = {
onSuccess?: (registration: ServiceWorkerRegistration) => void;
onUpdate?: (registration: ServiceWorkerRegistration) => void;
};

export function register(config?: Config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}

window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;

if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);

// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA',
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}

function registerValidSW(swUrl: string, config?: Config) {
navigator.serviceWorker
.register(swUrl)
Expand All @@ -74,7 +40,7 @@ function registerValidSW(swUrl: string, config?: Config) {
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.',
'tabs for this page are closed. See https://bit.ly/CRA-PWA.',
);

// Execute callback
Expand Down Expand Up @@ -126,6 +92,40 @@ function checkValidServiceWorker(swUrl: string, config?: Config) {
});
}

export function register(config?: Config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL!, window.location.href);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}

window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;

if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);

// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA',
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}

export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
Expand Down
6 changes: 3 additions & 3 deletions packages/components-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"version": "1.0.0",
"main": "src/index.tsx",
"main:src": "src/index.tsx",
"private": true,
"scripts": {
"test": "react-scripts test",
"lint": "eslint ./src/**/*.tsx --max-warnings=0 --format=codeframe"
},
"dependencies": {
"@react-workspaces/react-scripts": "3.3.0-alpha-08",
"@storybook/react": "^5.2.8",
"@react-workspaces/react-scripts": "3.4.0-alpha-01",
"@storybook/react": "^6.1.11",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.4.0",
"@testing-library/user-event": "^8.0.3",
Expand All @@ -21,7 +22,6 @@
"@typescript-eslint/parser": "^2.15.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.3.0",
"typescript": "~3.7.4"
},
"eslintConfig": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';
import { storiesOf } from '@storybook/react';

import CompOne from '.';

storiesOf('CompOne', module).add('Default', () => <CompOne />);
export default {
title: 'CompOne',
};

export const Default = () => <CompOne />;
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';
import { storiesOf } from '@storybook/react';

import CompTwo from '.';

storiesOf('CompTwo', module).add('Default', () => <CompTwo />);
export default {
title: 'CompTwo',
};

export const Default = () => <CompTwo />;
3 changes: 1 addition & 2 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"lint": "eslint ./src/**/*.js --max-warnings=0 --format=codeframe"
},
"dependencies": {
"@react-workspaces/react-scripts": "3.3.0-alpha-08",
"@storybook/react": "^5.2.8",
"@react-workspaces/react-scripts": "3.4.0-alpha-01",
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/components/src/CompOne/CompOne.stories.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';
import { storiesOf } from '@storybook/react';

import CompOne from '.';

storiesOf('CompOne', module).add('Default', () => <CompOne />);
export default {
title: 'CompOne',
};

export const Default = () => <CompOne />;
7 changes: 5 additions & 2 deletions packages/components/src/CompTwo/CompTwo.stories.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';
import { storiesOf } from '@storybook/react';

import CompTwo from '.';

storiesOf('CompTwo', module).add('Default', () => <CompTwo />);
export default {
title: 'CompTwo',
};

export const Default = () => <CompTwo />;
3 changes: 0 additions & 3 deletions packages/storybook-typescript/.storybook/.babelrc

This file was deleted.

1 change: 0 additions & 1 deletion packages/storybook-typescript/.storybook/addons.js

This file was deleted.

14 changes: 0 additions & 14 deletions packages/storybook-typescript/.storybook/config.js

This file was deleted.

10 changes: 10 additions & 0 deletions packages/storybook-typescript/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
"stories": [
"../../components-typescript/src/**/*.stories.mdx",
"../../components-typescript/src/**/*.stories.@(js|jsx|ts|tsx)",
],
"addons": [
"@storybook/addon-links",
"@storybook/addon-essentials"
]
}
15 changes: 0 additions & 15 deletions packages/storybook-typescript/.storybook/preset.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/storybook-typescript/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
}
20 changes: 7 additions & 13 deletions packages/storybook-typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
{
"name": "@project/storybook-typescript",
"version": "1.0.0",
"private": true,
"scripts": {
"storybook": "start-storybook -p 9009",
"build-storybook": "build-storybook"
},
"dependencies": {
"@project/components-typescript": "1.0.0",
"@react-workspaces/react-scripts": "3.3.0-alpha-08",
"@react-workspaces/react-scripts": "3.4.0-alpha-01",
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
"devDependencies": {
"@babel/core": "^7.7.7",
"@storybook/addon-actions": "^5.2.8",
"@storybook/addon-docs": "^5.2.8",
"@storybook/addon-info": "^5.2.8",
"@storybook/addon-links": "^5.2.8",
"@storybook/addons": "^5.2.8",
"@storybook/preset-create-react-app": "^1.5.0",
"@storybook/react": "^5.2.8",
"@storybook/theming": "^5.2.8",
"babel-loader": "^8.0.6",
"cross-env": "6.0.3"
"@storybook/addon-actions": "^6.1.11",
"@storybook/addon-docs": "^6.1.11",
"@storybook/addon-links": "^6.1.11",
"@storybook/addons": "^6.1.11",
"@storybook/theming": "^6.1.11",
"babel-loader": "^8.2.2"
}
}
19 changes: 0 additions & 19 deletions packages/storybook-typescript/tsconfig.json

This file was deleted.

12 changes: 6 additions & 6 deletions packages/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
"dependencies": {
"@project/components": "1.0.0",
"@babel/core": "^7.7.7",
"@react-workspaces/react-scripts": "3.3.0-alpha-08",
"@react-workspaces/react-scripts": "3.4.0-alpha-01",
"babel-loader": "^8.0.6",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"cross-env": "6.0.3"
},
"devDependencies": {
"@storybook/react": "^5.2.8",
"@storybook/addon-actions": "^5.2.8",
"@storybook/addon-links": "^5.2.8",
"@storybook/addons": "^5.2.8",
"@storybook/theming": "^5.2.8"
"@storybook/react": "^6.1.11",
"@storybook/addon-actions": "^6.1.11",
"@storybook/addon-links": "^6.1.11",
"@storybook/addons": "^6.1.11",
"@storybook/theming": "^6.1.11"
}
}
Loading