react typescript package
parent
b9910e2f61
commit
3f35229fef
|
@ -0,0 +1,2 @@
|
|||
node_modules
|
||||
dist
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -7,7 +7,6 @@ node_modules
|
|||
build
|
||||
lib
|
||||
dist
|
||||
.rpt2_cache
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
"bracketSpacing": true,
|
||||
"arrowParens": "avoid",
|
||||
"printWidth": 160,
|
||||
"printWidth": 120,
|
||||
"trailingComma": "none",
|
||||
"singleQuote": false
|
||||
"singleQuote": false,
|
||||
"endOfLine": "auto"
|
||||
}
|
||||
|
|
|
@ -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.
|
|
@ -2,9 +2,10 @@
|
|||
"transform": {
|
||||
"^.+\\.(t|j)sx?$": "ts-jest"
|
||||
},
|
||||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
|
||||
"testRegex": "(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
|
||||
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
|
||||
"collectCoverage": true,
|
||||
"testEnvironment": "jsdom",
|
||||
"collectCoverage": false,
|
||||
"coverageThreshold": {
|
||||
"global": {
|
||||
"branches": 50,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
54
package.json
54
package.json
|
@ -1,18 +1,21 @@
|
|||
{
|
||||
"name": "@flare/tuitio-react-client",
|
||||
"version": "1.0.0",
|
||||
"description": "React Tuitio client",
|
||||
"main": "./lib/index.js",
|
||||
"types": "./lib/index.d.ts",
|
||||
"description": "Tuitio react client",
|
||||
"main": "./dist/cjs/index.js",
|
||||
"module": "./dist/esm/index.js",
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"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",
|
||||
"format": "prettier --write \"src/**/*.ts\"",
|
||||
"lint": "tslint -p tsconfig.json",
|
||||
"format": "prettier --write \"{src,tests}/**/*.{js,ts,jsx,tsx}\"",
|
||||
"lint": "eslint \"{**/*,*}.{js,ts,jsx,tsx}\"",
|
||||
"prepublishOnly": "npm test && npm run lint",
|
||||
"prepush": "npm run build",
|
||||
"preversion": "npm run lint",
|
||||
"version": "npm run format && git add -A src",
|
||||
"version": "npm run format",
|
||||
"push": "npm publish",
|
||||
"push:major": "npm run version:major && npm run push",
|
||||
"push:minor": "npm run version:minor && npm run push",
|
||||
|
@ -34,29 +37,40 @@
|
|||
"email": "tudor.stanciu94@gmail.com",
|
||||
"url": "https://lab.code-rove.com/tsp"
|
||||
},
|
||||
"license": "ISC",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://lab.code-rove.com/gitea/bricks/tuitio-react-client/issues"
|
||||
},
|
||||
"homepage": "https://lab.code-rove.com/gitea/bricks/tuitio-react-client#readme",
|
||||
"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": {
|
||||
"@flare/tuitio-client": "^1.0.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
|
@ -1 +0,0 @@
|
|||
// to do
|
|
@ -1,2 +1,3 @@
|
|||
const x = 4;
|
||||
export default x;
|
||||
import TuitioProvider from "./TuitioProvider";
|
||||
|
||||
export default TuitioProvider;
|
||||
|
|
|
@ -10,6 +10,6 @@ export const initialState: TuitioReactState = {
|
|||
};
|
||||
|
||||
export const initialDispatchActions: TuitioDispatchActions = {
|
||||
onLoginSuccess: () => {},
|
||||
onLogout: () => {}
|
||||
onLoginSuccess: () => undefined,
|
||||
onLogout: () => undefined
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ import type { TuitioReactState, TuitioDispatchActions } from "./types";
|
|||
import type { TuitioToken } from "@flare/tuitio-client";
|
||||
import { Dispatch } from "react";
|
||||
|
||||
export const reducer = (state: TuitioReactState = initialState, action: any) => {
|
||||
export const reducer = (state: TuitioReactState = initialState, action: any): TuitioReactState => {
|
||||
switch (action.type) {
|
||||
case "onLoginSuccess": {
|
||||
return {
|
||||
|
|
|
@ -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>
|
||||
);
|
||||
});
|
||||
});
|
|
@ -1,18 +1,25 @@
|
|||
{
|
||||
"include": ["src"],
|
||||
"exclude": ["dist", "node_modules"],
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"module": "esnext",
|
||||
"lib": ["dom", "esnext"],
|
||||
"importHelpers": true,
|
||||
"declaration": true,
|
||||
"outDir": "./lib",
|
||||
"jsx": "react",
|
||||
"sourceMap": true,
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist/esm",
|
||||
"strict": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"moduleResolution": "node",
|
||||
"jsx": "react",
|
||||
"allowJs": false,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowJs": false,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true
|
||||
},
|
||||
"include": ["./src"],
|
||||
"exclude": ["node_modules", "**/__tests__/*"]
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"extends": ["tslint:recommended", "tslint-config-prettier"]
|
||||
}
|
Loading…
Reference in New Issue