diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..e56874cc --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +src/types/* +src/api/operations/*/operation.tsx +src/react-app-env.d.ts +src/serviceWorker.ts diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..d821bc4b --- /dev/null +++ b/.eslintrc @@ -0,0 +1,84 @@ +{ + "extends": [ + "eslint:recommended", + "plugin:react/recommended", + "airbnb", + "react-app" + ], + "plugins": [ + "sort-destructure-keys", + "typescript-sort-keys", + "postro4no" + ], + "rules": { + "@typescript-eslint/array-type": [ + "warn", + { "default" : "generic" } + ], + "@typescript-eslint/indent": ["warn", 2], + "@typescript-eslint/member-delimiter-style": ["warn", { + "multiline": { + "delimiter": "comma", + "requireLast": true + }, + "singleline": { + "delimiter": "comma", + "requireLast": false + } + }], + "import/extensions": [ + "warn", + "never", + { + "svg": "always", + "css": "always", + "scss": "always" + } + ], + "import/no-duplicates": "warn", + "import/no-extraneous-dependencies": [ + "warn", + { "devDependencies": ["src/setupTests.ts"] } + ], + "jsx-quotes": [ + "warn", + "prefer-single" + ], + "no-param-reassign": [ + "warn", + { + "props": true, + "ignorePropertyModificationsFor": ["self", "acc"] + } + ], + "postro4no/function-args": "warn", + "postro4no/import": "warn", + "postro4no/object-props": "warn", + "react/jsx-filename-extension": [ + "warn", + { "extensions": [".tsx"] } + ], + "react/jsx-indent": ["warn", 2], + "sort-destructure-keys/sort-destructure-keys": [ + 1, + { "caseSensitive": false } + ], + "sort-keys": [ + "warn", + "asc", { + "caseSensitive": true, + "natural": true + } + ], + "typescript-sort-keys/interface": 1, + "typescript-sort-keys/string-enum": 1, + + "camelcase": "off", + "import/no-unresolved": "off", + "import/prefer-default-export": "off", + "indent": "off", + "no-unused-vars": "off", + "react/jsx-one-expression-per-line": "off", + "semi": "off" + } +} diff --git a/codegen.yml b/codegen.yml new file mode 100644 index 00000000..7801e848 --- /dev/null +++ b/codegen.yml @@ -0,0 +1,22 @@ +overwrite: true +schema: '' +documents: src/api/operations/**/*.graphql +generates: + src/types/index.tsx: + plugins: + - typescript + src/: + preset: + near-operation-file + presetConfig: + extension: .tsx + baseTypesPath: types + plugins: + - typescript-operations + - typescript-react-apollo + config: + withComponent: false + withHOC: false + withHooks: true +config: + typesPrefix: T diff --git a/package.json b/package.json index a4d7cab2..e6968d2e 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,21 @@ "version": "0.1.0", "private": true, "scripts": { + "prestart ": "yarn generate", "start": "react-scripts start", "build": "GENERATE_SOURCEMAP=false react-scripts build && gzipper --verbose ./build", - "test": "react-scripts test --passWithNoTests --watchAll=false", - "eject": "react-scripts eject" + "test": "react-scripts test --testMatch '**/__tests__/*' --passWithNoTests --watchAll=false", + "test:watch": "react-scripts test --testMatch '**/__tests__/*'", + "eject": "react-scripts eject", + "generate": "graphql-codegen --config codegen.yml", + "lint": "eslint 'src/**/*.{ts,tsx}'" }, "dependencies": { + "@apollo/react-common": "^3.1.4", + "@apollo/react-hooks": "^3.1.5", + "apollo-boost": "^0.4.9", + "graphql": "^15.0.0", + "lodash": "^4.17.15", "react": "^16.13.1", "react-dom": "^16.13.1", "react-scripts": "3.4.1" @@ -16,21 +25,35 @@ "devDependencies": { "@commitlint/cli": "^8.3.5", "@commitlint/config-conventional": "^8.3.4", + "@graphql-codegen/cli": "1.15.0", + "@graphql-codegen/import-types-preset": "^1.15.0", + "@graphql-codegen/near-operation-file-preset": "^1.15.0", + "@graphql-codegen/typescript": "1.15.0", + "@graphql-codegen/typescript-operations": "1.15.0", + "@graphql-codegen/typescript-react-apollo": "1.15.0", "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.2", "@testing-library/user-event": "^7.1.2", "@types/jest": "^24.0.0", + "@types/lodash": "^4.14.154", "@types/node": "^12.0.0", "@types/react": "^16.9.0", "@types/react-dom": "^16.9.0", "commitizen": "^4.1.2", + "eslint": "6.8.0", + "eslint-config-airbnb": "18.1.0", + "eslint-plugin-import": "^2.20.1", + "eslint-plugin-jsx-a11y": "^6.2.3", + "eslint-plugin-postro4no": "^0.0.7", + "eslint-plugin-react": "^7.19.0", + "eslint-plugin-react-hooks": "2.5.0", + "eslint-plugin-sort-destructure-keys": "^1.3.4", + "eslint-plugin-typescript-sort-keys": "^1.2.0", "gzipper": "^3.7.0", "husky": "^4.2.5", + "lint-staged": "^10.2.7", "typescript": "^3.9.3" }, - "eslintConfig": { - "extends": "react-app" - }, "config": { "commitizen": { "path": "./node_modules/cz-conventional-changelog" @@ -38,10 +61,16 @@ }, "husky": { "hooks": { - "pre-commit": "npm test", + "pre-commit": "lint-staged", "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" } }, + "lint-staged": { + "src/**/*.{ts,tsx}": [ + "npm run lint -- --max-warnings 0", + "npm run test -- --findRelatedTests" + ] + }, "browserslist": { "production": [ ">0.2%", diff --git a/src/api/operations/User/queries.graphql b/src/api/operations/User/queries.graphql new file mode 100644 index 00000000..14ec1c2c --- /dev/null +++ b/src/api/operations/User/queries.graphql @@ -0,0 +1,8 @@ +query User { + __schema { + types { + name + kind + } + } +} diff --git a/src/api/operations/User/queries.tsx b/src/api/operations/User/queries.tsx new file mode 100644 index 00000000..bbbcc5b7 --- /dev/null +++ b/src/api/operations/User/queries.tsx @@ -0,0 +1,3 @@ +// autgenerated using https://graphql-code-generator.com/ + +export {} diff --git a/src/api/requests/index.tsx b/src/api/requests/index.tsx new file mode 100644 index 00000000..d4389750 --- /dev/null +++ b/src/api/requests/index.tsx @@ -0,0 +1 @@ +export * from './login' diff --git a/src/api/requests/login.tsx b/src/api/requests/login.tsx new file mode 100644 index 00000000..627dbbf4 --- /dev/null +++ b/src/api/requests/login.tsx @@ -0,0 +1 @@ +export const login = () => {} diff --git a/src/config/index.tsx b/src/config/index.tsx new file mode 100644 index 00000000..49800c7a --- /dev/null +++ b/src/config/index.tsx @@ -0,0 +1 @@ +export * from './routes' diff --git a/src/config/routes.tsx b/src/config/routes.tsx new file mode 100644 index 00000000..2f03b423 --- /dev/null +++ b/src/config/routes.tsx @@ -0,0 +1,2 @@ +export const API_ROOT = '' +export const GRAPHQL = `${API_ROOT}/graphql` diff --git a/src/features/Login/index.tsx b/src/features/Login/index.tsx new file mode 100644 index 00000000..741eb3d8 --- /dev/null +++ b/src/features/Login/index.tsx @@ -0,0 +1,7 @@ +import React from 'react' + +export const Login = () => ( +