Skip to content

Commit ad9f456

Browse files
authored
Merge pull request #1 from flow-build/chore/DAT-385
chore/DAT-385: Configurações da biblioteca
2 parents 61a345c + 070d1d3 commit ad9f456

File tree

14 files changed

+4088
-6020
lines changed

14 files changed

+4088
-6020
lines changed

.eslintrc.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:@typescript-eslint/recommended",
9+
"plugin:import/recommended",
10+
"plugin:import/typescript",
11+
"plugin:react/recommended",
12+
"plugin:prettier/recommended",
13+
"plugin:react-hooks/recommended"
14+
],
15+
"parser": "@typescript-eslint/parser",
16+
"parserOptions": {
17+
"ecmaVersion": 12,
18+
"sourceType": "module",
19+
"ecmaFeatures": {
20+
"jsx": true
21+
}
22+
},
23+
"plugins": [
24+
"@typescript-eslint",
25+
"react",
26+
"prettier",
27+
"eslint-plugin-import-helpers",
28+
"import",
29+
"react-hooks"
30+
],
31+
"rules": {
32+
"prettier/prettier": "error",
33+
"linebreak-style": ["error", "unix"],
34+
"max-len": ["error", { "code": 80, "ignoreUrls": true }],
35+
"import-helpers/order-imports": [
36+
"error",
37+
{
38+
"newlinesBetween": "always",
39+
"groups": ["/^react/", "module", ["parent", "sibling", "index"]],
40+
"alphabetize": { "order": "asc", "ignoreCase": true }
41+
}
42+
],
43+
"no-console": "warn",
44+
"no-nested-ternary": "off",
45+
"react/jsx-filename-extension": ["warn", { "extensions": [".tsx"] }],
46+
"react-hooks/rules-of-hooks": "error",
47+
"react-hooks/exhaustive-deps": "warn",
48+
"react/prop-types": "off",
49+
"import/no-unresolved": "error",
50+
"import/prefer-default-export": "off"
51+
},
52+
"settings": {
53+
"import/resolver": {}
54+
}
55+
}

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"jsxSingleQuote": false,
5+
"printWidth": 80
6+
}

.storybook/main.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

.storybook/preview.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

CHANGELOG.md

Whitespace-only changes.

jest.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
clearMocks: true,
3+
preset: 'ts-jest',
4+
roots: ['<rootDir>/src'],
5+
testEnvironment: 'jsdom',
6+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
7+
transform: {
8+
'^.+\\.tsx?$': 'ts-jest',
9+
},
10+
};

package.json

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,49 @@
11
{
2+
"name": "@flowbuild/react-mqtt-workflow-manager",
23
"version": "0.1.0",
34
"license": "MIT",
5+
"description": "A react wrapper manager for MQTT",
6+
"repository": "https://github.com/flow-build/react-mqtt-workflow-manager",
7+
"homepage": "https://github.com/flow-build/react-mqtt-workflow-manager/#readme",
8+
"author": {
9+
"name": "FlowBuild",
10+
"url": "https://github.com/flow-build"
11+
},
412
"main": "dist/index.js",
513
"typings": "dist/index.d.ts",
614
"files": [
7-
"dist",
8-
"src"
15+
"dist"
916
],
1017
"engines": {
1118
"node": ">=10"
1219
},
20+
"browserslist": {
21+
"production": [
22+
">0.2%",
23+
"not dead",
24+
"not op_mini all"
25+
],
26+
"development": [
27+
"last 1 chrome version",
28+
"last 1 firefox version",
29+
"last 1 safari version"
30+
]
31+
},
1332
"scripts": {
1433
"dev": "tsdx watch",
15-
"build": "tsdx build",
16-
"test": "tsdx test --passWithNoTests",
17-
"lint": "tsdx lint",
18-
"prepare": "tsdx build",
34+
"build": "rimraf dist/ && tsdx build",
35+
"test": "jest",
36+
"lint": "eslint --fix",
37+
"fmt": "prettier --write src/**/*.{ts,tsx}",
38+
"fmt:check": "prettier --check src/**/*.{ts,tsx}",
39+
"prepare": "tsdx build && husky install",
1940
"size": "size-limit",
20-
"analyze": "size-limit --why",
21-
"storybook": "start-storybook -p 6006",
22-
"build-storybook": "build-storybook"
41+
"analyze": "size-limit --why"
2342
},
2443
"peerDependencies": {
25-
"react": ">=16"
26-
},
27-
"husky": {
28-
"hooks": {
29-
"pre-commit": "tsdx lint"
30-
}
31-
},
32-
"prettier": {
33-
"printWidth": 80,
34-
"semi": true,
35-
"singleQuote": true,
36-
"trailingComma": "es5"
44+
"react": ">=16",
45+
"react-dom": ">=16"
3746
},
38-
"name": "react-mqtt-workflow-manager",
39-
"author": "wallace-sf",
4047
"module": "dist/react-mqtt-workflow-manager.esm.js",
4148
"size-limit": [
4249
{
@@ -51,21 +58,54 @@
5158
"devDependencies": {
5259
"@babel/core": "^7.21.0",
5360
"@size-limit/preset-small-lib": "^8.2.4",
54-
"@storybook/addon-essentials": "^6.5.16",
55-
"@storybook/addon-info": "^5.3.21",
56-
"@storybook/addon-links": "^6.5.16",
57-
"@storybook/addons": "^6.5.16",
58-
"@storybook/react": "^6.5.16",
61+
"@testing-library/jest-dom": "^5.16.5",
62+
"@testing-library/react": "^14.0.0",
63+
"@types/jest": "^29.4.0",
5964
"@types/react": "^18.0.28",
6065
"@types/react-dom": "^18.0.11",
66+
"@typescript-eslint/eslint-plugin": "^5.54.0",
67+
"@typescript-eslint/parser": "^5.54.0",
6168
"babel-loader": "^9.1.2",
69+
"eslint": "^8.35.0",
70+
"eslint-config-prettier": "^8.6.0",
71+
"eslint-import-resolver-typescript": "^3.5.3",
72+
"eslint-plugin-import": "^2.25.2",
73+
"eslint-plugin-import-helpers": "^1.3.1",
74+
"eslint-plugin-prettier": "^4.2.1",
75+
"eslint-plugin-react": "^7.32.2",
76+
"eslint-plugin-react-hooks": "^4.6.0",
6277
"husky": "^8.0.3",
78+
"jest": "^29.4.3",
79+
"jest-environment-jsdom": "^29.4.3",
80+
"lint-staged": "^13.1.2",
81+
"prettier": "^2.8.4",
6382
"react": "^18.2.0",
6483
"react-dom": "^18.2.0",
6584
"react-is": "^18.2.0",
85+
"rimraf": "^4.1.2",
86+
"semantic-release": "^20.1.1",
6687
"size-limit": "^8.2.4",
88+
"ts-jest": "^29.0.5",
89+
"ts-node": "^10.9.1",
6790
"tsdx": "^0.14.1",
6891
"tslib": "^2.5.0",
6992
"typescript": "^4.9.5"
93+
},
94+
"dependencies": {
95+
"mqtt": "^4.3.7"
96+
},
97+
"lint-staged": {
98+
"src/**/*.{ts,tsx}": [
99+
"yarn lint",
100+
"yarn fmt"
101+
]
102+
},
103+
"settings": {
104+
"import/resolver": {
105+
"typescript": {
106+
"typescript": true,
107+
"node": true
108+
}
109+
}
70110
}
71111
}

src/WorkflowManager.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
1-
import React, { FC } from 'react';
1+
import React, { FC, useCallback, useEffect, useState } from 'react';
2+
3+
import { connect, MqttClient } from 'mqtt';
24

35
import { WorkflowManagerProps } from './types';
46

5-
export const WorkflowManager: FC<WorkflowManagerProps> = ({ children }) => {
6-
return <div>{children || `Hello WorkflowManager`}</div>;
7+
export const WorkflowManager: FC<WorkflowManagerProps> = ({
8+
brokerUrl,
9+
options,
10+
children,
11+
}) => {
12+
const [client, setClient] = useState<MqttClient | null>(null);
13+
14+
const init = useCallback(() => {
15+
if (client === null) {
16+
try {
17+
const mqttInstance = connect(brokerUrl, options);
18+
19+
setClient(mqttInstance);
20+
} catch (error) {
21+
// TODO: Handle error with invariant
22+
}
23+
}
24+
}, [brokerUrl, client, options]);
25+
26+
useEffect(() => {
27+
init();
28+
}, [init]);
29+
30+
return <>{children}</>;
731
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
3+
import { render } from '@testing-library/react';
4+
5+
import { WorkflowManager } from '../WorkflowManager';
6+
7+
describe('WorkflowManager component', () => {
8+
beforeEach(() => {
9+
const props = { brokerUrl: 'http://localhost:8080' };
10+
11+
render(<WorkflowManager {...props} />);
12+
});
13+
14+
it('should render', () => {
15+
expect(true).toBeTruthy();
16+
});
17+
});

0 commit comments

Comments
 (0)