Setup TSDX for design system

This commit is contained in:
Hammad Jutt
2020-07-28 14:33:43 -06:00
parent 64f9a2f661
commit 7a3b83d9d8
14 changed files with 1941 additions and 218 deletions

View File

@@ -28,7 +28,8 @@
"typecheck": "lerna run typecheck",
"precommit": "lerna run --concurrency 1 --stream precommit",
"prepush": "yarn typecheck",
"web": "yarn --cwd packages/web/"
"web": "yarn --cwd packages/web/",
"ds": "yarn --cwd packages/design-system/"
},
"workspaces": [
"packages/*"
@@ -51,9 +52,13 @@
"eslint-plugin-simple-import-sort": "5.0.3",
"hasura-cli": "1.2.1",
"husky": "^4.2.5",
"jest": "^26.1.0",
"lerna": "^3.16.4",
"lint-staged": "^10.2.11",
"prettier": "^2.0.5",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"tsdx": "^0.13.2",
"typescript": "^3.9.6"
}
}

View File

@@ -1,9 +1,28 @@
module.exports = {
stories: ['../stories/**/*.stories.jsx'],
addons: [
'@storybook/preset-typescript',
'@storybook/addon-actions',
'@storybook/addon-links',
'@storybook/addon-docs',
],
webpackFinal: async (config) => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
use: [
{
loader: require.resolve('ts-loader'),
options: {
transpileOnly: true,
},
},
{
loader: require.resolve('react-docgen-typescript-loader'),
},
],
});
config.resolve.extensions.push('.ts', '.tsx');
return config;
},
};

View File

@@ -0,0 +1,87 @@
# MetaGame Design System User Guide
> This was bootstrapped using [TSDX](https://github.com/formium/tsdx). Modified README for MetaGame usage below:
Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Lets get you oriented with whats here and how to use it.
> This TSDX setup is meant for developing React components (not apps!) that can be published to NPM. If youre looking to build an app, you should use `create-react-app`, `razzle`, `nextjs`, `gatsby`, or `react-static`.
> If youre new to TypeScript and React, checkout [this handy cheatsheet](https://github.com/sw-yx/react-typescript-cheatsheet/)
## Commands
TSDX scaffolds your new library inside `/src`.
The recommended workflow is to run TSDX in one terminal:
```
yarn start
```
This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
Then run storybook:
### Storybook
Run inside another terminal:
```
yarn storybook
```
This loads the stories from `./stories`.
> NOTE: Stories should reference the components as if using the library, similar to the example playground. This means importing from the root project directory. This has been aliased in the tsconfig and the storybook webpack config as a helper.
To run tests, use `yarn test`.
### Jest
Jest tests are set up to run with `npm test` or `yarn test`. This runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.
#### Folder Structure
```
/.storybook # Storybook configuration
/__tests__ # Test Files
foo.test.tsx
/src
index.tsx # Entry Point
theme.ts # Default Theme
GlobalStyle.ts # CSS Reset and Emotion Global Styles
/stories # Storybook files
Foo.stories.tsx
package.json
tsconfig.json
```
### Rollup
TSDX uses [Rollup v1.x](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.
## Optimizations
Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations:
```js
// ./types/index.d.ts
declare var __DEV__: boolean;
// inside your code...
if (__DEV__) {
console.log('foo');
}
```
You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions.
## Module Formats
CJS, ESModules, and UMD module formats are supported.
The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.
## Named Exports
Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.

View File

@@ -0,0 +1,12 @@
import React from 'react';
import * as ReactDOM from 'react-dom';
import { Sizes } from './0-Text.stories';
describe('Text Stories', () => {
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Sizes />, div);
ReactDOM.unmountComponentAtNode(div);
});
});

View File

@@ -2,17 +2,27 @@
"name": "@metafam/ds",
"version": "0.1.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"typings": "dist/index.d.ts",
"files": [
"dist",
"src"
],
"module": "dist/ds.esm.js",
"license": "MIT",
"scripts": {
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"prepare": "yarn build",
"typecheck": "yarn build",
"dev": "tsc -w",
"build": "tsc",
"typecheck": "tsc -p tsconfig.build.json",
"dev": "yarn start",
"start": "tsdx watch --tsconfig tsconfig.build.json --verbose --noClean",
"build": "tsdx build --tsconfig tsconfig.build.json",
"test": "tsdx test --passWithNoTests",
"prepublish": "yarn build",
"precommit": "yarn lint-staged"
},
"peerDependencies": {
"react": ">=16"
},
"dependencies": {
"@chakra-ui/core": "^0.8.0",
"@emotion/core": "^10.0.28",
@@ -20,15 +30,16 @@
"emotion-theming": "^10.0.27"
},
"devDependencies": {
"@babel/core": "^7.10.4",
"@babel/core": "^7.10.5",
"@storybook/addon-actions": "^5.3.19",
"@storybook/addon-docs": "^5.3.19",
"@storybook/addon-info": "^5.3.19",
"@storybook/addon-links": "^5.3.19",
"@storybook/addons": "^5.3.19",
"@storybook/preset-typescript": "^3.0.0",
"@storybook/react": "^5.3.19",
"babel-loader": "^8.1.0",
"fork-ts-checker-webpack-plugin": "^5.0.9",
"ts-loader": "^8.0.1"
"react-docgen-typescript-loader": "^3.7.2",
"ts-loader": "^8.0.1",
"tslib": "^2.0.0"
}
}

View File

@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"composite": true,
"rootDir": "./src",
"outDir": "./dist",
"tsBuildInfoFile": "./dist/.tsbuildinfo"
},
"include": ["./src"]
}

View File

@@ -1,12 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"composite": true,
"rootDir": "src",
"outDir": "dist",
"tsBuildInfoFile": "dist/.tsbuildinfo"
},
"include": ["src"]
"extends": "./tsconfig.build.json",
"include": ["./src", "__tests__", "stories"]
}

View File

@@ -1,9 +1,8 @@
import { Box, Heading, Image, SimpleGrid } from '@metafam/ds';
import { MetaLink } from 'components/Link';
import { getPokemons } from 'graphql/getPokemons';
import { InferGetStaticPropsType } from 'next';
import { MetaLink } from '../components/Link';
import { getPokemons } from '../graphql/getPokemons';
type Props = InferGetStaticPropsType<typeof getStaticProps>;
export const getStaticProps = async () => {

View File

@@ -24,6 +24,7 @@ const PokemonPage: React.FC<Props> = ({ pokemon }) => {
</Flex>
);
};
export default PokemonPage;
export const getStaticPaths: GetStaticPaths = async () => {

View File

@@ -7,6 +7,7 @@
"isolatedModules": true,
"jsx": "preserve",
"lib": ["dom", "es2017"],
"baseUrl": ".",
"noEmit": true
},
"references": [
@@ -14,7 +15,7 @@
"path": "../utils/tsconfig.json"
},
{
"path": "../design-system/tsconfig.json"
"path": "../design-system/tsconfig.build.json"
}
],
"include": ["**/*.ts", "**/*.tsx", "next-env.d.ts"],

View File

@@ -4,21 +4,21 @@
"target": "es6",
"moduleResolution": "node",
"jsx": "react",
"outDir": "./dist",
"skipLibCheck": true,
"strict": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"importHelpers": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"allowSyntheticDefaultImports": true,
"typeRoots": ["./packages/@types", "./node_modules/@types"]
},

1962
yarn.lock

File diff suppressed because it is too large Load Diff