feat: scaffold monorepo

This commit is contained in:
Yangshun Tay
2022-09-29 16:23:34 +08:00
parent 27a82e8c0f
commit 523d91f920
62 changed files with 19346 additions and 712 deletions

View File

@ -0,0 +1,147 @@
/* eslint-disable sort-keys-fix/sort-keys-fix */
const OFF = 0;
const WARN = 1;
const ERROR = 2;
module.exports = {
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'simple-import-sort',
'sort-keys-fix',
'typescript-sort-keys',
],
extends: [
'next',
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
settings: {
react: {
version: 'detect',
},
},
rules: {
camelcase: [ERROR, { properties: 'never', ignoreDestructuring: true }],
'capitalized-comments': [
ERROR,
'always',
{ ignoreConsecutiveComments: true },
],
'consistent-this': ERROR,
curly: ERROR,
'dot-notation': ERROR,
eqeqeq: [ERROR, 'smart'],
'func-name-matching': ERROR,
'func-names': [ERROR, 'as-needed'],
'func-style': [ERROR, 'declaration', { allowArrowFunctions: true }],
'guard-for-in': ERROR,
'init-declarations': ERROR,
'no-console': [ERROR, { allow: ['warn', 'error', 'info'] }],
'no-else-return': [ERROR, { allowElseIf: false }],
'no-extra-boolean-cast': ERROR,
'no-lonely-if': ERROR,
'no-shadow': ERROR,
'no-unused-vars': OFF, // Use @typescript-eslint/no-unused-vars instead.
'object-shorthand': ERROR,
'one-var': [ERROR, 'never'],
'operator-assignment': ERROR,
'prefer-arrow-callback': ERROR,
'prefer-const': ERROR,
'prefer-destructuring': [
ERROR,
{
object: true,
},
],
radix: ERROR,
'spaced-comment': ERROR,
'react/button-has-type': ERROR,
'react/display-name': OFF,
'react/destructuring-assignment': [ERROR, 'always'],
// 'react/hook-use-state': ERROR,
'react/no-array-index-key': ERROR,
'react/no-unescaped-entities': OFF,
'react/void-dom-elements-no-children': ERROR,
'react/jsx-boolean-value': [ERROR, 'always'],
'react/jsx-curly-brace-presence': [
ERROR,
{ props: 'never', children: 'never' },
],
'react/jsx-no-useless-fragment': ERROR,
'react/jsx-sort-props': [
ERROR,
{
callbacksLast: true,
shorthandFirst: true,
reservedFirst: true,
},
],
'@next/next/no-img-element': OFF,
'@next/next/no-html-link-for-pages': OFF,
'@typescript-eslint/array-type': [
ERROR,
{ default: 'generic', readonly: 'generic' },
],
'@typescript-eslint/consistent-generic-constructors': [
ERROR,
'constructor',
],
'@typescript-eslint/consistent-indexed-object-style': [ERROR, 'record'],
'@typescript-eslint/consistent-type-definitions': [ERROR, 'type'],
'@typescript-eslint/consistent-type-imports': ERROR,
'@typescript-eslint/no-duplicate-enum-values': ERROR,
'@typescript-eslint/no-for-in-array': ERROR,
'@typescript-eslint/no-non-null-assertion': OFF,
'@typescript-eslint/no-unused-vars': [ERROR, { argsIgnorePattern: '^_' }],
'@typescript-eslint/prefer-optional-chain': ERROR,
'@typescript-eslint/require-array-sort-compare': ERROR,
'@typescript-eslint/restrict-plus-operands': ERROR,
'@typescript-eslint/sort-type-union-intersection-members': ERROR,
// Sorting
'typescript-sort-keys/interface': ERROR,
'typescript-sort-keys/string-enum': ERROR,
'sort-keys-fix/sort-keys-fix': ERROR,
'simple-import-sort/exports': WARN,
'simple-import-sort/imports': [
WARN,
{
groups: [
// Ext library & side effect imports.
['^~?\\w', '^\\u0000', '^@'],
// Lib and hooks.
['^~/lib', '^~/hooks'],
// Static data.
['^~/data'],
// Components.
['^~/components'],
// Other imports.
['^~/'],
// Relative paths up until 3 level.
[
'^\\./?$',
'^\\.(?!/?$)',
'^\\.\\./?$',
'^\\.\\.(?!/?$)',
'^\\.\\./\\.\\./?$',
'^\\.\\./\\.\\.(?!/?$)',
'^\\.\\./\\.\\./\\.\\./?$',
'^\\.\\./\\.\\./\\.\\.(?!/?$)',
],
['^~/types'],
// {s}css files
['^.+\\.s?css$'],
// Others that don't fit in.
['^'],
],
},
],
},
};

View File

@ -0,0 +1,21 @@
{
"name": "eslint-config-tih",
"version": "0.0.0",
"private": true,
"license": "MIT",
"main": "index.js",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"eslint-config-next": "^12.3.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-react": "7.28.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-sort-keys-fix": "^1.1.2",
"eslint-plugin-typescript-sort-keys": "^2.1.0",
"eslint-config-turbo": "latest"
},
"publishConfig": {
"access": "public"
}
}

View File

@ -0,0 +1,20 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Default",
"compilerOptions": {
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"moduleResolution": "node",
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
"skipLibCheck": true,
"strict": true
},
"exclude": ["node_modules"]
}

View File

@ -0,0 +1,21 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Next.js",
"extends": "./base.json",
"compilerOptions": {
"allowJs": true,
"declaration": false,
"declarationMap": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"incremental": true,
"jsx": "preserve",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"noEmit": true,
"resolveJsonModule": true,
"target": "es5",
"strict": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.cjs", "**/*.mjs"]
}

View File

@ -0,0 +1,9 @@
{
"name": "@tih/tsconfig",
"version": "0.0.0",
"private": true,
"license": "MIT",
"publishConfig": {
"access": "public"
}
}

View File

@ -0,0 +1,11 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "React Library",
"extends": "./base.json",
"compilerOptions": {
"jsx": "react-jsx",
"lib": ["ES2015"],
"module": "ESNext",
"target": "es6"
}
}

8
packages/ui/.eslintrc.js Normal file
View File

@ -0,0 +1,8 @@
module.exports = {
root: true,
extends: ['tih'],
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
};

30
packages/ui/package.json Normal file
View File

@ -0,0 +1,30 @@
{
"name": "@tih/ui",
"version": "0.0.0",
"private": true,
"license": "MIT",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist/**"
],
"scripts": {
"build": "tsup src/index.tsx --format esm,cjs --dts --external react",
"clean": "rm -rf dist",
"tsc": "tsc",
"dev": "tsup src/index.tsx --format esm,cjs --watch --dts --external react",
"lint": "eslint src/**/*.ts* --fix"
},
"devDependencies": {
"@tih/tsconfig": "*",
"@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6",
"eslint": "^8.24.0",
"eslint-config-tih": "*",
"react": "^18.2.0",
"tsup": "^6.2.3",
"typescript": "^4.8.3"
}
}

View File

@ -0,0 +1,42 @@
import * as React from 'react';
export function CounterButton() {
const [count, setCount] = React.useState(0);
return (
<div
style={{
background: `rgba(0,0,0,0.05)`,
borderRadius: `8px`,
fontWeight: 500,
padding: '1.5rem',
}}>
<p style={{ margin: '0 0 1.5rem 0' }}>
This component is from{' '}
<code
style={{
background: `rgba(0,0,0,0.1)`,
borderRadius: '0.25rem',
padding: '0.2rem 0.3rem',
}}>
@tih/ui
</code>
</p>
<div>
<button
style={{
background: 'black',
border: 'none',
borderRadius: '0.25rem',
color: 'white',
cursor: 'pointer',
display: 'inline-block',
padding: '0.5rem 1rem',
}}
type="button"
onClick={() => setCount((c) => c + 1)}>
Count: {count}
</button>
</div>
</div>
);
}

View File

@ -0,0 +1,15 @@
import * as React from 'react';
export function NewTabLink({
children,
href,
...other
}: {
children: React.ReactNode;
href: string;
}) {
return (
<a href={href} rel="noreferrer" target="_blank" {...other}>
{children}
</a>
);
}

View File

@ -0,0 +1,2 @@
export { CounterButton } from './CounterButton';
export { NewTabLink } from './NewTabLink';

View File

@ -0,0 +1,8 @@
{
"compilerOptions": {
"lib": ["dom", "ES2015"]
},
"extends": "@tih/tsconfig/react-library.json",
"include": ["."],
"exclude": ["dist", "build", "node_modules"]
}