react typescript package

master
Tudor Stanciu 2023-02-11 20:52:00 +02:00
parent b9910e2f61
commit 3f35229fef
16 changed files with 4323 additions and 348 deletions

2
.eslintignore Normal file
View File

@ -0,0 +1,2 @@
node_modules
dist

32
.eslintrc Normal file
View File

@ -0,0 +1,32 @@
{
"root": true,
"extends": [
"prettier",
"plugin:prettier/recommended",
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "prettier", "react", "react-hooks"],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-explicit-any": "off"
},
"settings": {
"react": {
"version": "detect"
}
},
"env": {
"browser": true,
"node": true
},
"globals": {
"JSX": true
}
}

1
.gitignore vendored
View File

@ -7,7 +7,6 @@ node_modules
build build
lib lib
dist dist
.rpt2_cache
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*

View File

@ -1,6 +1,8 @@
{ {
"bracketSpacing": true,
"arrowParens": "avoid", "arrowParens": "avoid",
"printWidth": 160, "printWidth": 120,
"trailingComma": "none", "trailingComma": "none",
"singleQuote": false "singleQuote": false,
"endOfLine": "auto"
} }

22
LICENSE Normal file
View File

@ -0,0 +1,22 @@
MIT License
Copyright (c) 2023 Tudor Stanciu
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -2,9 +2,10 @@
"transform": { "transform": {
"^.+\\.(t|j)sx?$": "ts-jest" "^.+\\.(t|j)sx?$": "ts-jest"
}, },
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "testRegex": "(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"], "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"collectCoverage": true, "testEnvironment": "jsdom",
"collectCoverage": false,
"coverageThreshold": { "coverageThreshold": {
"global": { "global": {
"branches": 50, "branches": 50,

4469
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +1,21 @@
{ {
"name": "@flare/tuitio-react-client", "name": "@flare/tuitio-react-client",
"version": "1.0.0", "version": "1.0.0",
"description": "React Tuitio client", "description": "Tuitio react client",
"main": "./lib/index.js", "main": "./dist/cjs/index.js",
"types": "./lib/index.d.ts", "module": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts",
"scripts": { "scripts": {
"build": "tsc", "build": "npm run build:esm && npm run build:cjs",
"build:esm": "tsc",
"build:cjs": "tsc --module commonjs --outDir dist/cjs",
"test": "jest --config jestconfig.json", "test": "jest --config jestconfig.json",
"format": "prettier --write \"src/**/*.ts\"", "format": "prettier --write \"{src,tests}/**/*.{js,ts,jsx,tsx}\"",
"lint": "tslint -p tsconfig.json", "lint": "eslint \"{**/*,*}.{js,ts,jsx,tsx}\"",
"prepublishOnly": "npm test && npm run lint", "prepublishOnly": "npm test && npm run lint",
"prepush": "npm run build", "prepush": "npm run build",
"preversion": "npm run lint", "preversion": "npm run lint",
"version": "npm run format && git add -A src", "version": "npm run format",
"push": "npm publish", "push": "npm publish",
"push:major": "npm run version:major && npm run push", "push:major": "npm run version:major && npm run push",
"push:minor": "npm run version:minor && npm run push", "push:minor": "npm run version:minor && npm run push",
@ -34,29 +37,40 @@
"email": "tudor.stanciu94@gmail.com", "email": "tudor.stanciu94@gmail.com",
"url": "https://lab.code-rove.com/tsp" "url": "https://lab.code-rove.com/tsp"
}, },
"license": "ISC", "license": "MIT",
"bugs": { "bugs": {
"url": "https://lab.code-rove.com/gitea/bricks/tuitio-react-client/issues" "url": "https://lab.code-rove.com/gitea/bricks/tuitio-react-client/issues"
}, },
"homepage": "https://lab.code-rove.com/gitea/bricks/tuitio-react-client#readme", "homepage": "https://lab.code-rove.com/gitea/bricks/tuitio-react-client#readme",
"files": [ "files": [
"lib/**/*" "dist",
"LICENSE",
"README.md"
], ],
"devDependencies": {
"@types/jest": "^29.4.0",
"@types/react": "^18.0.27",
"jest": "^29.4.1",
"jest-environment-jsdom": "^29.4.2",
"prettier": "^2.8.3",
"ts-jest": "^29.0.5",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.9.5"
},
"dependencies": { "dependencies": {
"@flare/tuitio-client": "^1.0.2" "@flare/tuitio-client": "^1.0.2"
}, },
"peerDependencies": { "peerDependencies": {
"react": "^16.14.0" "react": "^16.14.0"
},
"devDependencies": {
"@testing-library/react": "^12.1.5",
"@types/jest": "^29.4.0",
"@types/react": "^18.0.27",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"jest": "^29.4.2",
"jest-canvas-mock": "^2.4.0",
"jest-environment-jsdom": "^29.4.2",
"prettier": "^2.8.4",
"react": "^16.14.0",
"react-dom": "16.14.0",
"ts-jest": "^29.0.5",
"typescript": "^4.9.5"
} }
} }

24
src/TuitioProvider.tsx Normal file
View File

@ -0,0 +1,24 @@
import React, { useReducer, useMemo, ReactNode } from "react";
import { TuitioContext, TuitioDispatchContext } from "./contexts";
import { initialState } from "./initialState";
import { reducer, dispatchActions } from "./reducer";
import { TuitioReactState } from "./types";
type Props = {
children: ReactNode;
tuitioUrl: string;
};
const TuitioProvider = ({ children, tuitioUrl }: Props) => {
const initState: TuitioReactState = { ...initialState, configuration: { tuitioUrl } };
const [state, dispatch] = useReducer(reducer, initState);
const actions = useMemo(() => dispatchActions(dispatch), [dispatch]);
return (
<TuitioContext.Provider value={state}>
<TuitioDispatchContext.Provider value={actions}>{children}</TuitioDispatchContext.Provider>
</TuitioContext.Provider>
);
};
export default TuitioProvider;

View File

@ -1 +0,0 @@
// to do

View File

@ -1,2 +1,3 @@
const x = 4; import TuitioProvider from "./TuitioProvider";
export default x;
export default TuitioProvider;

View File

@ -10,6 +10,6 @@ export const initialState: TuitioReactState = {
}; };
export const initialDispatchActions: TuitioDispatchActions = { export const initialDispatchActions: TuitioDispatchActions = {
onLoginSuccess: () => {}, onLoginSuccess: () => undefined,
onLogout: () => {} onLogout: () => undefined
}; };

View File

@ -3,7 +3,7 @@ import type { TuitioReactState, TuitioDispatchActions } from "./types";
import type { TuitioToken } from "@flare/tuitio-client"; import type { TuitioToken } from "@flare/tuitio-client";
import { Dispatch } from "react"; import { Dispatch } from "react";
export const reducer = (state: TuitioReactState = initialState, action: any) => { export const reducer = (state: TuitioReactState = initialState, action: any): TuitioReactState => {
switch (action.type) { switch (action.type) {
case "onLoginSuccess": { case "onLoginSuccess": {
return { return {

View File

@ -0,0 +1,14 @@
import * as React from "react";
import { render } from "@testing-library/react";
import "jest-canvas-mock";
import TuitioProvider from "../src";
describe("Tuitio provider render", () => {
it("renders without crashing", () => {
render(
<TuitioProvider tuitioUrl="https://test.com/api">
<div></div>
</TuitioProvider>
);
});
});

View File

@ -1,18 +1,25 @@
{ {
"include": ["src"],
"exclude": ["dist", "node_modules"],
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "es5",
"module": "commonjs", "module": "esnext",
"lib": ["dom", "esnext"],
"importHelpers": true,
"declaration": true, "declaration": true,
"outDir": "./lib", "sourceMap": true,
"jsx": "react", "rootDir": "./src",
"outDir": "./dist/esm",
"strict": true, "strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"moduleResolution": "node",
"jsx": "react",
"allowJs": false,
"esModuleInterop": true, "esModuleInterop": true,
"skipLibCheck": true, "skipLibCheck": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true
"allowJs": false, }
"noUnusedLocals": true,
"noUnusedParameters": true
},
"include": ["./src"],
"exclude": ["node_modules", "**/__tests__/*"]
} }

View File

@ -1,3 +0,0 @@
{
"extends": ["tslint:recommended", "tslint-config-prettier"]
}